Help with an expanding dot cloud (DrawDots)

Hi all,
I’ve been trying to create an expanding dot cloud using DrawDots, to suggest moving forward towards a point in the center of the screen. So far I’ve managed to create an expanding cloud from the ExpandingRings demo, however, I can’t work out how to confine it within a rectangular aperture (as used with DrawDots moving in the same direction), or how to loop it to send dots that go past the edge of the screen back to the beginning or to recreate them elsewhere - currently I have a firework rather than continuous flow! I’ve attached the section of code for this below, it makes a firework when the loop at boundaries part is not included but when it is included it restricts the stimulus to the top portion of the screen.
Does anyone have a better idea of how I can create a continuous loop of expanding dots that move from the center towards the edge of a pre-defined box, or let me know where I’m going wrong with looping it back around?
Thank you for any help anyone can offer,
Beth

% apeture setup
apSizeX = screenXpixels;
apSizeY = screenYpixels;

xPosMax = screenXpixels;
xPosMin = 0;
yPosMax = screenYpixels;
yPosMin = 0;

% dot start position
dotXpos = apSizeX * rand(1, numDots);
dotYpos = apSizeY * rand(1, numDots);

% dot movement
th = 2pirand(1, numDots);
xPos = dotXpos .* cos(th);
yPos = dotYpos .* sin(th);
motionDir = 1;
dr = dotSpeed * motionDir;
dx = dr .* cos(th);
dy = dr .* sin(th);

% animation loop
while ~KbCheck
xPos = xPos + dx;
yPos = yPos + dy;
xyPos = [xPos; yPos];
Screen(‘DrawDots’, window, xyPos, dotWidth, dotColour, dotCenter, 1);

    % loop at boundaries
    xPosM(xPosM < xPosMin) = xPosM(xPosM < xPosMin) + xPosMax;
    xPosM(xPosM < xPosMax) = xPosM(xPosM < xPosMax) - xPosMax;
    yPosM(yPosM < yPosMin) = yPosM(yPosM < yPosMin) + yPosMax;
    yPosM(yPosM < yPosMax) = yPosM(yPosM < yPosMax) - yPosMax;
    
    Screen('Flip', window);

end

Have you looked at DotDemo.m? That seems close to what you want.

1 Like