|
16 | 16 | % dots outside of the aperture is turned into a NaN so effectively the |
17 | 17 | % actual number of dots on the screen at any given time is not the one that you input but a |
18 | 18 | % smaller number (nDots / Area of aperture) on average. |
19 | | - |
| 19 | + |
20 | 20 | %% Get parameters |
21 | | - dontClear = cfg.dot.dontClear; |
22 | | - |
23 | 21 | direction = thisEvent.direction(1); |
24 | 22 | isTarget = thisEvent.target(1); |
25 | | - speed = thisEvent.speed(1); |
26 | | - |
27 | | - coh = cfg.dot.coh; |
28 | | - ndots = cfg.dot.maxNbPerFrame; |
29 | | - dotSizePix = cfg.dot.sizePix; |
| 23 | + |
| 24 | + |
30 | 25 | dotLifeTime = cfg.dot.lifeTime; |
31 | | - dotColor = cfg.dot.color; |
32 | | - |
| 26 | + |
33 | 27 | targetDuration = cfg.target.duration; |
34 | | - |
| 28 | + |
35 | 29 | % thisEvent = deg2Pix('speed', thisEvent, cfg); |
36 | 30 | % dotSpeedPix = logFile.iEventSpeedPix; |
37 | | - |
38 | | - diamAperturePix = cfg.diameterAperturePix; |
39 | | - diamAperture = cfg.diameterAperture; |
40 | | - |
| 31 | + |
| 32 | + coh = cfg.dot.coh; |
| 33 | + speed = thisEvent.speed(1); |
41 | 34 | % Check if it is a static or motion block |
42 | 35 | if direction == -1 |
43 | | - |
44 | | - % dotSpeedPix = 0; |
45 | | - |
| 36 | + |
46 | 37 | speed = 0; |
47 | | - |
| 38 | + coh = 1; |
| 39 | + |
48 | 40 | dotLifeTime = cfg.eventDuration; |
49 | 41 | end |
50 | | - |
| 42 | + |
51 | 43 | %% initialize variables |
52 | | - |
| 44 | + |
53 | 45 | % Set an array of dot positions [xposition, yposition] |
54 | 46 | % These can never be bigger than 1 or lower than 0 |
55 | | - % [0,0] is the top / left of the square that contains the square aperture |
56 | | - % [1,1] is the bottom / right of the square that contains the square aperture |
57 | | - xy = rand(ndots, 2); |
58 | | - |
| 47 | + % [0,0] is the top / left of the square |
| 48 | + % [1,1] is the bottom / right of the square |
| 49 | + dotPositions = rand(cfg.dot.number, 2); |
| 50 | + |
59 | 51 | % Set a N x 2 matrix that gives jump size in pixels |
60 | 52 | % pix/sec * sec/frame = pix / frame |
61 | 53 | dxdy = repmat( ... |
62 | | - speed * 10 / (diamAperture * 10) * (3 / cfg.screen.monitorRefresh) * ... |
63 | | - [cos(pi * direction / 180.0) -sin(pi * direction / 180.0)], ndots, 1); |
64 | | - |
| 54 | + speed * 10 / (cfg.aperture.width * 10) * (3 / cfg.screen.monitorRefresh) * ... |
| 55 | + [cos(pi * direction / 180.0) -sin(pi * direction / 180.0)], cfg.dot.number, 1); |
| 56 | + |
65 | 57 | % dxdy = repmat(... |
66 | 58 | % dotSpeedPix / Cfg.ifi ... |
67 | 59 | % * (cos(pi*direction/180) - sin(pi*direction/180)), ... |
68 | 60 | % ndots, 1); |
69 | | - |
| 61 | + |
70 | 62 | % Create a ones vector to update to dotlife time of each dot |
71 | | - dotTime = ones(size(xy, 1), 1); |
72 | | - |
73 | | - % Set for how many frames to show the dots |
74 | | - continueShow = floor(cfg.eventDuration / cfg.screen.ifi); |
75 | | - |
| 63 | + dotTime = ones(size(dotPositions, 1), 1); |
| 64 | + |
76 | 65 | % Covert the dotLifeTime from seconds to frames |
77 | 66 | dotLifeTime = ceil(dotLifeTime / cfg.screen.ifi); |
| 67 | + |
| 68 | + % Set for how many frames this event will last |
| 69 | + framesLeft = floor(cfg.eventDuration / cfg.screen.ifi); |
78 | 70 |
|
79 | 71 | %% Start the dots presentation |
80 | | - vbl = Screen('Flip', cfg.screen.win, 0, dontClear); |
| 72 | + vbl = Screen('Flip', cfg.screen.win); |
81 | 73 | onset = vbl; |
82 | | - |
83 | | - while continueShow |
84 | | - |
| 74 | + |
| 75 | + while framesLeft |
| 76 | + |
85 | 77 | % L are the dots that will be moved |
86 | | - L = rand(ndots, 1) < coh; |
87 | | - |
| 78 | + L = rand(cfg.dot.number, 1) < coh; |
| 79 | + |
88 | 80 | % Move the selected dots |
89 | | - xy(L, :) = xy(L, :) + dxdy(L, :); |
90 | | - |
| 81 | + dotPositions(L, :) = dotPositions(L, :) + dxdy(L, :); |
| 82 | + |
91 | 83 | % If not 100% coherence, we get new random locations for the other dots |
92 | 84 | if sum(~L) > 0 |
93 | | - xy(~L, :) = rand(sum(~L), 2); |
| 85 | + dotPositions(~L, :) = rand(sum(~L), 2); |
94 | 86 | end |
95 | | - |
| 87 | + |
96 | 88 | % Create a logical vector to detect any dot that has: |
97 | 89 | % - an xy position inferior to 0 |
98 | 90 | % - an xy position superior to 1 |
99 | 91 | % - has exceeded its liftime |
100 | | - N = any([xy > 1, xy < 0, dotTime > dotLifeTime], 2) ; |
101 | | - |
| 92 | + N = any([dotPositions > 1, dotPositions < 0, dotTime > dotLifeTime], 2) ; |
| 93 | + |
102 | 94 | % If there is any such dot we relocate it to a new random position |
103 | 95 | % and change its lifetime to 1 |
104 | 96 | if any(N) |
105 | | - xy(N, :) = rand(sum(N), 2); |
| 97 | + dotPositions(N, :) = rand(sum(N), 2); |
106 | 98 | dotTime(N, 1) = 1; |
107 | 99 | end |
108 | | - |
109 | | - % Convert the dot position to pixels |
110 | | - xy_pix = floor(xy * diamAperturePix); |
111 | | - |
| 100 | + |
| 101 | + %% Convert the dot position to pixels |
| 102 | + % We expand that square so that its side is equal to the whole |
| 103 | + % screen width. |
| 104 | + % With no aperture the whole screen is filled with dots. |
| 105 | + dotPositionsPix = floor(dotPositions * cfg.screen.winRect(3)); |
| 106 | + |
112 | 107 | % This assumes that zero is at the top left, but we want it to be |
113 | 108 | % in the center, so shift the dots up and left, which just means |
114 | 109 | % adding half of the aperture size to both the x and y direction. |
115 | | - xy_pix = (xy_pix - diamAperturePix / 2)'; |
116 | | - |
117 | | - % NaN out-of-circle dots |
118 | | - % We use Pythagore's theorem to figure out which dots are out of the |
119 | | - % circle |
120 | | - outCircle = sqrt(xy_pix(1, :).^2 + xy_pix(2, :).^2) + ... |
121 | | - dotSizePix / 2 > (diamAperturePix / 2); |
122 | | - xy_pix(:, outCircle) = NaN; |
123 | | - |
124 | | - %% PTB draws the dots stimulation |
125 | | - |
126 | | - % Draw the fixation cross |
127 | | - color = cfg.fixation.color; |
| 110 | + dotPositionsPix = (dotPositionsPix - cfg.screen.winRect(3) / 2)'; |
| 111 | + |
| 112 | + thisEvent.dot.positions = dotPositionsPix; |
| 113 | + |
| 114 | + %% make textures |
| 115 | + dotTexture('make', cfg, thisEvent); |
| 116 | + |
| 117 | + apertureTexture('make', cfg, thisEvent); |
| 118 | + |
| 119 | + %% draw evetything and flip screen |
| 120 | + |
| 121 | + dotTexture('draw', cfg, thisEvent); |
| 122 | + |
| 123 | + apertureTexture('draw', cfg, thisEvent); |
| 124 | + |
128 | 125 | % If this frame shows a target we change the color |
| 126 | + thisFixation.fixation = cfg.fixation; |
| 127 | + thisFixation.screen = cfg.screen; |
129 | 128 | if GetSecs < (onset + targetDuration) && isTarget == 1 |
130 | | - color = cfg.fixation.colorTarget; |
| 129 | + thisFixation.fixation.color = cfg.fixation.colorTarget; |
131 | 130 | end |
132 | | - drawFixationCross(cfg, color); |
133 | | - |
134 | | - % Draw the dots |
135 | | - Screen('DrawDots', cfg.screen.win, xy_pix, dotSizePix, dotColor, cfg.screen.center, 2); |
136 | | - |
137 | | - Screen('DrawingFinished', cfg.screen.win, dontClear); |
138 | | - |
139 | | - vbl = Screen('Flip', cfg.screen.win, vbl + cfg.screen.ifi, dontClear); |
140 | | - |
| 131 | + drawFixation(thisFixation); |
| 132 | + |
| 133 | + Screen('DrawingFinished', cfg.screen.win); |
| 134 | + |
| 135 | + vbl = Screen('Flip', cfg.screen.win, vbl + cfg.screen.ifi); |
| 136 | + |
141 | 137 | %% Update counters |
142 | | - |
| 138 | + |
143 | 139 | % Check for end of loop |
144 | | - continueShow = continueShow - 1; |
145 | | - |
| 140 | + framesLeft = framesLeft - 1; |
| 141 | + |
146 | 142 | % Add one frame to the dot lifetime to each dot |
147 | 143 | dotTime = dotTime + 1; |
148 | | - |
| 144 | + |
149 | 145 | end |
150 | | - |
| 146 | + |
151 | 147 | %% Erase last dots |
152 | | - |
153 | | - drawFixationCross(cfg, cfg.fixation.color); |
154 | | - |
155 | | - Screen('DrawingFinished', cfg.screen.win, dontClear); |
156 | | - |
157 | | - vbl = Screen('Flip', cfg.screen.win, vbl + cfg.screen.ifi, dontClear); |
158 | | - |
| 148 | + |
| 149 | + drawFixation(cfg); |
| 150 | + |
| 151 | + Screen('DrawingFinished', cfg.screen.win); |
| 152 | + |
| 153 | + vbl = Screen('Flip', cfg.screen.win, vbl + cfg.screen.ifi); |
| 154 | + |
159 | 155 | duration = vbl - onset; |
160 | | - |
| 156 | + |
161 | 157 | end |
| 158 | + |
0 commit comments