Page MenuHomeDevCentral
Paste P291

mandelbrot-inspired-spaceship.sql
ActivePublic

Authored by dereckson on Feb 24 2020, 07:42.
Tags
None
Referenced Files
F875330: raw.txt
Feb 24 2020, 07:42
Subscribers
None
WITH RECURSIVE
-- Grid of points for which the Mandelbrot set will be approximated
xaxis(x) as (VALUES(-2.0) UNION ALL SELECT x+0.05 FROM xaxis WHERE x < 1.2),
yaxis(y) as (VALUES(-1.0) UNION ALL SELECT y+0.10 FROM yaxis WHERE y < 1.0),
-- Mandelbrot iterations
m(iter, cx, cy, x, y) AS (
SELECT 0, x, y, 0.0, 0.0 FROM xaxis, yaxis
UNION ALL
SELECT iter + 1, cx, cy, x*x - y*y + cx, x*y*(x+y) + cy FROM m
WHERE (x*x + y*y) < 4.0 AND iter < 28
),
m2(iter, cx, cy) AS (
SELECT max(iter), cx, cy FROM m GROUP BY cx, cy
),
-- ASCII representation line per line
a(t) AS (
SELECT group_concat(substr(' .+*#', 1 + min(iter/7, 4), 1), '')
FROM m2 GROUP BY cy
)
-- All lines
SELECT group_concat(rtrim(t), x'0a') FROM a;

Event Timeline

dereckson changed the title of this paste from untitled to mandelbrot-inspired-spaceship.sql.