Page 1 of 1

Spirograph

Posted: Thu Apr 11, 2013 4:58 pm
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

Re: Spirograph

Posted: Thu Apr 11, 2013 6:55 pm
by Mr. Kibernetik
This is a very nice program! :D

Re: Spirograph

Posted: Fri Apr 12, 2013 9:57 am
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

Re: Spirograph

Posted: Wed Nov 10, 2021 10:25 am
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 !

Re: Spirograph

Posted: Thu Nov 11, 2021 6:35 pm
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.