Skip to content

Commit ad07055

Browse files
committed
refactoring dot functions
1 parent 9578e80 commit ad07055

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

src/dot/computeCartCoord.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
function cartesianCoordinates = computeCartCoord(positions, cfg)
22
cartesianCoordinates = ...
3-
[positions(:,1) - cfg.screen.winWidth / 2, ... % x coordinate
4-
positions(:,2) + cfg.screen.winWidth / 2]; % y coordinate
3+
[positions(:,1) + cfg.dot.matrixWidth, ... % x coordinate
4+
positions(:,2) + cfg.dot.matrixWidth]; % y coordinate
5+
6+
% cartesianCoordinates = positions;
57
end

src/dot/generateNewDotPositions.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function newPositions = generateNewDotPositions(cfg, dotNumber)
2+
3+
newPositions = rand(dotNumber, 2) * cfg.dot.matrixWidth;
4+
5+
end

src/dot/initDots.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
% These can never be bigger than 1 or lower than 0
3939
% [0,0] is the top / left of the square
4040
% [1,1] is the bottom / right of the square
41-
dots.positions = rand(cfg.dot.number, 2) * cfg.screen.winWidth;
41+
dots.positions = generateNewDotPositions(cfg, cfg.dot.number);
4242

4343
%% Set vertical and horizontal speed for all dots
4444
dots = setDotDirection(cfg, dots);

src/dot/reseedDots.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
cartesianCoordinates = computeCartCoord(dots.positions, cfg);
99
[~, radius] = cart2pol(cartesianCoordinates(:, 1), cartesianCoordinates(:, 2));
1010

11+
12+
1113
% Create a logical vector to detect any dot that has:
1214
% - an xy position inferior to 0
1315
% - an xy position superior to winWidth
@@ -16,24 +18,26 @@
1618
% - has been been picked to be killed
1719

1820
N = any([ ...
19-
dots.positions > cfg.screen.winWidth, ...
21+
dots.positions > cfg.dot.matrixWidth, ...
2022
dots.positions < 0, ...
2123
dots.time > dots.lifeTime, ...
2224
radius - cfg.dot.sizePix < fixationWidthPix / 2, ...
2325
rand(cfg.dot.number, 1) < cfg.dot.proportionKilledPerFrame, ...
2426
], 2) ;
25-
27+
2628
% If there is any such dot we relocate it to a new random position
2729
% and change its lifetime to 1
2830
if any(N)
2931

30-
dots.positions(N, :) = rand(sum(N), 2) * cfg.screen.winWidth;
32+
dots.positions(N, :) = generateNewDotPositions(cfg, sum(N));
3133

3234
dots = setDotDirection(cfg, dots);
35+
3336
[horVector, vertVector] = decomposeMotion(dots.directionAllDots);
3437
dots.speeds = [horVector, vertVector] * dots.speedPixPerFrame;
3538

3639
dots.time(N, 1) = 1;
40+
3741
end
3842

3943
end

0 commit comments

Comments
 (0)