### Author Topic: Spirograph  (Read 277 times)

#### B+

• Sr. Member
• Posts: 458
##### Spirograph
« on: 01. July 2017, 19:39:45 »
Just got the mechanism worked out, here is first fancy up:
Code: [Select]
`'Spirograph RO divided by 2 - 10 = RI.bas SmallBASIC 0.12.9 (B+=MGA) 2017-07-01rO = ymax/2 - 10 ' fit screen radius of big circleOx = xmax/2Oy = ymax/2pIndex = 0dim 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  nextnextpausesub 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  nextend`

#### B+

• Sr. Member
• Posts: 458
##### Re: Spirograph
« Reply #1 on: 03. July 2017, 04:52:52 »
Wheels within wheels:
Code: [Select]
`'Spirograph wheels within wheels.bas SmallBASIC 0.12.9 (B+=MGA) 2017-07-02rO = ymax/2 - 10 ' fit screen radius of big circleOx = xmax/2Oy = ymax/2pIndex = 0dim mark(4)dim px(), py()m = 0 : mark(0) = 0for 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 - 1nextdelay 2000for 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  pausenext 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 ifend`

#### jbk

• Newcomer
• Posts: 28
##### Re: Spirograph
« Reply #2 on: 05. July 2017, 13:31:51 »
hello B+
here's one in FreeBasic by dafhi http://www.freebasic.net/forum/viewtopic.php?p=205476#p205476
I modified the background, commenting-out the checker board background and changing the color.
the picture shown is one of an infinite of random variations
« Last Edit: 05. July 2017, 14:00:03 by jbk »

#### B+

• Sr. Member
• Posts: 458
##### Re: Spirograph
« Reply #3 on: 05. July 2017, 16:21:18 »
Hey jbk,

That is gorgeous! Thanks

That Squares thread is gigantic + humongous, I bet it has more such golden nuggets. Maybe I will do some mining when don't have a project going.

Or someone could start a highlights museum... hmm

« Last Edit: 05. July 2017, 16:28:46 by B+ »

#### Galileo

• Jr. Member
• Posts: 53
##### Re: Spirograph
« Reply #4 on: 14. August 2017, 18:41:20 »
Beauty, jbk.