A Gif showing off spirals. the last one is the most interesting one, since its the Ulam-Spiral (https://en.wikipedia.org/wiki/Ulam_spiral) where the prime numbers form a pattern. About the code: At first I had multiple variables storing the layer and direction, later I decided to reduce the variables as much as I can. I thick I can shave off the x,y too.
(687 chars)
function prim(a) if(a<=1)return false if(a<=3)return true if(a%2==0 or a%3==0)return false for i=5,sqrt(a)\1+1,6 do if(a%i==0 or a%(i+2)==0)return false end return true end function spiral(✽) local x,y,val=0,0,1 for j=0,13^2 do for i=0,sqrt(val-1) do local layer=((sqrt(val*4))%4)\1/4 pset(x,y,✽(layer,val)) x+=cos(layer) y+=sin(layer) val+=1 end if(j%5==0)flip() end end cls() flip() camera(-64,-64) rect(-46,-44,44,44) spiral(function(l,v) return l*4 end) spiral(function(l,v)return sqrt(l+v)end) spiral(function(l,v)return ((l+.2)&v/10)*10end) spiral(function(l,v)return v%5 end) spiral(function(l,v)return tonum(prim(v))*13 end) extcmd"video" |
[Please log in to post a comment]




