• Remix
  • Share
  • New Entry

on 8 Nov 2023
  • 13
  • 42
  • 0
  • 3
  • 462
drawframe(1);
Write your drawframe function below
function drawframe(f)
persistent h th s cnt
if f==1
rng default
set(gcf,"Color","k")
axes(Position=[0 0 1 1])
n=35;
cnt=rand(2,n); % center of initial polygons
xlim([0,1])
ylim(xlim)
hold on
axis off
th=2*pi*rand(5,n); % polygons are 4 coordinates along a circle
s=(rand(size(th))<.5)*2-1;
h=patch(nan,nan,"w",Clipping="off"); % polygon patches
colors = rand(n,3);
h.FaceVertexCData=colors;
h.FaceColor='flat';
end
f=0.05;
th=mod(th+0.3*s,2*pi);
th(5,:)=th(1,:);
cnt(2,:) = cnt(2,:)-1.1/48;
x=cnt(1,:)+f*cos(th);
y=cnt(2,:)+f*sin(th);
set(h,"XData",x,"YData",y)
offAx=all(y<0,1);
cnt(2,offAx)=mod(cnt(2,offAx),1)+2*f;
end
Animation
Remix Tree