-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathch31.py
More file actions
76 lines (53 loc) · 1.59 KB
/
ch31.py
File metadata and controls
76 lines (53 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from decimal import Decimal
from PIL import Image
H = 480
W = 640
def mine():
orig_img = Image.open('mandelbrot.gif')
print orig_img.mode
pal = orig_img.getpalette()
#orignal image needs to be vertically flipped to be right orientation for comparison with our mandelbrot img
orig_img = orig_img.transpose(Image.FLIP_TOP_BOTTOM)
# draw our own mandelbrot fractal
# starting drawing area - left="0.34" top="0.57" width="0.036" height="0.027"
height = 0.027
width = 0.036
x_start = 0.34
y_start = 0.57 #html top means bottom!
maxIt = 128 # max iterations allowed
# image size
imgx = W
imgy = H
image = Image.new("P", (imgx, imgy))
image.putpalette(pal)
diffs = []
diffvals = []
image_data = []
for y in xrange(imgy):
# print y
cy = float(y) * height / float(imgy) + y_start
for x in xrange(imgx):
cx = float(x) * width / float(imgx) + x_start
c = complex(cx, cy)
z = complex(0.0)
for i in xrange(1, maxIt+1):
if abs(z) >= 2:
break
z = z * z + c
#the closer i is to maxIt, the better this current point is a part of the mandelbrot set
iterations = i-2
image_data.append(iterations)
orig = orig_img.getpixel((x,y))
diff = orig-iterations
if abs(diff) > 0 and orig != 127: # orig = 127 pixels are just wierd
diffs.append(diff)
diffvals.append(iterations)
image.putdata(image_data)
image.show()
print len(diffs)
# print diffs[:100]
# print diffvals[:100]
# print ''.join(chr(x) for x in diffvals)
if __name__ == '__main__':
# other()
mine()