Spirograph

A topic started at QB64 by Ashish, I brought to TJP and developed down a couple of roads. Here is my latest:

'Spirograph RO divided by 2 - 10 = RI.bas SmallBASIC 0.12.9 (B+=MGA) 2017-07-01

rO = ymax/2 - 10 ' fit screen radius of big circle
Ox = xmax/2
Oy = ymax/2
pIndex = 0
dim px(), py()
for
ir = 2 to 10
rI = rO/ir ' smaller circle that travels inside edge of larger
OI = rO /rI ' rate inner circle spins compared to angle on outer circle
for a = 0 to 2 * pi step pi/360 'while the inner circle contacts outer at angle a
cls
circle Ox, Oy, rO, 1, 9
'the origin of inner circle at same angle
Ix = Ox + (rO - rI) * cos(a)
Iy = Oy + (rO - rI) * sin(a)
Ia = OI * a 'the angle of the inner points are OI * a on outer circle
'draw line from origin of inner circle to outer edge
color 12
wheel(Ix, Iy, rI, -Ia)
for i = 0 to pIndex-1
pset px(i), py(i), 15
next
showpage
delay 10
next
next
pause
sub
wheel(x,y,r,a)
local i, x1, y1, x2, y2
circle x, y, r
for i = 1 to 12
x1 = x + r*cos(i*2*pi/12 + a)
y1 = y + r*sin(i*2*pi/12 + a)
line x, y, x1, y1
if i = 12 then
x2 = x + r/2*cos(i*2*pi/12 + a)
y2 = y + r/2*sin(i*2*pi/12 + a)
px << x2
py << y2
pIndex = pIndex + 1
fi
next
end

Ah... This brings back memories... Nice neat lines. Not like some old leaky biro's that we used to use.. lol

Well done!!

Hey, how have you been? Should be going on mid winter in Aussie country.

The Spirograph started at QB64 was not the Spirograph of my memory, I was curious if I could work the one from my memory out in code.
I could, but I think there are other code constructions that offer much richer variation than this Spirograph that imitates the mechanical one: eg crop circles, string art, morphing curves, Superformula or what I called Pedal equations.

I did draw dots but lines could be made from one dot to next and then Paint fills could be applied. But now I remember, there was the uncertainty of knowing when to stop, that is when you use something other than an integer division of the circle. As I write this, I am seeing a connection to music notes, dividing a string length by integer lengths produces harmonious relations with rational number divisions probably much more complex harmonies, irrationals like SQR(2) may never harmonize but transcendental (like pi) might???... eh


'Spirograph wheels within wheels.bas SmallBASIC 0.12.9 (B+=MGA) 2017-07-02

rO = ymax/2 - 10 ' fit screen radius of big circle
Ox = xmax/2
Oy = ymax/2
pIndex = 0
dim mark(4)
dim px(), py()
m = 0 : mark(0) = 0
for
ir = 5 to 2 step -1
rI = rO/ir ' smaller circle that travels inside edge of larger
OI = rO /rI ' rate inner circle spins compared to angle on outer circle
for a = 0 to 2 * pi step pi/360 'while the inner circle contacts outer at angle a
cls
circle Ox, Oy, rO, 1, 9
'the origin of inner circle at same angle
Ix = Ox + (rO - rI) * cos(a)
Iy = Oy + (rO - rI) * sin(a)
Ia = OI * a 'the angle of the inner points are OI * a on outer circle
'draw line from origin of inner circle to outer edge
color 12
wheel Ix, Iy, rI, -Ia
for i = 0 to pIndex-1
pset px(i), py(i), 15
next
showpage
delay 10
next
m++
mark(m) = pIndex - 1
next
delay 2000
for
j = 0 to m-1
cls
for i = mark(j) to mark(j+1)-1
pset px(i), py(i), 15
next
? "Press any..."
showpage
pause
next


sub
wheel(x,y,r,a)
local i, x1, y1, x2, y2, rI2, Ix2, Iy2, Ia2
circle x, y, r
for i = 1 to 12
x1 = x + r*cos(i*2*pi/12 + a)
y1 = y + r*sin(i*2*pi/12 + a)
line x, y, x1, y1
if i = 12 then
x2 = x + r/2*cos(i*2*pi/12 + a)
y2 = y + r/2*sin(i*2*pi/12 + a)
px << x2
py << y2
pIndex = pIndex + 1
fi
next
if r > 20 then
rI2 = r / ir
Ix2 = x + (r - rI2) * cos(a)
Iy2 = y + (r - rI2) * sin(a)
Ia2 = r / rI2 * a
wheel Ix2, Iy2, rI2, -Ia2
end if
end

Very cool indeed... :)

J

ps: Yep. Winter is in full swing. Not like the winters you guys get. It's been at least two decades since we have had snow in Melbourne. But, summer on the other hand, got almost to 46C not too long ago...