Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import numpy as np
- from PIL import Image, ImageColor # pillow fork of PIL
- height, width = 599, 750
- grid = np.ogrid[-1.0:1.0:1j*height, -2.0:.5:1j*width]
- c = grid[1] + 1j * grid[0]
- z = c.copy()
- logisticmap = np.zeros((height, width), dtype=np.uint8)
- x = np.arange(width, dtype=np.int64)
- for iterate in range(500):
- mandelbrot = abs(z) < 50.0
- np.putmask(z, mandelbrot, z*z + c)
- realaxis = z[height // 2 ].real
- y = np.int16( 0.15 * (4.5 - realaxis) * (height - 1))
- np.clip(y, 0, height - 1, y)
- if iterate > 100:
- logisticmap[y,x] = 1
- colors = ("white","black","red", "black")
- rgbcolors = np.uint8(list(map(ImageColor.getrgb, colors)))
- rgb = rgbcolors[logisticmap + 2 * mandelbrot]
- image = Image.fromarray(rgb, mode="RGB")
- image.save('mandelbrot-bifurcation.png')
- image.show()
Advertisement
Add Comment
Please, Sign In to add comment