Skip to content

Instantly share code, notes, and snippets.

@alvesjnr
Created February 29, 2012 15:59
Show Gist options
  • Save alvesjnr/1941980 to your computer and use it in GitHub Desktop.
Save alvesjnr/1941980 to your computer and use it in GitHub Desktop.

Como os Espirógrafos Funcionam?

Alguns de vocês devem se perguntar: "Como os espirógrafos funcionam?". Mas a maioria de vocês perguntaria antes "espiro-o-que??".

Bem, espirógrafo é aquele brinquedo que muitos de nós usamos quando pequenos para fazer umas "espirais malucas" desenhadas no papel. O brinquedo é esse aí:

Espirografo

import math
PI = math.pi
def give_dots(R,r,r_,resolution=2*PI/1000,spins=5):
def x(theta):
return (R - r) * math.cos( theta ) + r_* math.cos( (R - r) / r * theta )
def y(theta):
return (R - r) * math.sin( theta ) - r_* math.sin( (R - r) / r * theta )
theta = 0.0
while theta < 2*PI*spins:
yield (x(theta), y(theta))
theta += resolution
if __name__=='__main__':
from pylab import *
dots = give_dots(4,1.98,1.1, spins=45)
x,y = zip(*dots)
plot(x,y)
show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment