source — gen_b.g09_halftone
def g09_halftone(rng):
"""HALFTONE RELIEF — a synthetic lit surface (lambert term from a tilted
normal field) resolved through the measured density ramp. The ramp spans the
full available range, blocks included, so the surface can actually go dark."""
N = 40
c = Canvas(N, "GLYPH", "glyph", "halftone", tiles=False)
NX, NY = c.cols, c.rows
R = FULL_RAMP
nz = Value2D(rng, res=rng.choice([3, 4, 6]))
lx, ly = rng.uniform(-1, 1), rng.uniform(-1, 1)
lm = math.hypot(lx, ly) + 1e-6
lx, ly = lx / lm, ly / lm
amp = rng.uniform(2.5, 6.0)
gamma = rng.uniform(0.55, 1.05)
h = 1.0 / NX
for i in range(NX):
for j in range(NY):
u, v = (i + 0.5) / NX, (j + 0.5) / NY
gx = (nz(u + h, v) - nz(u - h, v)) * amp
gy = (nz(u, v + h) - nz(u, v - h)) * amp
lam = clamp(0.55 - (gx * lx + gy * ly) * 1.5)
k = int(round((1 - clamp(lam ** gamma)) * (len(R) - 1)))
if R[k] != " ":
c.glyph(i, j, R[k])
return c