-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy path10_color_hsb.py
More file actions
32 lines (26 loc) · 904 Bytes
/
10_color_hsb.py
File metadata and controls
32 lines (26 loc) · 904 Bytes
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
from mandelbrot_03 import MandelbrotSet
from PIL import Image
from PIL.ImageColor import getrgb
from viewport import Viewport
def hsb(hue_degrees: int, saturation: float, brightness: float):
return getrgb(
f"hsv({hue_degrees % 360},"
f"{saturation * 100}%,"
f"{brightness * 100}%)"
)
if __name__ == "__main__":
print("This might take a while...")
mandelbrot_set = MandelbrotSet(max_iterations=20, escape_radius=1000)
image = Image.new(mode="RGB", size=(512, 512))
for pixel in Viewport(image, center=-0.75, width=3.5):
stability = mandelbrot_set.stability(complex(pixel), smooth=True)
pixel.color = (
(0, 0, 0)
if stability == 1
else hsb(
hue_degrees=int(stability * 360),
saturation=stability,
brightness=1,
)
)
image.show()