Fibanacci3.bas

Posted by an anonymous user


#!/usr/local/bin/sbrun -g
cls
midy = ymax/2
midx = xmax/2
otx=midx
oty=midy
n=1.6180339887499
n=n+(n/4.25)
ot=1
dim t(2)
t(1)=1
for
j=1 to 12
ot=t(1)+t(2)
if
ot>0
? ot
a=a+1
if
a=1 then tx=midx+ot: ty=midy+ot:midx=tx+ot:midy=ty+ot:arc tx+ot,ty-ot, ot*n, RAD(90), RAD(180)
if
a=2 then tx=midx+ot: ty=midy-ot:midx=tx+ot:midy=ty-ot:arc tx-ot,ty-ot, ot*n, RAD(0), RAD(90)
if
a=3 then tx=midx-ot: ty=midy-ot:midx=tx-ot:midy=ty-ot:arc tx-ot,ty+ot, ot*n, RAD(270), RAD(0)
if
a=4 then tx=midx-ot: ty=midy+ot:midx=tx-ot:midy=ty+ot:arc tx+ot,ty+ot, ot*n, RAD(180), RAD(270):a=0

line tx-ot,ty+ot,tx+ot,ty+ot
line tx-ot,ty-ot,tx+ot,ty-ot
line tx-ot,ty-ot,tx-ot,ty+ot
line tx+ot,ty-ot,tx+ot,ty+ot
ax=j-sin(j)
ay=j-cos(j)

endif
t(1)=t(2)
t(2)=ot
next
j
? "Press any key to exit"
while ok=""
ok=inkey
wend
end

Comments

I slightly rearanged the original program, and fixed the 'size' factor (g) to value 2 (instead of 1.998747), which fits perfectly wth the initial radius (a=1) of golden spiral.
One can experiment with other values, but it looks great on my tablet with 600x976 pixels, as well on win-7.

def f(x)=iff(x<2,x,(f(x-1)+f(x-2)))
y=250:x=400:ph=pi/2:n=(sqr(5)+1)/2:g=2 ':g=n+n/4.25
'Fibonacci spiral - approximation - white
for j=1 to 13:a=(j-1)%4:s=f(j):t=g*s:?s
select case a
case 0:x+=t:arc x,y,t,ph,pi,1,15:y+=t:u=-t:v=-t
case 1:y-=t:arc x,y,t,0,ph,1,15:x+=t:u=-t:v=t
case 2:x-=t:arc x,y,t,-ph,0,1,15:y-=t:u=t:v=t
case 3:y+=t:arc x,y,t,pi,-ph,1,15:x-=t:u=t:v=-t
end select
rect x,y,step u,v
next

'True golden spiral - yellow colored
'actual starting point: it starts at pi/2, with r=2
y=251:x=402:b=2*log(n)/pi:q=6.6*pi:a=1
for j=0 to q step 0.002
ax=x-a*exp(b*j)*cos(j):ay=y+a*exp(b*j)*sin(j)
pset ax,ay,14
next
pause
stop