Skip to content

Instantly share code, notes, and snippets.

@rouault
Created June 7, 2014 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rouault/862de9a1691f59f5a814 to your computer and use it in GitHub Desktop.
Save rouault/862de9a1691f59f5a814 to your computer and use it in GitHub Desktop.
Mandelbrot fractal with OGR
Credits to http://www.sqlite.org/lang_with.html#mandelbrot
$ LD_LIBRARY_PATH=/home/even/install-sqlite-3.8.5/lib:$LD_LIBRARY_PATH ogrinfo :memory: -sql "WITH RECURSIVE 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.1 FROM yaxis WHERE y<1.0),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, 2.0*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), a(t) AS (SELECT group_concat( substr(' .+*#', 1+min(iter/7,4), 1), '') FROM m2 GROUP BY cy) SELECT x'0a' || group_concat(rtrim(t),x'0a') as mandelbrot FROM a" -dialect sqlite
INFO: Open of `:memory:'
using driver `SQLite' successful.
Layer name: SELECT
Geometry: None
Feature Count: 1
Layer SRS WKT:
(unknown)
mandelbrot: String (0.0)
OGRFeature(SELECT):0
mandelbrot (String) =
....#
..#*..
..+####+.
.......+####.... +
..##+*##########+.++++
.+.##################+.
.............+###################+.+
..++..#.....*#####################+.
...+#######++#######################.
....+*################################.
#############################################...
....+*################################.
...+#######++#######################.
..++..#.....*#####################+.
.............+###################+.+
.+.##################+.
..##+*##########+.++++
.......+####.... +
..+####+.
..#*..
....#
+.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment