def g08_interference(rng):
"""INTERFERENCE — dot radius is the product of two plane waves at different
frequencies and headings. Where they beat, the dots swell into visible fringes."""
N = 80
c = Canvas(N, "GEOMETRIC", "dots", "interference", tiles=False)
C = c.C
f1, f2 = rng.uniform(6, 16), rng.uniform(6, 16)
a1 = math.radians(rng.uniform(0, 180))
a2 = math.radians(rng.uniform(0, 180))
mix = rng.uniform(0.0, 0.5)
for i in range(N):
for j in range(N):
u, v = (i + 0.5) / N, (j + 0.5) / N
w1 = math.sin((u * math.cos(a1) + v * math.sin(a1)) * f1 * math.tau)
w2 = math.sin((u * math.cos(a2) + v * math.sin(a2)) * f2 * math.tau)
t = 0.5 + 0.5 * (w1 * w2 * (1 - mix) + (w1 + w2) / 2 * mix)
r = 0.52 * C * clamp(t) ** 0.75
if r > 0.03 * C:
x, y = c.center(i, j)
c.circle(x, y, r)
return c