phlyingpenguin
By: a guest | Sep 4th, 2008 | Syntax:
Python | Size: 1.57 KB | Hits: 41 | Expires: Never
from p2d import *
sys.setrecursionlimit(100000)
p = Python2d(-2, -2, 2, 2, 1000, 1000, 0, 0, 1000, 1000)
flower4_func = lambda t: 4*math.cos(2*t)
flower8_func = lambda t: 4*math.cos(4*t)
spiral_func = lambda t: 0.5*t
butterfly_func = lambda i: math.exp(math.cos(i)) - 2 * math.cos(4*i) + math.pow(math.sin(i/12), 5)
def polar_equation(equation,s,e):
global p
theta = arange(s, e, 0.001)
for t in theta:
r = equation(t)
x = r*math.cos(t)
y = r*math.sin(t)
p.point(x,y)
def butterfly():
polar_equation(butterfly_func, 0, 2*pi)
def multi_butterfly():
butterfly()
p.scale(0.9, 0.9)
butterfly()
p.scale(0.9, 0.9)
butterfly()
p.scale(0.9, 0.9)
butterfly()
def double_butterfly():
p.push_matrix()
p.pop_matrix()
def spiral():
p.scale(0.1,0.1)
polar_equation(spiral_func, 0, pi*6)
def flower4():
p.scale(0.1,0.1)
polar_equation(flower4_func, 0, pi*6)
def flower8():
p.scale(0.1,0.1)
polar_equation(flower8_func, 0, pi*6)
def graph_lines():
p.set_color(0.1,0.1,0.1)
for i in xrange(-2,2):
p.line(-2,i,2,i)
p.line(i,-2,i,2)
graph_lines()
p.load_identity()
p.translate(-1.1, -1.2)
p.rotate(pi/3)
p.scale(0.25, 0.25)
p.set_color(0,0,1)
multi_butterfly()
p.load_identity()
p.translate(0.5, -1)
p.rotate(-pi/4)
p.scale(0.2, 0.2)
p.set_color(1,0,0)
multi_butterfly()
p.set_color(0,1,0)
p.load_identity()
p.translate(1,1)
spiral()
p.set_color(1,0,1)
p.load_identity()
p.translate(-0.5, 1.5)
flower4()
p.set_color(1,0.5,0)
p.load_identity()
p.translate(-1.5, 0.5)
flower8()
p.render()