aboutsummaryrefslogtreecommitdiff
path: root/src/voronoi.image.sql
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2026-06-07 17:46:08 +0530
committerAkshay Nair <phenax5@gmail.com>2026-06-07 17:46:08 +0530
commitafaf82538d09cd77ee4f5a435b79995e88be84f5 (patch)
tree5fb4db643debbd3a04b010e1470838750b427dd6 /src/voronoi.image.sql
parentb893b29d7be4fadb563187d2c6ed20865686aeff (diff)
downloadsqlite-creative-coding-afaf82538d09cd77ee4f5a435b79995e88be84f5.tar.gz
sqlite-creative-coding-afaf82538d09cd77ee4f5a435b79995e88be84f5.zip
Rename the files
Diffstat (limited to 'src/voronoi.image.sql')
-rw-r--r--src/voronoi.image.sql23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/voronoi.image.sql b/src/voronoi.image.sql
new file mode 100644
index 0000000..ffe621b
--- /dev/null
+++ b/src/voronoi.image.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;