|
1 | 1 | function [dots] = initializeDots(cfg, thisEvent) |
2 | | - |
| 2 | + |
3 | 3 | direction = thisEvent.direction(1); |
4 | | - |
| 4 | + |
5 | 5 | dots.lifeTime = cfg.dot.lifeTime; |
6 | | - |
7 | | - speedPixPerFrame = thisEvent.speed(1); |
8 | | - |
| 6 | + |
| 7 | + speedPixPerFrame = thisEvent.speed(1); |
| 8 | + |
9 | 9 | % decide which dots are signal dots (1) and those are noise dots (0) |
10 | 10 | dots.isSignal = rand(cfg.dot.number, 1) < cfg.dot.coherence; |
11 | | - |
| 11 | + |
12 | 12 | % for static dots |
13 | 13 | if direction == -1 |
14 | 14 | speedPixPerFrame = 0; |
15 | 15 | dots.lifeTime = cfg.eventDuration; |
16 | 16 | dots.isSignal = ones(cfg.dot.number, 1); |
17 | 17 | end |
18 | | - |
| 18 | + |
19 | 19 | % Convert from seconds to frames |
20 | 20 | dots.lifeTime = ceil(dots.lifeTime / cfg.screen.ifi); |
21 | 21 |
|
|
24 | 24 | % [0,0] is the top / left of the square |
25 | 25 | % [1,1] is the bottom / right of the square |
26 | 26 | dots.positions = rand(cfg.dot.number, 2) * cfg.screen.winWidth; |
27 | | - |
28 | | - % Set a N x 2 matrix that speed in X and Y |
| 27 | + |
| 28 | + % Set a N x 2 matrix that speed in X and Y |
29 | 29 | dots.speeds = nan(cfg.dot.number, 2); |
30 | | - |
| 30 | + |
31 | 31 | % Coherent dots |
32 | 32 | [horVector, vertVector] = decompMotion(direction); |
33 | | - dots.speeds(dots.isSignal,:) = ... |
| 33 | + dots.speeds(dots.isSignal, :) = ... |
34 | 34 | repmat([horVector, vertVector], sum(dots.isSignal), 1); |
35 | | - |
| 35 | + |
36 | 36 | % If not 100% coherence, we get new random direction for the other dots |
37 | 37 | direction = rand(sum(~dots.isSignal), 1) * 360; |
38 | 38 | [horVector, vertVector] = decompMotion(direction); |
39 | 39 | dots.speeds(~dots.isSignal, :) = [horVector, vertVector]; |
40 | | - |
| 40 | + |
41 | 41 | % So far we were working wiht unit vectors convert that speed in pixels per |
42 | 42 | % frame |
43 | 43 | dots.speeds = dots.speeds * speedPixPerFrame; |
44 | | - |
| 44 | + |
45 | 45 | % Create a vector to update to dotlife time of each dot |
46 | 46 | % Not all set to one so the dots will die at different times |
47 | 47 | dots.time = floor(rand(cfg.dot.number, 1) * cfg.eventDuration / cfg.screen.ifi); |
48 | | - |
49 | | -end |
50 | 48 |
|
| 49 | +end |
0 commit comments