• Remix
  • Share
  • New Entry

  • Josh

  • /
  • Looping Abelian Sandpiles

on 13 Nov 2023
  • 12
  • 49
  • 0
  • 0
  • 308
drawframe(24);
Write your drawframe function below
function drawframe(n)
% starting condition is a 5x5 square of piles, each with a grain "height" of 10, with 3
% rows/columns of padding to account for roll off
in=uint8(padarray(10*ones(5),[3 3],0,'both'));
o=in;
[rw,cl]=size(o);
% reversed loop created by mirroring frames 1-24 to 25-48 -> f25=f24, f26=f23, f27=f22, etc.
if n>24
n=25-(n-24);
end
for i=1:n
% frame 1 is starting condition
if n<2
break;
else
% iterate through all values in matrix and apply abelian algrorithm at elements with value >3
for r=1:rw
for c=1:cl
if in(r,c)>3
o(r-1,c)=o(r-1,c)+1;
o(r+1,c)=o(r+1,c)+1;
o(r,c-1)=o(r,c-1)+1;
o(r,c+1)=o(r,c+1)+1;
o(r,c)=o(r,c)-4;
end
end
end
end
in=o;
end
% output (o) is essentially an indexed image and just needs a colormap attached
cm=colormap(turbo(1+max(max(o))));
o=ind2rgb(o,cm);
imshow(o)
end
Animation
Remix Tree