Advertisement
atm-irbis

Simple IFS

Feb 18th, 2013
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import matplotlib.pyplot as plt
  4.  
  5. class IFSTree(object):
  6.     def __init__(self):
  7.         self.x = [0.4545]
  8.     self.y = [0.0001]
  9.     def __rule1__(self):
  10.     y = self.y[-1]
  11.     self.x.append(0)
  12.     self.y.append(y*0.16)
  13.     def __rule2__(self):
  14.         x = self.x[-1]
  15.     y = self.y[-1]
  16.     self.x.append(-0.85*x+0.04*y)
  17.     self.y.append(-0.04*x+0.85*y+1.6)
  18.     def __rule3__(self):
  19.         x = self.x[-1]
  20.     y = self.y[-1]
  21.     self.x.append(0.2*x-0.26*y)
  22.     self.y.append(0.23*x+0.22*y+1.6)
  23.     def __rule4__(self):
  24.         x = self.x[-1]
  25.     y = self.y[-1]
  26.     self.x.append(-0.15*x+0.28*y)
  27.     self.y.append(0.26*x+0.24*y+0.44)
  28.     def generate(self,iter):
  29.         i,func = 1,[self.__rule1__,self.__rule2__,self.__rule3__,self.__rule4__]
  30.     while i <= iter:
  31.         import random
  32.         func[random.randrange(0,3)]()
  33.             i+=1
  34.     def graph(self):
  35.         plt.plot(self.x,self.y,'go')
  36.     plt.show()
  37.    
  38.        
  39. z = IFSTree()
  40. z.generate(250000) # number of iteration
  41. z.graph()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement