• Remix
  • Share
  • New Entry

on 7 Nov 2023
  • 9
  • 34
  • 1
  • 0
  • 561
drawframe(1);
Write your drawframe function below
function drawframe(f)
persistent x y h sz
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);
h = scatter(nan(n,1),nan(n,1),nan(n,1),spring(n),'.');
sz = randsize(n);
axis off
xlim([-1,1])
ylim([-1,1])
end
[th,r] = cart2pol(x,y);
r = r + 0.04; % Controls speed
[x,y] = pol2cart(th,r);
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
sz(isout) = randsize(nout); % Assign a new size to the new points
set(h,'XData',x,'YData',y,'SizeData',sz) % update scatter object
end
function s = randsize(n)
s = rand(n,1)*500+10;
end
function r = randCentered(n)
r = rand(n,1)*2-1;
end
Animation
Remix Tree