|
| 1 | +function [dots] = initializeDots(cfg, thisEvent) |
| 2 | + |
| 3 | + direction = thisEvent.direction(1); |
| 4 | + |
| 5 | + dots.lifeTime = cfg.dot.lifeTime; |
| 6 | + |
| 7 | + speedPixPerFrame = thisEvent.speed(1); |
| 8 | + |
| 9 | + % decide which dots are signal dots (1) and those are noise dots (0) |
| 10 | + dots.isSignal = rand(cfg.dot.number, 1) < cfg.dot.coherence; |
| 11 | + |
| 12 | + % for static dots |
| 13 | + if direction == -1 |
| 14 | + speedPixPerFrame = 0; |
| 15 | + dots.lifeTime = cfg.eventDuration; |
| 16 | + dots.isSignal = ones(cfg.dot.number, 1); |
| 17 | + 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] |
| 23 | + % These can never be bigger than 1 or lower than 0 |
| 24 | + % [0,0] is the top / left of the square |
| 25 | + % [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); |
| 30 | + |
| 31 | + % Coherent dots |
| 32 | + [horVector, vertVector] = decompMotion(direction); |
| 33 | + dots.speeds(dots.isSignal,:) = ... |
| 34 | + repmat([horVector, vertVector], sum(dots.isSignal), 1); |
| 35 | + |
| 36 | + % If not 100% coherence, we get new random direction for the other dots |
| 37 | + direction = rand(sum(~dots.isSignal), 1) * 360; |
| 38 | + [horVector, vertVector] = decompMotion(direction); |
| 39 | + dots.speeds(~dots.isSignal, :) = [horVector, vertVector]; |
| 40 | + |
| 41 | + % So far we were working wiht unit vectors convert that speed in pixels per |
| 42 | + % frame |
| 43 | + dots.speeds = dots.speeds * speedPixPerFrame; |
| 44 | + |
| 45 | + % Create a vector to update to dotlife time of each dot |
| 46 | + % Not all set to one so the dots will die at different times |
| 47 | + dots.time = floor(rand(cfg.dot.number, 1) * cfg.eventDuration / cfg.screen.ifi); |
| 48 | + |
| 49 | +end |
| 50 | + |
0 commit comments