Advertisement
atm-irbis

Cannabis in Python (modified)

Mar 24th, 2013
403
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. from math import sin,cos
  2.  
  3. class ToPolar:
  4.     def __init__(self):
  5.         self.x = []
  6.         self.y = []
  7.     def convert(self,r,phi):
  8.         self.x.append(r*cos(phi))
  9.         self.y.append(r*sin(phi))
  10.     @property
  11.     def x(self):
  12.         return self.x
  13.     @property
  14.     def y(self):
  15.         return self.y
  16.        
  17. def cannabis(phi):
  18.     return 1+sin(phi)*(1+0.9*cos(8*phi))*(1+0.1*cos(24*phi))
  19.    
  20. class Cannabis:
  21.     def __init__(self):
  22.         self.tp = ToPolar()
  23.         self.__start__()
  24.     def __start__(self):
  25.         phi = 0.0
  26.         while phi < 360.0:
  27.             y = cannabis(phi)
  28.             self.tp.convert(y,phi)
  29.             phi+=0.01
  30.     def plot(self):
  31.         '''
  32.       plotting cannabis
  33.       '''
  34.         import matplotlib.pyplot as plt
  35.         plt.plot(self.tp.x,self.tp.y,'go')
  36.         plt.show()
  37.  
  38. x = Cannabis()
  39. x.plot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement