-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathExample_Slider_Script.m
More file actions
120 lines (99 loc) · 3.96 KB
/
Copy pathExample_Slider_Script.m
File metadata and controls
120 lines (99 loc) · 3.96 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
%% Example Slider Script - 01/05/24
% Initialize variables
KbName('UnifyKeyNames')
try
right_keypress = KbName('RightArrow');
left_keypress = KbName('LeftArrow');
space_keypress = KbName('Space');
catch
right_keypress = [115 13];
left_keypress = [114 12];
space_keypress = [66 14];
end
cWhite0 = 255;
% fixation_color = [255 0 0];
viewDist = 120;
curScreen = 0;
aperture_size = 50;
visInfo.displaceSet = aperture_size;
% Prompt for monitor width
monWidth = input('Monitor Width (in cm)? : ');
% Opens psychtoolbox and initializes experiment
Screen('Preference', 'SkipSyncTests', 1);
[screenInfo, xCenter, yCenter] = openExperiment(monWidth, viewDist, curScreen);
curWindow= screenInfo.curWindow;
screenRect= screenInfo.screenRect;
% Enable alpha blending with proper blend-function. We need it for drawing
% of smoothed points.
Screen('BlendFunction', curWindow, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
monRefresh = 1/screenInfo.frameDur;
slack = Screen('GetFlipInterval', curWindow);
vbl = Screen('Flip', curWindow);
% Needed to present stimuli
EEG_nature = 0;
outlet = NaN;
markers = NaN;
% Variables for nonchanging visual stimulus
inputtype = 1; typeInt = 1; minNum = 1.5; maxNum = 2.5; meanNum = 2; maxdotsframe = 150;
block_dot_speed = 15; vel_stair = 0; visInfo.vel = 58.8; dur = 0.5;
monWidth = 50.8; viewDist = 120; givenCoh = 0.5;
% Parameters for your scale and text that you want
question = 'USE THE SLIDER TO MATCH THE VISUAL NOISINESS TO THE AUDITORY NOISINESS.';
lowerText = 'Most Noisy';
upperText = 'Least Noisy';
pixelsPerPress = 2;
waitframes = 1;
lineLength = 500; % in pixels
halfLength = lineLength/2;
divider = lineLength/100; % for a rating of 1:10
currentRating = NaN;
baseRect = [0 0 10 30]; % size of slider
LineX = xCenter;
LineY = yCenter;
rectColor = cWhite0;
lineColor = cWhite0;
textColor = cWhite0;
while KbCheck; end
while true
%% Create slider
[keyisDown, secs, keyCode] = KbCheck;
pressedKeys = find(keyCode);
disp(KbName)
if ismember(pressedKeys, right_keypress)
LineX = LineX + pixelsPerPress;
elseif ismember(pressedKeys, left_keypress)
LineX = LineX - pixelsPerPress;
elseif ismember(pressedKeys, space_keypress)
StopPixel_M = ((LineX - xCenter) + halfLength)/divider; % for a rating of between 0 and 10. Tweak this as necessary
break
end
if LineX < (xCenter - halfLength)
LineX = xCenter - halfLength;
elseif LineX > (xCenter + halfLength)
LineX = xCenter + halfLength;
end
if LineY < 0
LineY = 0;
elseif LineY > (yCenter + 10)
LineY = yCenter + 10;
end
centeredRect = CenterRectOnPointd(baseRect, LineX, LineY);
currentRating = ((LineX - xCenter) + halfLength)/divider;
ratingText = num2str(currentRating); % to make this display whole numbers, use "round(currentRating)"
ratingText = sprintf(ratingText, '%');
DrawFormattedText(curWindow, ratingText,'center', (yCenter-200), textColor, [],[],[],5); % display current rating
DrawFormattedText(curWindow, question ,'center', (yCenter-100), textColor, [],[],[],5);
Screen('DrawLine', curWindow, lineColor, (xCenter+halfLength), (yCenter),(xCenter-halfLength), (yCenter), 1);
Screen('DrawLine', curWindow, lineColor, (xCenter+halfLength), (yCenter+10), (xCenter+halfLength), (yCenter-10), 1);
Screen('DrawLine', curWindow, lineColor, (xCenter-halfLength), (yCenter+10), (xCenter-halfLength), (yCenter-10), 1);
Screen('DrawText', curWindow, lowerText, (xCenter-halfLength), (yCenter+25), textColor);
Screen('DrawText', curWindow, upperText , (xCenter+halfLength) , (yCenter+25), textColor);
Screen('FillRect', curWindow, rectColor, centeredRect);
vbl = Screen('Flip', curWindow, vbl + (waitframes - 0.5) * slack);
WaitSecs(4)
end
%% Close everything and display the rating. If you're doing this during a script, just put in a flip and save the rating somewhere.
disp('Rating: ') ;
disp(StopPixel_M);
sca;
Screen('CloseAll');