Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt #needs a better plotter
- class doesIt:
- ITERATIONS = 30
- DIVERGETHRESHOLD = 50.0
- DEBUG = False
- def iterate(self, x, c):
- for i in range(self.ITERATIONS):
- x = x**2 + c
- if abs(x) > self.DIVERGETHRESHOLD:
- break
- yield (i, x, abs(x))
- def counter(self, x, c):
- for (i, x, a) in self.iterate(x, c):
- pass
- return i
- def printer(self, x, c):
- for (i, x, a) in self.iterate(x, c):
- print (i,x,a)
- def plotter(self, x, c):
- # yuk
- xlist = []
- ylist = []
- alist = []
- for (i, x, a) in self.iterate(x, c):
- xlist.append(x.real)
- ylist.append(x.imag)
- alist.append(a)
- if self.DEBUG:
- print ('diverged after', i)
- plt.plot(xlist, ylist)
- plt.show()
- plt.plot(range(len(alist)), alist)
- plt.show()
- def searcher(self, x, start, end, step):
- this = start
- xlist = []
- ylist = []
- while this.real <= end.real:
- while this.imag <= end.imag:
- i = self.counter(x, this)
- if i == (self.ITERATIONS - 1):
- xlist.append(this.real)
- ylist.append(this.imag)
- if self.DEBUG:
- print (this, i)
- this = complex(this.real, this.imag + step)
- this = complex(this.real + step, start.imag)
- plt.axis([min(xlist), max(xlist), min(ylist), max(ylist)])
- plt.plot(xlist, ylist, 'b,')
- plt.show()
- if __name__ == '__main__':
- it = doesIt()
- x = complex(0, 0)
- #c = complex(0.33, .587)
- #it.plotter(x, c)
- # full image
- # it.searcher(x, complex(-2.25, -1.5), complex(0.75, 1.5), 0.005)
- # left hand side
- it.searcher(x, complex(-1.5, -0.5), complex(-0.5, 0.5), 0.005)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement