aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--examples/mandelbrot.sql31
-rwxr-xr-ximage.sh2
-rw-r--r--justfile2
3 files changed, 33 insertions, 2 deletions
diff --git a/examples/mandelbrot.sql b/examples/mandelbrot.sql
new file mode 100644
index 0000000..1c25461
--- /dev/null
+++ b/examples/mandelbrot.sql
@@ -0,0 +1,31 @@
+DELETE FROM images WHERE id = 'mandelbrot';
+INSERT INTO images (id, width, height) VALUES ('mandelbrot', 400, 400) RETURNING id;
+
+WITH RECURSIVE
+ image AS (SELECT *, 0.008 AS scale, (width * 5)/7 AS ox, (height / 2) AS oy FROM images WHERE id = 'mandelbrot'),
+ 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),
+ mando(i, px, py, cx, cy, x, y) AS (
+ SELECT 0, 0.0, 0.0,
+ (SELECT (horizontal.x - ox)*scale FROM image), (SELECT (vertical.y - oy)*scale FROM image),
+ horizontal.x, vertical.y
+ FROM vertical, horizontal
+ UNION ALL
+ SELECT i + 1, px*px - py*py + cx, 2.0*px*py + cy, cx, cy, x, y FROM mando
+ WHERE (px*px + py*py) < 4.0 AND i < 20
+ ),
+ mandogrouped(x, y, i) AS (SELECT x, y, max(i) FROM mando GROUP BY x, y),
+ colors(i, r, g, b) AS (
+ SELECT 19, 255, 150, 150 UNION ALL
+ SELECT 10, 150, 120, 120 UNION ALL
+ SELECT 7, 50, 100, 100 UNION ALL
+ SELECT 0 , 0, 50, 50
+ ),
+ _pixels(x, y, r, g, b) AS (
+ SELECT x, y, c.r, c.g, c.b
+ FROM mandogrouped g
+ JOIN colors c ON c.i = (SELECT max(i) FROM colors WHERE i <= g.i)
+ )
+INSERT INTO pixels (image_id, x, y, r, g, b) SELECT 'mandelbrot', x, y, r, g, b FROM _pixels;
diff --git a/image.sh b/image.sh
index 80dba42..6a82ee6 100755
--- a/image.sh
+++ b/image.sh
@@ -4,7 +4,7 @@ DB=fun.db
[ $# -lt 1 ] && echo "Fuck" && exit 1;
-db() { sqlite3 -list "$DB" "$@"; }
+db() { sqlite3 -list -noheader "$DB" "$@"; }
image_id="$1"
echo "P3"
diff --git a/justfile b/justfile
index be55afb..f8f3413 100644
--- a/justfile
+++ b/justfile
@@ -13,7 +13,7 @@ image file *args:
show-image image_id:
echo "Displaying {{image_id}}" 1>&2
- ./image.sh {{image_id}} | magick display -
+ ./image.sh {{image_id}} | tee output.ignore.txt | magick display ppm:-
repl *args:
rlwrap sqlite3 "{{DB}}" {{args}}