-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorTest_example.m
83 lines (63 loc) · 2.64 KB
/
ColorTest_example.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
% ColorTest_example.m - An example that cycles through font / background
% colors...
%
%
% Author: Brian Armstrong
%
% import our lab's custom package so we can use its functions.
import cog_comm_tools.*;
% font settings
fontFace = 'Arial';
fontSize = 30;
fontStyle = 1;
fontColor = getRGBColor('white');
% you can increase the increment value to make the test cycle through colors
% more quickly.
incValue = 1;
% here we are specifying what screen resolution we want(uncomment an
% option, or specify a valid resolution for the machine you are working on)
screenResolution = [1024 768];
% screenResolution = [1152 864];
% screenResolution = [1920 1080];
% declare experimental constants
% a try block 'tries' a block of code and if an exception occurs it will jump to the following catch block
try
% SETUP EXPERIMENT
% assert that what we need is installed and working
initializeExperiment();
% initilize the window, set font style
[window, resolution] = initializeWindow( fontFace, fontSize, fontStyle, screenResolution, fontColor);
% notice we don't supply any optional arguments. See the code for
% displayInstructions to see all the paramenters.
displayInstructions(window, 'This is a color test. You can pause on a certain color by pressing space. (Resume by pressing space again.) Hit ESC to exit once the test begins...');
% keep going until halt with ESC
while(true)
% cycle through all the colors by fifteen
for red=0:incValue:255
for green=0:incValue:255
for blue=0:incValue:255
% allow for pause...
checkForSpaceKeyToPause();
% string of the color...
colorString = ['[' num2str(red) ' ' num2str(green) ' ' num2str(blue) ']'];
% RGB color value...
fontColor = [red green blue];
% display the text...
displayTextCentered(window, colorString, fontColor);
% allow for exit...
checkForEscapeKeyToHalt();
end
end
end
end
% SHUTDOWN THE EXPERIMENT
shutDownExperiment();
catch
% This "catch" section executes in case of an error in the "try" section above.
% If we encounter an exception, we clean up.
% Clean up.
shutDownExperiment();
% Since we are catching (handling) the error, we want to rethrow it so we can see
% what happened. We only catch it to call shutDownExperiment.
psychrethrow(psychlasterror);
end