forked from BrainAndNumber/SimSeq_CerebralCortex2019
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixation.m
More file actions
57 lines (47 loc) · 1.77 KB
/
Fixation.m
File metadata and controls
57 lines (47 loc) · 1.77 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
function [start_fix,dur_fix,pressed] = Fixation(w,rect,mon_width,v_dist,dur,color,start_trigger)
% Do initial flip...
mon_width = 50; % horizontal dimension of viewable screen (cm)
v_dist = 60; % viewing distance (cm)
fix_r = 0.3; % radius of fixation point (deg)
[center(1), center(2)] = RectCenter(rect);
ppd = pi * (rect(3)-rect(1)) / atan(mon_width/v_dist/2) / 360; % pixels per degree
fix_cord = [center-fix_r*ppd center+fix_r*ppd];
[X,Y] = RectCenter(rect);
FixCross = [X-2,Y-12,X+2,Y+12;X-12,Y-2,X+12,Y+2];
kc_esc = KbName('esc');
% kc_lctrl = KbName('1!');
% kc_rctrl = KbName('4$');
kc_lctrl = KbName('left_control');
kc_rctrl = KbName('right_control');
% Measure the vertical refresh rate of the monitor
ifi = Screen('GetFlipInterval', w);
% Numer of frames to wait when specifying good timing
waitframes = 1;
pressed = 0;
Priority(MaxPriority(w));
vbl = Screen('Flip', w);
% Length of time and number of frames we will use for each drawing test
numSecs = dur;
numFrames = round(numSecs / ifi);
for frame = 1:numFrames
Screen('FillRect', w, color, FixCross');
% Tell PTB no more drawing commands will be issued until the next flip
Screen('DrawingFinished', w);
% Flip to the screen
if frame == 1
start_fix = vbl + (waitframes - 0.5) * ifi-start_trigger;
end;
vbl = Screen('Flip', w, vbl + (waitframes - 0.5) * ifi);
[keyIsDown secs keycodes] = KbCheck();
if ~isempty(keycodes)
if keycodes(kc_esc)
Priority(0);
ShowCursor;
Screen('CloseAll');
elseif keycodes(kc_lctrl) || keycodes(kc_rctrl)
pressed = 1;
end;
end;
end
Priority(0);
dur_fix = vbl + (waitframes - 0.5) * ifi-start_fix-start_trigger;