File tree Expand file tree Collapse file tree 2 files changed +24
-19
lines changed Expand file tree Collapse file tree 2 files changed +24
-19
lines changed Original file line number Diff line number Diff line change 1+ function dots = reseedDots(dots , cfg )
2+
3+ % Create a logical vector to detect any dot that has:
4+ % - an xy position inferior to 0
5+ % - an xy position superior to winWidth
6+ % - has exceeded its liftime
7+ % - has been been picked to be killed
8+ N = any([ ...
9+ dots .positions > cfg .screen .winWidth , ...
10+ dots .positions < 0 , ...
11+ dots .time > dots .lifeTime , ...
12+ rand(cfg .dot .number , 1 ) < cfg .dot .proportionKilledPerFrame ], 2 ) ;
13+
14+ % If there is any such dot we relocate it to a new random position
15+ % and change its lifetime to 1
16+ if any(N )
17+ dots .positions(N , : ) = rand(sum(N ), 2 ) * cfg .screen .winWidth ;
18+ dots .time(N , 1 ) = 1 ;
19+ end
20+
21+ end
Original file line number Diff line number Diff line change 66 if all(isnan(dots .positions(: )))
77 errorStruct.message = ' All dots position have NaN values.' ;
88 errorStruct.identifier = ' updateDots:onlyNans' ;
9-
9+
1010 error(errorStruct );
1111 end
1212
13- % Create a logical vector to detect any dot that has:
14- % - an xy position inferior to 0
15- % - an xy position superior to winWidth
16- % - has exceeded its liftime
17- % - has been been picked to be killed
18- N = any([ ...
19- dots .positions > cfg .screen .winWidth , ...
20- dots .positions < 0 , ...
21- dots .time > dots .lifeTime , ...
22- rand(cfg .dot .number , 1 ) < cfg .dot .proportionKilledPerFrame ], 2 ) ;
23-
24- % If there is any such dot we relocate it to a new random position
25- % and change its lifetime to 1
26- if any(N )
27- dots .positions(N , : ) = rand(sum(N ), 2 ) * cfg .screen .winWidth ;
28- dots .time(N , 1 ) = 1 ;
29- end
13+ dots = reseedDots(dots , cfg );
3014
3115 % Add one frame to the dot lifetime to each dot
3216 dots.time = dots .time + 1 ;
33-
17+
3418end
You can’t perform that action at this time.
0 commit comments