Add Mandelbrot set drawing

This commit is contained in:
Diomidis Spinellis
2025-12-30 11:34:28 +02:00
parent 8c840078c5
commit e40ddb1c99
4 changed files with 125 additions and 0 deletions
+14
View File
@@ -988,6 +988,10 @@ check_output!(pi, ["-f", "script/math.sed", "input/pi"]);
// Solve the Towers of Hanoi puzzle
check_output!(hanoi, ["-f", "script/hanoi.sed", "input/hanoi"]);
////////////////////////////////////////////////////////////
// Long-running scripts
// Test with cargo test -- --ignored
// Check the output of Bach's prelude in C major from WTC book I.
// Run with cargo test test_bach_prelude_matches -- --ignored.
#[test]
@@ -1010,6 +1014,16 @@ fn test_bach_prelude_matches() {
);
}
// Draw the Mandelbrot set.
#[ignore] // Slow; takes > 15" on an i7 CPU
#[test]
fn test_mandelbrod() {
new_ucmd!()
.args(&["-En", "-f", "script/mandelbrot.sed", "input/newline"])
.succeeds()
.stdout_is_fixture("output/mandelbrot");
}
////////////////////////////////////////////////////////////
// Error handling
#[test]
+1
View File
@@ -0,0 +1 @@
+41
View File
@@ -0,0 +1,41 @@
oooooooooooooo----,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,........++----++++++....,,,,,,,,,,,,,,,,,,,,,,----..
oooooooooooo------,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,............++++,,++oooo++........,,,,,,,,,,,,,,,,,,----..
oooooooooo------,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,..............++++++oo--..oo++ ++..........,,,,,,,,,,,,,,,,--..
oooooooo--------,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,................++++++----,,,,..--oo++............,,,,,,,,,,,,--..
oooooo----------,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,..............++++oooo---- ......oo++++..........,,,,,,,,,,,,--..
oooo------------,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,................++oooo--oo -- ,,--++++++......,,,,,,,,,,,,--..
oo--------------,,,,,,,,,,,,,,,,,,,,,,,,,,,,............++++oooooo--,,.. ,,--oooo++++....,,,,,,,,,,,,--..
----------------,,,,,,,,,,,,,,,,,,,,,,,,,,..........++++oo--++ ,,....oo ++,,--oooooo++..,,,,,,,,,,,,--..
--------------,,,,,,,,,,,,,,,,,,,,,,,,............++++++--..oooo++oo ..-- --....,,--,,--++..,,,,,,,,,,,,..
--------------,,,,,,,,,,,,,,............++++++++++++++oo--,, oo,, oo++++..--++....,,,,,,,,,,..
------------,,,,,,,,,,,,,,............++++++++++++oooo--,,oo oo oo++......,,,,,,..
------------,,,,,,,,,,,,,,..........++++++++++++oooo----....oo ,,oo++++......,,,,..
----------,,,,,,,,,,,,,,......++oooooooo++oooooooo----..++oo ,,--++......,,,,,,..
----------,,,,,,,,,,........++oooo,,--------,,------,,oo --++......,,,,,,..
--------,,,,............++++++++oo++--oo....--,,,,.... ..++......,,,,,,..
--------,,,,............++++++++--..oo --++oooo------ ----oo++..,,,,,,,,..
------,,,,............++++++oo----++oo-- oo ,,,, ++++......,,,,,,..
----,,,,,,........++++++oooo--....,, .. ,,oo......,,,,,,..
--,,,,,,,,....++++++oooooo--,,oo,, ,, ++oo++........,,,,..
,,,,,,,,..++oooooo------,,,,++--++ ,,--oo++........,,,,..
,,,,,,.. ++..--oo++++........,,..
,,,,,,,,..++oooooo------,,,,++--++ ,,--oo++........,,,,..
--,,,,,,,,....++++++oooooo--,,oo,, ,, ++oo++........,,,,..
----,,,,,,........++++++oooo--....,, .. ,,oo......,,,,,,..
------,,,,............++++++oo----++oo-- oo ,,,, ++++......,,,,,,..
--------,,,,............++++++++--..oo --++oooo------ ----oo++..,,,,,,,,..
--------,,,,............++++++++oo++--oo....--,,,,.... ..++......,,,,,,..
----------,,,,,,,,,,........++oooo,,--------,,------,,oo --++......,,,,,,..
----------,,,,,,,,,,,,,,......++oooooooo++oooooooo----..++oo ,,--++......,,,,,,..
------------,,,,,,,,,,,,,,..........++++++++++++oooo----....oo ,,oo++++......,,,,..
------------,,,,,,,,,,,,,,............++++++++++++oooo--,,oo oo oo++......,,,,,,..
--------------,,,,,,,,,,,,,,............++++++++++++++oo--,, oo,, oo++++..--++....,,,,,,,,,,..
--------------,,,,,,,,,,,,,,,,,,,,,,,,............++++++--..oooo++oo ..-- --....,,--,,--++..,,,,,,,,,,,,..
----------------,,,,,,,,,,,,,,,,,,,,,,,,,,..........++++oo--++ ,,....oo ++,,--oooooo++..,,,,,,,,,,,,--..
oo--------------,,,,,,,,,,,,,,,,,,,,,,,,,,,,............++++oooooo--,,.. ,,--oooo++++....,,,,,,,,,,,,--..
oooo------------,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,................++oooo--oo -- ,,--++++++......,,,,,,,,,,,,--..
oooooo----------,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,..............++++oooo---- ......oo++++..........,,,,,,,,,,,,--..
oooooooo--------,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,................++++++----,,,,..--oo++............,,,,,,,,,,,,--..
oooooooooo------,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,..............++++++oo--..oo++ ++..........,,,,,,,,,,,,,,,,--..
oooooooooooo------,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,............++++,,++oooo++........,,,,,,,,,,,,,,,,,,----..
oooooooooooooo----,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,........++----++++++....,,,,,,,,,,,,,,,,,,,,,,----..
+69
View File
@@ -0,0 +1,69 @@
#!/bin/sed -Enf
#
# Draw the Mandelbrot set.
# Obtained from https://github.com/laserbat/mandelbrot.sed
#
# Public domain (http://unlicense.org/)
#
# usage: echo | ./mandelbrot.sed
s/.*/aaaa;/
s/a/aaaaa/g
x
:s
g
x
/;a{21}/q
/^;/s/;/&a/
s/^a//
x
s/;//
s/a*/,,-tt,&,;/
s/t/tttt/g
s/t/aaaaa/g
:g
s/(,,a*)([^;]*;)$/&\1a\2/
/,a{55}-/!bg
:l
s/[^x]*x{30,};/ ;/g
s/(-?)(a*),(-?)(a*),((-?a*),(a*),x*)/\2:x\2-\4:x\4+\6,\7\1\3+\2\2:x\4,\5x/g
s/[^;]*:x[-a]{55,}:x[^;]*,(x*);/\1;/g
s/--|\+?(-)\+?/\1/g
:m
s/(a*):(a*y*)xa/\1:\1\2x/g
s/a{18}(y*x)/y\1/g
tm
s/a{9}(y*x)/y\1/g
s/a*:a*(y*)x/\1/g
y/y/a/
s/-(a*)-(a*)/-\1\2/g
s/(a*)-(a*)\+(a*)/\1\3-\2/g
s/\+//g
:u
s/a-a/-/g
tu
s/-,/,/g
/a/bl
s/ ?x*/<&>/g
s/(x{5})*//g
s/xxxx/,/g
s/xxx/-/g
s/xx/o/g
s/x/+/g
s/<>/./g
s/[<>;]//g
s/./&&/gp
bs