|
| 1 | +function [dots] = initDots(cfg, thisEvent) |
| 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 | + |
| 21 | + dots.direction = thisEvent.direction(1); |
| 22 | + |
| 23 | + speedPixPerFrame = thisEvent.speed(1); |
| 24 | + |
| 25 | + lifeTime = cfg.dot.lifeTime; |
| 26 | + |
| 27 | + % decide which dots are signal dots (1) and those are noise dots (0) |
| 28 | + dots.isSignal = rand(cfg.dot.number, 1) < cfg.dot.coherence; |
| 29 | + |
| 30 | + % for static dots |
| 31 | + if dots.direction == -1 |
| 32 | + speedPixPerFrame = 0; |
| 33 | + lifeTime = Inf; |
| 34 | + dots.isSignal = true(cfg.dot.number, 1); |
| 35 | + end |
| 36 | + |
| 37 | + %% Set an array of dot positions [xposition, yposition] |
| 38 | + % These can never be bigger than 1 or lower than 0 |
| 39 | + % [0,0] is the top / left of the square |
| 40 | + % [1,1] is the bottom / right of the square |
| 41 | + dots.positions = generateNewDotPositions(cfg, cfg.dot.number); |
| 42 | + |
| 43 | + %% Set vertical and horizontal speed for all dots |
| 44 | + dots = setDotDirection(cfg, dots); |
| 45 | + |
| 46 | + [horVector, vertVector] = decomposeMotion(dots.directionAllDots); |
| 47 | + speeds = [horVector, vertVector]; |
| 48 | + |
| 49 | + % we were working with unit vectors. we now switch to pixels |
| 50 | + speeds = speeds * speedPixPerFrame; |
| 51 | + |
| 52 | + %% Create a vector to update to dotlife time of each dot |
| 53 | + % Not all set to 1 so the dots will die at different times |
| 54 | + % The maximum value is the duraion of the event in frames |
| 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.speedPixPerFrame = speedPixPerFrame; |
| 65 | + |
| 66 | +end |
| 67 | + |
| 68 | + |
0 commit comments