def g04_castshadow(rng):
"""CAST SHADOW — a white plate with a black outline sits over a solid black
copy of itself, offset by a quantised elevation. Elevation is a noise field,
so the sheet reads as buckled."""
N = 20
c = Canvas(N, "GEOMETRIC", "squares", "castshadow", tiles=False)
C = c.C
nz = Value2D(rng, res=rng.choice([3, 4, 5]))
dx = rng.choice([1, 1, -1])
size = rng.uniform(0.62, 0.78) * C
sw = rng.uniform(0.045, 0.075) * C
shadows, plates = [], []
for i in range(N):
for j in range(N):
u, v = (i + 0.5) / N, (j + 0.5) / N
e = int(round(nz(u, v) * 2.49)) # 0,1,2 -> offsets of 0, C/2, C
x, y = c.center(i, j)
if e:
shadows.append((x + dx * e * C / 2, y + e * C / 2))
plates.append((x, y))
for (x, y) in shadows:
c.rect(x, y, size, size, fill="#000000")
for (x, y) in plates:
c.rect(x, y, size, size, fill="#FFFFFF", stroke="#000000", sw=sw)
return c