English: An Ulam Spiral for numbers from 1 to 16008001. Note that in this picture, the number 1 is coloured black even though it is, by convention, not prime. Also, note that the image is rotated by 90 degrees clockwise when compared with this picture.
The image was generated with MATLAB in 1600 seconds. Here's my remarkably clunky and inefficient code:
function spiral
n=2000;
A=zeros(2*n+1);
B=A;
x=n+1;
y=x;
A(x,y)=true;
B(x,y)=true;
direction=1;
for i=2:(2*n+1)^2
switch direction
case 1
x=x+1;
B(x,y)=true;
A(x,y)=isprime(i);
if ~B(x,y+1)
direction=2;
end
case 2
y=y+1;
B(x,y)=true;
A(x,y)=isprime(i);
if ~B(x-1,y)
direction=3;
end
case 3
x=x-1;
B(x,y)=true;
A(x,y)=isprime(i);
if ~B(x,y-1)
direction=4;
end
case 4
y=y-1;
B(x,y)=true;
A(x,y)=isprime(i);
if ~B(x+1,y)
direction=1;
end
end
end
imwrite(imresize(~A,3,'nearest'),['output' num2str(n) '.png'],'png');