-
Notifications
You must be signed in to change notification settings - Fork 26
/
resist.py
98 lines (69 loc) · 2.42 KB
/
resist.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# Experimenting with a new kind of transform (see resist.png for an example)
import pixelhouse as ph
import numpy as np
import cv2
from pixelhouse.artist import constant
def erosion_distance(canvas, kernel_size=5, depth_iterations=3, decay=0.90):
dist = np.zeros(shape=canvas.shape[:2], dtype=float)
dist += canvas.alpha / 255
mask = dist.astype(np.uint8)
ks = kernel_size
kernel = np.ones((ks, ks), np.uint8)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (ks, ks))
gamma = 1.0
for k in range(depth_iterations):
gamma *= decay
mask = cv2.erode(mask, kernel, iterations=3)
dist += gamma * mask
return dist
class rise(ph.transform.elastic.ElasticTransform):
dist = constant(None)
amplitude = constant(0.02)
theta = constant(0.0)
mode = constant("constant")
args = ("dist", "amplitude", "theta", "mode")
def draw(self, cvs, t=0.0):
coords = cvs.grid_coordinates()
cx = coords[0][:, :, 0]
cy = coords[1][:, :, 0]
dist = self.dist(t)
dx = np.zeros_like(coords[0]).astype(np.float)
dy = np.zeros_like(coords[1]).astype(np.float)
dist = np.array(dist)
theta = self.theta(t)
amplitude = cvs.transform_length(self.amplitude(t), is_discrete=False)
dy += amplitude * np.cos(theta) * dist[:, :, np.newaxis]
dx += amplitude * np.sin(theta) * dist[:, :, np.newaxis]
dy[:, :, 0] *= 0
self.transform(cvs, dy, dx, coords, self.mode(t), order=0)
pal = ph.palette(13)
# w,h = 3*600, 3*200
scale = 4
w, h = scale * 600, scale * 200
C = ph.Canvas(w, h)
C += ph.text(
"RESIST",
x=0,
y=0.5,
font="TitilliumWeb-Black.ttf",
vpos="center",
font_size=2.50,
)
dist = erosion_distance(
C, kernel_size=3, decay=0.8, depth_iterations=20
).tolist()
C = ph.Animation(w, h, bg=pal[-1])
n, tc = 40, 0.020
lg = ph.gradient.linear([pal[0], pal[1]])
for y in np.linspace(1.25 * C.ymin, 1.25 * C.ymax, n):
C += ph.line(C.xmin, y, C.xmax, y, thickness=tc, gradient=lg)
C += ph.filters.gaussian_blur(0.10, 0.10)
for y in np.linspace(1.25 * C.ymin, 1.25 * C.ymax, n):
C += ph.line(C.xmin, y, C.xmax, y, thickness=tc, gradient=lg)
z = ph.motion.easeInQuad(0, 0.030, flip=True)
C += rise(dist, amplitude=z)
X = C.render(len(C) // 2)
X += ph.transform.scale(1.0 / scale, 1.0 / scale)
X += ph.filters.gaussian_blur(0.50, 0)
X.save("figures/resist.png")
X.show()