patterns — halfcell

generator verdict no votes yet
source — color/gen_e.g11_halfcell
def g11_halfcell(rng):
    """Marching squares — a corner triangle wherever the ramp steps up across the cell."""
    steps = rng.randint(5, 8)
    N = rng.choice([40, 50])
    c = Canvas(N, _pal(rng), steps, "halfcell", "tri")
    f = Field(rng, "mesh", warp=rng.uniform(0.15, 0.4), steps=steps)
    C = c.C
    corners = ((0, 0), (1, 0), (0, 1), (1, 1))
    ks = [[f.idx(i / N, j / N) for j in range(N + 1)] for i in range(N + 1)]
    c.ground(lambda i, j: min(ks[i + dx][j + dy] for dx, dy in corners))
    for j in range(N):
        for i in range(N):
            base = min(ks[i + dx][j + dy] for dx, dy in corners)
            x, y = i * C, j * C
            for dx, dy in corners:
                k = ks[i + dx][j + dy]
                if k == base:
                    continue
                px, py = x + dx * C, y + dy * C
                c.poly([(px, py),
                        (x + (C if dx == 0 else C / 2), py),
                        (px, y + (C if dy == 0 else C / 2))], k)
    return c
halfcell-tri-40-8190
halfcell-tri-40-8190
halfcell-tri-50-5261
halfcell-tri-50-5261
halfcell-tri-40-d78d
halfcell-tri-40-d78d
halfcell-tri-50-f48c
halfcell-tri-50-f48c
halfcell-tri-50-d94d
halfcell-tri-50-d94d

generator