Author Topic: Spirograph  (Read 1548 times)

B+

  • Guest
Spirograph
« on: July 01, 2017, 05:39:45 PM »
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-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

B+

  • Guest
Re: Spirograph
« Reply #1 on: July 03, 2017, 02:52:52 AM »
Wheels within wheels:
Code: [Select]
'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

jbk

  • Guest
Re: Spirograph
« Reply #2 on: July 05, 2017, 11:31:51 AM »
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: July 05, 2017, 12:00:03 PM by jbk »

B+

  • Guest
Re: Spirograph
« Reply #3 on: July 05, 2017, 02:21:18 PM »
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: July 05, 2017, 02:28:46 PM by B+ »

Galileo

  • Guest
Re: Spirograph
« Reply #4 on: August 14, 2017, 04:41:20 PM »
Beauty, jbk.