aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2026-06-04 21:59:28 +0530
committerAkshay Nair <phenax5@gmail.com>2026-06-04 21:59:52 +0530
commit9d178c66ef3b9f50c62d05c53f1dc772cc0f25fe (patch)
tree4ba6f0892fb284834dc60700db1a23adf32d6545
parent72e84fc3a354e21290b77203d226c9968ae14418 (diff)
downloadsqlite-creative-coding-9d178c66ef3b9f50c62d05c53f1dc772cc0f25fe.tar.gz
sqlite-creative-coding-9d178c66ef3b9f50c62d05c53f1dc772cc0f25fe.zip
Add voronoi
Diffstat (limited to '')
-rw-r--r--README.md5
-rw-r--r--media/voronoi.pngbin0 -> 6680 bytes
-rw-r--r--src/voronoi.sql23
3 files changed, 27 insertions, 1 deletions
diff --git a/README.md b/README.md
index ef15bbe..368a2ff 100644
--- a/README.md
+++ b/README.md
@@ -31,7 +31,10 @@ Generating some visuals with SQL because nobody stopped me. With the magic of [r
<h3><a href="./src/polka.sql">Just some dots</a></h3>
<img src="media/polka.png" />
</td>
- <td width="50%" valign="top"></td>
+ <td width="50%" valign="top">
+ <h3><a href="./src/voronoi.sql">Voronoi</a></h3>
+ <img src="media/voronoi.png" />
+ </td>
</tr>
</table>
diff --git a/media/voronoi.png b/media/voronoi.png
new file mode 100644
index 0000000..f01faf6
--- /dev/null
+++ b/media/voronoi.png
Binary files differ
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;