Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. import matplotlib.pyplot as plt #needs a better plotter
  2.  
  3. class doesIt:
  4. ITERATIONS = 30
  5. DIVERGETHRESHOLD = 50.0
  6. DEBUG = False
  7.  
  8. def iterate(self, x, c):
  9. for i in range(self.ITERATIONS):
  10. x = x**2 + c
  11. if abs(x) > self.DIVERGETHRESHOLD:
  12. break
  13. yield (i, x, abs(x))
  14.  
  15. def counter(self, x, c):
  16. for (i, x, a) in self.iterate(x, c):
  17. pass
  18. return i
  19.  
  20. def printer(self, x, c):
  21. for (i, x, a) in self.iterate(x, c):
  22. print (i,x,a)
  23.  
  24. def plotter(self, x, c):
  25. # yuk
  26. xlist = []
  27. ylist = []
  28. alist = []
  29.  
  30. for (i, x, a) in self.iterate(x, c):
  31. xlist.append(x.real)
  32. ylist.append(x.imag)
  33. alist.append(a)
  34. if self.DEBUG:
  35. print ('diverged after', i)
  36. plt.plot(xlist, ylist)
  37. plt.show()
  38. plt.plot(range(len(alist)), alist)
  39. plt.show()
  40.  
  41. def searcher(self, x, start, end, step):
  42. this = start
  43. xlist = []
  44. ylist = []
  45. while this.real <= end.real:
  46. while this.imag <= end.imag:
  47. i = self.counter(x, this)
  48. if i == (self.ITERATIONS - 1):
  49. xlist.append(this.real)
  50. ylist.append(this.imag)
  51. if self.DEBUG:
  52. print (this, i)
  53. this = complex(this.real, this.imag + step)
  54. this = complex(this.real + step, start.imag)
  55. plt.axis([min(xlist), max(xlist), min(ylist), max(ylist)])
  56. plt.plot(xlist, ylist, 'b,')
  57. plt.show()
  58.  
  59. if __name__ == '__main__':
  60. it = doesIt()
  61. x = complex(0, 0)
  62. #c = complex(0.33, .587)
  63. #it.plotter(x, c)
  64. # full image
  65. # it.searcher(x, complex(-2.25, -1.5), complex(0.75, 1.5), 0.005)
  66. # left hand side
  67. 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