def g10_trails(rng):
"""TRAILS — many random walkers cross a wrapping grid. Each cell climbs the
density ramp per visit, so the pattern is a record of its own traffic:
worn paths go solid, untravelled ground stays open."""
N = 40
c = Canvas(N, "GLYPH", "glyph", "trails", tiles=True)
NX, NY = c.cols, c.rows
R = FULL_RAMP
hits = [[0] * NY for _ in range(NX)]
walkers = rng.randint(60, 150)
steps = rng.randint(120, 320)
inertia = rng.uniform(0.55, 0.92)
dirs = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
for _ in range(walkers):
x, y = rng.randrange(NX), rng.randrange(NY)
d = rng.choice(dirs)
for _ in range(steps):
if rng.random() > inertia:
d = rng.choice(dirs)
x = (x + d[0]) % NX
y = (y + d[1]) % NY
hits[x][y] += 1
mx = max(max(r) for r in hits) or 1
bias = rng.uniform(0.28, 0.45)
for i in range(NX):
for j in range(NY):
t = (hits[i][j] / mx) ** bias
k = int(round(t * (len(R) - 1)))
if R[k] != " ":
c.glyph(i, j, R[k])
return c