1.1 --- a/algorithm.py Sun Jun 13 00:18:09 2010 +0200
1.2 +++ b/algorithm.py Sun Jun 13 01:53:58 2010 +0200
1.3 @@ -1,6 +1,22 @@
1.4 -def isDivergent(f):
1.5 - if f == float("inf") or f == float("-inf"):
1.6 +import time
1.7 +
1.8 +def profile(func):
1.9 + def wrapper(*arg):
1.10 + t1 = time.clock()
1.11 + res = func(*arg)
1.12 + t2 = time.clock()
1.13 + print "duration: %fs" % float(t2-t1)
1.14 + return res
1.15 + return wrapper
1.16 +
1.17 +def isDivergent(c):
1.18 + if c.real == float("inf") or c.real == float("-inf"):
1.19 return True
1.20 + if c.imag == float("inf") or c.imag == float("-inf"):
1.21 + return True
1.22 + return False
1.23 +
1.24 +def isPeriodic(z):
1.25 return False
1.26
1.27 class Cell(object):
1.28 @@ -19,10 +35,12 @@
1.29 z = [0]
1.30 for i in xrange(max_iter):
1.31 z.append(self.iterate(z[-1], c))
1.32 - if isDivergent(z[-1].real) or isDivergent(z[-1].imag):
1.33 + if isDivergent(z[-1]):
1.34 + break
1.35 + if isPeriodic(z[-10:-1]):
1.36 break
1.37 return z
1.38 -
1.39 + @profile
1.40 def resolve(self, max_iter):
1.41 cells = {}
1.42 x_diff = (self.range[1].real - self.range[0].real) / self.resolution[0]
1.43 @@ -32,8 +50,8 @@
1.44 for y in xrange(self.resolution[1]):
1.45 for x in xrange(self.resolution[0]):
1.46 c = self.range[0] + c_diff * complex(x, y)
1.47 - print c
1.48 - print self.test(c, max_iter)
1.49 + #print c
1.50 + #print self.test(c, max_iter)
1.51
1.52
1.53