-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmake_gradient_test.py
More file actions
76 lines (63 loc) · 1.91 KB
/
Copy pathmake_gradient_test.py
File metadata and controls
76 lines (63 loc) · 1.91 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 __future__ import annotations
from PIL import Image, ImageDraw, ImageFont
W = 384
H = 560
def font(path: str, size: int):
try:
return ImageFont.truetype(path, size)
except OSError:
return ImageFont.load_default()
img = Image.new("L", (W, H), 255)
d = ImageDraw.Draw(img)
title_font = font("C:/Windows/Fonts/consolab.ttf", 20)
small_font = font("C:/Windows/Fonts/consola.ttf", 14)
d.text((8, 8), "GRADIENT TEST", fill=0, font=title_font)
y = 44
d.text((8, y), "smooth horizontal", fill=0, font=small_font)
y += 22
ramp = Image.new("L", (W - 16, 80))
pix = ramp.load()
for x in range(W - 16):
v = int(255 * x / (W - 17))
for yy in range(80):
pix[x, yy] = v
img.paste(ramp, (8, y))
d.rectangle((8, y, W - 9, y + 79), outline=0)
y += 100
d.text((8, y), "smooth vertical", fill=0, font=small_font)
y += 22
vertical = Image.new("L", (W - 16, 80))
pix = vertical.load()
for yy in range(80):
v = int(255 * yy / 79)
for x in range(W - 16):
pix[x, yy] = v
img.paste(vertical, (8, y))
d.rectangle((8, y, W - 9, y + 79), outline=0)
y += 100
d.text((8, y), "16 tone steps", fill=0, font=small_font)
y += 22
step_w = (W - 16) // 16
for i in range(16):
v = int(255 * i / 15)
x0 = 8 + i * step_w
x1 = 8 + (i + 1) * step_w - 1 if i < 15 else W - 9
d.rectangle((x0, y, x1, y + 68), fill=v)
d.rectangle((8, y, W - 9, y + 68), outline=0)
y += 88
d.text((8, y), "radial / photo-like falloff", fill=0, font=small_font)
y += 22
radial = Image.new("L", (W - 16, 150), 255)
pix = radial.load()
cx = (W - 16) / 2
cy = 75
for yy in range(150):
for x in range(W - 16):
dist = ((x - cx) ** 2 + (yy - cy) ** 2) ** 0.5
pix[x, yy] = max(0, min(255, int(dist * 2.4)))
img.paste(radial, (8, y))
d.rectangle((8, y, W - 9, y + 149), outline=0)
y += 166
d.text((8, y), "0 25 50 75 100%", fill=0, font=small_font)
img.save("gradient_test.png")
print("Wrote gradient_test.png")