Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- from math import log2, log1p
- import time
- w, h = 900, 720
- t1 = time.time()
- xc, yc = -0.6, 0.005
- mag = 0.65
- imax, zmax = 190, 50
- blues = [(v**4, v**2.5, v) for v in (0.2 + x/200 for x in range(160))]
- sepias = [(v, v**1.5, v**3) for v in (x/96 for x in range(95, -1, -1))]
- rgbcolors = [[int(256 * v) for v in x] for x in blues + sepias]
- databytes = bytearray([])
- for y in range(h):
- for x in range(w):
- c = complex(xc + (2*x - w) / (w*mag), -yc - (2*y - h) / (w*mag))
- z = complex(0.0, 0.0)
- backgnd = 0
- for i in range(imax):
- z = z * z + c
- if abs(z) >= zmax:
- backgnd = log1p(i + 0.1 - log2(log2(abs(z) + 1))) / 5.25
- break
- databytes += bytearray(rgbcolors[int(backgnd * 255)])
- with open('mand.ppm','wb') as fout:
- fout.write("P6\n{} {}\n255\n".format(w,h).encode("ascii"))
- fout.write(databytes)
- print("Elapsed time: {:7.2f} s".format(time.time() - t1))
Add Comment
Please, Sign In to add comment