From 72e84fc3a354e21290b77203d226c9968ae14418 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Thu, 4 Jun 2026 00:23:29 +0530 Subject: Add polka thing --- README.md | 9 ++++++++- media/polka.png | Bin 0 -> 1899 bytes src/polka.sql | 24 ++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 media/polka.png create mode 100644 src/polka.sql diff --git a/README.md b/README.md index 9bafdf2..ef15bbe 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # sqlite creative coding -Generating some visuals with SQL because nobody stopped me +Generating some visuals with SQL because nobody stopped me. With the magic of [recursive CTE](https://sqlite.org/lang_with.html). ### Dependencies - sqlite3 @@ -26,5 +26,12 @@ Generating some visuals with SQL because nobody stopped me + + +

Just some dots

+ + + + diff --git a/media/polka.png b/media/polka.png new file mode 100644 index 0000000..c15804b Binary files /dev/null and b/media/polka.png differ diff --git a/src/polka.sql b/src/polka.sql new file mode 100644 index 0000000..3d72540 --- /dev/null +++ b/src/polka.sql @@ -0,0 +1,24 @@ +INSERT OR REPLACE INTO images (id, width, height) VALUES ('polka', 400, 400) RETURNING id; + +WITH RECURSIVE + image AS (SELECT *, width/10 AS gapx, height/10 AS gapy, 16.0 AS size FROM images WHERE id = 'polka'), + 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), + dotsx(dotx, column) AS ( + SELECT 0, 0 UNION ALL + SELECT dotx + gapx, column + 1 FROM dotsx, image WHERE dotx < width + ), + dotsy(doty, row) AS ( + SELECT 0, 0 UNION ALL + SELECT doty + gapy, row + 1 FROM dotsy, image WHERE doty < height + ), + _pixels(x, y, r, g, b) AS ( + SELECT x, y, + IFNULL((SELECT 60 * abs((row % 5) - (column % 5)) FROM dotsx, dotsy + WHERE POW(x - dotx - gapx*(row%2)/2.0, 2) + POW(y - doty, 2) < size*size LIMIT 1), 0), + 50, 70 + FROM vertical, horizontal, image + ) +INSERT INTO pixels (image_id, x, y, r, g, b) SELECT 'polka', x, y, r, g, b FROM _pixels; -- cgit v1.3.1