- /
-
Sierpinski carpet from Chaos game
on 6 Oct 2021
- 1
- 123
- 5
- 0
- 228
N=10^5;
v=zeros(N,2);
a=8;
%vertices and midpoints of a square
c=[[-1,1];[-1 0];[-1,-1];[0 1];[1,0];[0,-1];[1,1];[1,-1]];
p=[0,0];
lc=1;
for i=1:N
idx=randi(a);
lc=idx;
s=c(idx,:);
p=(p+s)/3;
v(i,:)=p;
end
plot(v(:,1),v(:,2),'.',markersize=1)
xlim([-0.5,0.5])
ylim([-0.5,0.5])
axis off equal