From 9d178c66ef3b9f50c62d05c53f1dc772cc0f25fe Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Thu, 4 Jun 2026 21:59:28 +0530 Subject: Add voronoi --- src/voronoi.sql | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/voronoi.sql (limited to 'src') diff --git a/src/voronoi.sql b/src/voronoi.sql new file mode 100644 index 0000000..ffe621b --- /dev/null +++ b/src/voronoi.sql @@ -0,0 +1,23 @@ +INSERT OR REPLACE INTO images (id, width, height) VALUES ('voronoi', 400, 400) RETURNING id; + +WITH RECURSIVE + image AS (SELECT *, 100 AS segments FROM images WHERE id = 'voronoi'), + horizontal(x) AS + (SELECT width FROM image UNION ALL SELECT x - 1 FROM horizontal WHERE x > 1), + vertical(y) AS + (SELECT height FROM image UNION ALL SELECT y - 1 FROM vertical WHERE y > 1), + points(px, py, count) AS ( + SELECT 0, 0, 0 UNION ALL + SELECT abs(RANDOM())%width, abs(RANDOM())%height, count + 1 FROM points, image WHERE count < segments + ), + _pixels(x, y, r, g, b) AS ( + SELECT x, y, + 0, + (SELECT color FROM + (SELECT (100*(px + 1)*(py + 1)) % 255 AS color, + POW(x - px, 2) + POW(y - py, 2) as distance + FROM points ORDER BY distance ASC LIMIT 1)), + 40 + FROM vertical, horizontal, image + ) +INSERT INTO pixels (image_id, x, y, r, g, b) SELECT 'voronoi', x, y, r, g, b FROM _pixels; -- cgit v1.3.1