Share Pastebin
Guest
Public paste!

phlyingpenguin

By: a guest | Sep 4th, 2008 | Syntax: Python | Size: 1.57 KB | Hits: 41 | Expires: Never
This paste has a previous version, view the difference. Copy text to clipboard
  1. from p2d import *
  2.  
  3. sys.setrecursionlimit(100000)
  4.  
  5. p = Python2d(-2, -2, 2, 2, 1000, 1000, 0, 0, 1000, 1000)
  6.  
  7. flower4_func = lambda t: 4*math.cos(2*t)
  8. flower8_func = lambda t: 4*math.cos(4*t)
  9. spiral_func = lambda t: 0.5*t
  10. butterfly_func = lambda i: math.exp(math.cos(i)) - 2 * math.cos(4*i) + math.pow(math.sin(i/12), 5)
  11.  
  12. def polar_equation(equation,s,e):
  13.         global p
  14.         theta = arange(s, e, 0.001)
  15.         for t in theta:
  16.                 r = equation(t)
  17.                 x = r*math.cos(t)
  18.                 y = r*math.sin(t)
  19.                 p.point(x,y)
  20.  
  21. def butterfly():
  22.         polar_equation(butterfly_func, 0, 2*pi)
  23.  
  24. def multi_butterfly():
  25.         butterfly()
  26.         p.scale(0.9, 0.9)
  27.         butterfly()
  28.         p.scale(0.9, 0.9)
  29.         butterfly()
  30.         p.scale(0.9, 0.9)
  31.         butterfly()
  32.  
  33. def double_butterfly():
  34.         p.push_matrix()
  35.  
  36.         p.pop_matrix()
  37.  
  38. def spiral():
  39.         p.scale(0.1,0.1)
  40.         polar_equation(spiral_func, 0, pi*6)
  41.  
  42. def flower4():
  43.         p.scale(0.1,0.1)
  44.         polar_equation(flower4_func, 0, pi*6)
  45.  
  46. def flower8():
  47.         p.scale(0.1,0.1)
  48.         polar_equation(flower8_func, 0, pi*6)
  49.  
  50. def graph_lines():
  51.         p.set_color(0.1,0.1,0.1)
  52.         for i in xrange(-2,2):
  53.                 p.line(-2,i,2,i)
  54.                 p.line(i,-2,i,2)
  55.  
  56. graph_lines()
  57.  
  58. p.load_identity()
  59. p.translate(-1.1, -1.2)
  60. p.rotate(pi/3)
  61. p.scale(0.25, 0.25)
  62. p.set_color(0,0,1)
  63. multi_butterfly()
  64.  
  65. p.load_identity()
  66. p.translate(0.5, -1)
  67. p.rotate(-pi/4)
  68. p.scale(0.2, 0.2)
  69. p.set_color(1,0,0)
  70. multi_butterfly()
  71.  
  72. p.set_color(0,1,0)
  73. p.load_identity()
  74. p.translate(1,1)
  75. spiral()
  76.  
  77. p.set_color(1,0,1)
  78. p.load_identity()
  79. p.translate(-0.5, 1.5)
  80. flower4()
  81.  
  82. p.set_color(1,0.5,0)
  83. p.load_identity()
  84. p.translate(-1.5, 0.5)
  85. flower8()
  86.  
  87. p.render()