Chaos game on a square

Mike Croucher on 4 Oct 2021
  • 1
  • 118
  • 12
  • 225
N=10^5;
v=zeros(N,2);
a=4;
t=linspace(0,2*pi,a+1);
c=[cos(t);sin(t)]';
p=[0,0];
lc=1;
for i=1:N
idx=randi(a);
while idx==lc % don't use the same vertex as last time
idx=randi(a);
end
lc=idx;
s=c(idx,:);
p=(p+s)/2;
v(i,:)=p;
end
plot(v(:,1),v(:,2),'.',markersize=1)
xlim([-1,1])
ylim([-1,1])
axis off

Remix tree

Load full remix tree