• Remix
  • Share
  • New Entry

on 8 Nov 2023
  • 10
  • 22
  • 0
  • 0
  • 527
drawframe(1);
Write your drawframe function below
function drawframe(f)
persistent x y h r
if f==1 || isempty(x)
% Creat scatter object
set(gcf,'color','k')
axes('Position',[0 0 1 1])
hold on
n = 500;
x = randCentered(n);
y = randCentered(n);
r = rand(n,1)*0.1+0.21;
h = scatter(nan(n,1),nan(n,1),nan(n,1),'.');
axis off
xlim([-1,1])
ylim([-1,1])
end
[th,rho] = cart2pol(x,y);
rho = rho + 0.04; % Controls speed
[x,y] = pol2cart(th,rho);
isout = abs(x)>1 | abs(y)>1; % find points outsize of axes limits
nout = sum(isout);
x(isout) = randCentered(nout); % replace points outside of limits
y(isout) = randCentered(nout); % replace points outside of limits
r(isout) = rand(nout,1)*0.1+0.01; % Assign a new radius to the new points
set(h,'XData',x,'YData',y,'SizeData',r*1000) % update scatter object
end
function r = randCentered(n)
r = rand(n,1)*2-1;
end
Animation
Remix Tree