Spirograph

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Spirograph

Post by Henko »

option base 1
option angle degrees
randomize
graphics
fill color 0,0,0
maxx=screen_width()
maxy=screen_height()
cx=maxx/2
cy=maxy/2
bigr=300
omega=10
dt=1
loop:
fill rect 0,0 to maxx,maxy
smalr=rnd(150)+100
ratio=smalr/bigr
graphics lock
draw to cx+bigr,cy
for t=0 to 5000 step dt
  theta=omega*t
  alfa=ratio*theta
  x=cx+(bigr-smalr)*cos(alfa)+smalr*cos(theta)
  y=cy+(bigr-smalr)*sin(alfa)+smalr*sin(theta)
  draw line to x,y
  next t
graphics unlock
pause 1
goto loop
end

User avatar
Mr. Kibernetik
Site Admin
Posts: 4782
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: Spirograph

Post by Mr. Kibernetik »

This is a very nice program! :D

Elchoud
Posts: 9
Joined: Wed Nov 21, 2012 3:31 am

Re: Spirograph

Post by Elchoud »

Very Nice indeed, thank You Henko for posting.
I made a small twist on speed and color, hope others will like it as well:

option base 1
option angle degrees
randomize
graphics
fill color 0,0,0
maxx=screen_width()
maxy=screen_height()
cx=maxx/2
cy=maxy/2
bigr=300
omega=10
dt=1
P=0.1
gosub btns
randomize
loop:
draw color rnd(1),rnd(1),rnd(1)
fill rect 0,0 to maxx,maxy
smalr=rnd(150)+100
ratio=smalr/bigr
graphics lock
draw to cx+bigr,cy
for t=0 to 5000 step dt
theta=omega*t
alfa=ratio*theta
x=cx+(bigr-smalr)*cos(alfa)+smalr*cos(theta)
y=cy+(bigr-smalr)*sin(alfa)+smalr*sin(theta)
draw line to x,y
next t
graphics unlock
gosub btchk
pause P
goto loop

btns:
BUTTON "A" TITLE "-" AT 10,maxy-50 SIZE 40,25
BUTTON "B" TITLE "+" AT Maxx-50,maxy-50 SIZE 40,25
return

btchk:
if BUTTON_PRESSED ("A") then
Rem Slow Down
P=P+0.1
if P>1 then P=1
SP = (1.1-P)*10
DRAW TEXT " Speed: " & SP AT maxx/2- 80, 20
end if
if BUTTON_PRESSED ("B") then
Rem Speed Up
P=P-0.1
if P<0.1 then P=0.1
SP = (1.1-P)*10
DRAW TEXT " Speed: " & SP AT maxx/2- 80, 20
end if
return

end

smbstarv
Posts: 98
Joined: Wed Nov 27, 2013 3:44 pm
My devices: Ipad 6th gen
Flag: Netherlands
Contact:

Re: Spirograph

Post by smbstarv »

I programmed a spirograph the other day, just before I found out you did this already in 2013 !
However I found the addition of " -alfa " in the second terms is more precise...
X=....*cos(alfa)+.....*cos(theta-alfa)
Y=....*sin(alfa)+.....*sin(theta-alfa)
Anyway the emerging drawings remain fun !

smbstarv
Posts: 98
Joined: Wed Nov 27, 2013 3:44 pm
My devices: Ipad 6th gen
Flag: Netherlands
Contact:

Re: Spirograph

Post by smbstarv »

I'm sorry about my previous comment, as it is wrong. I shouldn't have it submitted.
Still I have a problem with the calculation of the coordinates of the spirals, as generated.
In the program the ratio is stated between the angular speeds of the inner and outer circles, named theta and alfa respectively.
This ratio is calculated as ratio=bigr/smalr. However this should be ratio=(bigr-smalr)/smalr.

Post Reply