omega-rosetta
aien-dev/omega-rosetta
Brought by drakestapleton
omega-rosetta / tasks / mandelbrot-set / mandelbrot-set.om
| 1 | note Rosetta Code task "Mandelbrot set": https://rosettacode.org/wiki/Mandelbrot_set |
| 2 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 3 | om2 |
| 4 | text nl "\n" |
| 5 | text pal " .:-=+*%" |
| 6 | note emit writes every byte of a to stdout; a short write is retried, an error exits 1 |
| 7 | fn emit a view uchar * to void |
| 8 | o = ulong 0 |
| 9 | while lt o len a bound 4096 |
| 10 | k = write 1 a o sub len a o |
| 11 | if le k 0 |
| 12 | exit 1 |
| 13 | end |
| 14 | o = add o ulong k |
| 15 | end |
| 16 | end |
| 17 | fn emitc c uchar to void |
| 18 | b = new uchar 1 0 |
| 19 | put b 0 c |
| 20 | emit b |
| 21 | end |
| 22 | note IEEE f64: one rounding per operator and no fused multiply-add (OMEGESE 9.9), so an |
| 23 | note independent reference in any IEEE-754 binary64 language reproduces every character |
| 24 | fn main to int |
| 25 | for r ulong 24 |
| 26 | ci = sub 1.15 mul f64 r 0.1 |
| 27 | for c ulong 72 |
| 28 | cr = sub mul f64 c 0.0375 2.2 |
| 29 | zr = f64 0.0 |
| 30 | zi = f64 0.0 |
| 31 | it = ulong 0 |
| 32 | while lt it 50 bound 50 |
| 33 | zr2 = mul zr zr |
| 34 | zi2 = mul zi zi |
| 35 | if gt add zr2 zi2 4.0 |
| 36 | break |
| 37 | end |
| 38 | zi = add mul mul 2.0 zr zi ci |
| 39 | zr = add sub zr2 zi2 cr |
| 40 | it = add it 1 |
| 41 | end |
| 42 | if eq it 50 |
| 43 | emitc 35 |
| 44 | else |
| 45 | emitc get pal rem it 8 |
| 46 | end |
| 47 | end |
| 48 | emit nl |
| 49 | end |
| 50 | ret 0 |
| 51 | end |