Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import matplotlib.pyplot as plt
- class IFSTree(object):
- def __init__(self):
- self.x = [0.4545]
- self.y = [0.0001]
- def __rule1__(self):
- y = self.y[-1]
- self.x.append(0)
- self.y.append(y*0.16)
- def __rule2__(self):
- x = self.x[-1]
- y = self.y[-1]
- self.x.append(-0.85*x+0.04*y)
- self.y.append(-0.04*x+0.85*y+1.6)
- def __rule3__(self):
- x = self.x[-1]
- y = self.y[-1]
- self.x.append(0.2*x-0.26*y)
- self.y.append(0.23*x+0.22*y+1.6)
- def __rule4__(self):
- x = self.x[-1]
- y = self.y[-1]
- self.x.append(-0.15*x+0.28*y)
- self.y.append(0.26*x+0.24*y+0.44)
- def generate(self,iter):
- i,func = 1,[self.__rule1__,self.__rule2__,self.__rule3__,self.__rule4__]
- while i <= iter:
- import random
- func[random.randrange(0,3)]()
- i+=1
- def graph(self):
- plt.plot(self.x,self.y,'go')
- plt.show()
- z = IFSTree()
- z.generate(250000) # number of iteration
- z.graph()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement