aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/circle.sql7
-rw-r--r--src/gradient.sql5
-rw-r--r--src/mandelbrot.sql3
3 files changed, 6 insertions, 9 deletions
diff --git a/src/circle.sql b/src/circle.sql
index 46874cc..c4ac18a 100644
--- a/src/circle.sql
+++ b/src/circle.sql
@@ -1,9 +1,8 @@
-DELETE FROM images WHERE id = 'circle';
-INSERT INTO images (id, width, height) VALUES ('circle', 200, 200) RETURNING id;
+INSERT OR REPLACE INTO images (id, width, height) VALUES ('circle', 400, 400) RETURNING id;
WITH RECURSIVE
image AS (SELECT * FROM images WHERE id = 'circle'),
- circle AS (SELECT width/2 AS cx, height/2 AS cy, 80 AS radius FROM image),
+ circle AS (SELECT width/2 AS cx, height/2 AS cy, 160 AS radius FROM image),
horizontal(x) AS
(SELECT width FROM image UNION ALL SELECT x - 1 FROM horizontal WHERE x > 1),
vertical(y) AS
@@ -11,7 +10,7 @@ WITH RECURSIVE
_pixels(x, y, r, g, b) AS (SELECT
x, y,
150,
- 255 * MAX(0, MIN(1, (SELECT POW(x - cx, 2) + POW(y - cy, 2) - POW(radius, 2) FROM circle))),
+ 255 * MAX(0, MIN(1, (SELECT (x - cx)*(x - cx) + (y - cy)*(y - cy) - radius*radius FROM circle))),
150
FROM vertical, horizontal
)
diff --git a/src/gradient.sql b/src/gradient.sql
index f04cdad..4ad1820 100644
--- a/src/gradient.sql
+++ b/src/gradient.sql
@@ -1,5 +1,4 @@
-DELETE FROM images WHERE id = 'gradient';
-INSERT INTO images (id, width, height) VALUES ('gradient', 200, 200) RETURNING id;
+INSERT OR REPLACE INTO images (id, width, height) VALUES ('gradient', 400, 400) RETURNING id;
WITH RECURSIVE
image AS (SELECT * FROM images WHERE id = 'gradient'),
@@ -8,5 +7,5 @@ WITH RECURSIVE
vertical(y) AS
(SELECT height FROM image UNION ALL SELECT y - 1 FROM vertical WHERE y > 1),
_pixels(x, y, r, g, b) AS
- (SELECT x, y, mod(x, 255), mod(y, 255), 100 FROM vertical, horizontal)
+ (SELECT x, y, x*255/width, y*255/height, 100 FROM vertical, horizontal, image)
INSERT INTO pixels (image_id, x, y, r, g, b) SELECT 'gradient', x, y, r, g, b FROM _pixels;
diff --git a/src/mandelbrot.sql b/src/mandelbrot.sql
index 1c25461..b83b751 100644
--- a/src/mandelbrot.sql
+++ b/src/mandelbrot.sql
@@ -1,5 +1,4 @@
-DELETE FROM images WHERE id = 'mandelbrot';
-INSERT INTO images (id, width, height) VALUES ('mandelbrot', 400, 400) RETURNING id;
+INSERT OR REPLACE 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'),