-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.py
56 lines (47 loc) · 1.53 KB
/
index.py
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
from PIL import Image
import colorsys
import math
import os
width = 100
x = -0.65
y = 0
xRange = 3.4
aspectRatio = 4/3
height = round(width / aspectRatio)
yRange = xRange / aspectRatio
minX = x - xRange / 2
maxX = x + xRange / 2
minY = y - yRange / 2
maxY = y + yRange / 2
precision = 500
img = Image.new('RGB', (width, height), color = 'black')
pixels = img.load()
def logColor(distance):
color = -1 * math.log(distance, 50)
rgb = colorsys.hsv_to_rgb(0.4 + 0.9 * color,0.8,0.9)
return tuple(round(i * 255) for i in rgb)
def powerColor(distance, exp, const, scale):
color = distance**exp
rgb = colorsys.hsv_to_rgb(const + scale * color,1 - 0.6 * color,0.9)
return tuple(round(i * 255) for i in rgb)
for row in range(height):
for col in range(width):
x = minX + col * xRange / width
y = maxY - row * yRange / height
oldX = x
oldY = y
for i in range(precision + 1):
a = x*x - y*y #real component of z^2
b = 2 * x * y #imaginary component of z^2
x = a + oldX #real component of new z
y = b + oldY #imaginary component of new z
if x*x + y*y > 4:
break
if i < precision:
distance = (i + 1) / (precision + 1)
rgb = powerColor(distance, 0.2, 0.27, 1.0)
pixels[col,row] = rgb
index = row * width + col + 1
print("{} / {}, {}%".format(index, width * height, round(index / width / height * 100 * 10) / 10))
img.save('output.png')
os.system('open output.png')