|
1 | 1 | function [dots] = initDots(cfg, thisEvent) |
2 | | - |
| 2 | + % [dots] = initDots(cfg, thisEvent) |
| 3 | + % |
| 4 | + % % Dot life time in seconds |
| 5 | + % cfg.dot.lifeTime |
| 6 | + % % Number of dots |
| 7 | + % cfg.dot.number |
| 8 | + % Proportion of coherent dots. |
| 9 | + % cfg.dot.coherence |
| 10 | + % |
| 11 | + % % Direction (an angle in degrees) |
| 12 | + % thisEvent.direction |
| 13 | + % % Speed expressed in pixels per frame |
| 14 | + % thisEvent.speed |
| 15 | + % |
| 16 | + % |
| 17 | + |
| 18 | + % TODO |
| 19 | + % bound direction between 0 and 360 ?? |
| 20 | + |
3 | 21 | direction = thisEvent.direction(1); |
4 | | - |
5 | | - dots.lifeTime = cfg.dot.lifeTime; |
6 | | - |
| 22 | + |
7 | 23 | speedPixPerFrame = thisEvent.speed(1); |
8 | 24 |
|
| 25 | + lifeTime = cfg.dot.lifeTime; |
| 26 | + |
9 | 27 | % decide which dots are signal dots (1) and those are noise dots (0) |
10 | | - dots.isSignal = rand(cfg.dot.number, 1) < cfg.dot.coherence; |
| 28 | + isSignal = rand(cfg.dot.number, 1) < cfg.dot.coherence; |
11 | 29 |
|
12 | 30 | % for static dots |
13 | 31 | if direction == -1 |
14 | 32 | speedPixPerFrame = 0; |
15 | | - dots.lifeTime = Inf; |
16 | | - dots.isSignal = true(cfg.dot.number, 1); |
| 33 | + lifeTime = Inf; |
| 34 | + isSignal = true(cfg.dot.number, 1); |
17 | 35 | end |
18 | | - |
19 | | - % Convert from seconds to frames |
20 | | - dots.lifeTime = ceil(dots.lifeTime / cfg.screen.ifi); |
21 | | - |
22 | | - % Set an array of dot positions [xposition, yposition] |
| 36 | + |
| 37 | + %% Set an array of dot positions [xposition, yposition] |
23 | 38 | % These can never be bigger than 1 or lower than 0 |
24 | 39 | % [0,0] is the top / left of the square |
25 | 40 | % [1,1] is the bottom / right of the square |
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 |
29 | | - dots.speeds = nan(cfg.dot.number, 2); |
| 41 | + positions = rand(cfg.dot.number, 2) * cfg.screen.winWidth; |
30 | 42 |
|
31 | | - % Coherent dots |
32 | | - [horVector, vertVector] = decompMotion(direction); |
33 | | - dots.speeds(dots.isSignal, :) = ... |
34 | | - repmat([horVector, vertVector], sum(dots.isSignal), 1); |
| 43 | + %% Set vertical and horizontal speed for all dots |
| 44 | + directionAllDots = setDotDirection(cfg, positions, direction, isSignal); |
| 45 | + |
| 46 | + [horVector, vertVector] = decomposeMotion(directionAllDots); |
| 47 | + speeds = [horVector, vertVector]; |
| 48 | + |
| 49 | + % we were working with unit vectors. we now switch to pixels |
| 50 | + speeds = speeds * speedPixPerFrame; |
35 | 51 |
|
36 | | - % Random direction for the non coherent dots |
37 | | - if any(~dots.isSignal) |
38 | | - randomDirection = rand(sum(~dots.isSignal), 1) * 360; |
39 | | - [horVector, vertVector] = decompMotion(randomDirection); |
40 | | - dots.speeds(~dots.isSignal, :) = [horVector, vertVector]; |
41 | | - end |
42 | | - |
43 | | - % So far we were working wiht unit vectors convert that speed in pixels per |
44 | | - % frame |
45 | | - dots.speeds = dots.speeds * speedPixPerFrame; |
46 | | - |
47 | | - % Create a vector to update to dotlife time of each dot |
| 52 | + %% Create a vector to update to dotlife time of each dot |
48 | 53 | % Not all set to 1 so the dots will die at different times |
49 | 54 | % The maximum value is the duraion of the event in frames |
50 | | - dots.time = floor(rand(cfg.dot.number, 1) * cfg.eventDuration / cfg.screen.ifi); |
| 55 | + time = floor(rand(cfg.dot.number, 1) * cfg.eventDuration / cfg.screen.ifi); |
| 56 | + |
| 57 | + %% Convert from seconds to frames |
| 58 | + lifeTime = ceil(lifeTime / cfg.screen.ifi); |
| 59 | + |
| 60 | + %% |
| 61 | + dots.lifeTime = lifeTime; |
| 62 | + dots.time = time; |
| 63 | + dots.speeds = speeds; |
| 64 | + dots.isSignal = isSignal; |
| 65 | + dots.positions = positions; |
| 66 | +end |
51 | 67 |
|
| 68 | +function directionAllDots = setDotDirection(cfg, positions, direction, isSignal) |
| 69 | + |
| 70 | + directionAllDots = nan(cfg.dot.number, 1); |
| 71 | + |
| 72 | + direction = computeRadialMotionDirection(cfg, positions, direction); |
| 73 | + |
| 74 | + % Coherent dots |
| 75 | + directionAllDots(isSignal) = direction; |
| 76 | + % Random direction for the non coherent dots |
| 77 | + directionAllDots(~isSignal) = rand(sum(~isSignal), 1) * 360; |
| 78 | + directionAllDots = rem(directionAllDots,360); |
| 79 | + |
52 | 80 | end |
| 81 | + |
| 82 | + |
0 commit comments