diff options
| author | Cody <cody@codyq.dev> | 2023-07-20 18:07:48 -0500 |
|---|---|---|
| committer | Cody <cody@codyq.dev> | 2023-07-20 18:07:48 -0500 |
| commit | 7c53e65cad365ec112d2ec1bd9c3091dbed05720 (patch) | |
| tree | dbcac7754608949e6f454726d56b9cea427468d8 /examples/mandelbrot.sloth | |
| parent | ee2133a13d61b3b3fb8fcf88f9c9781debd77d9e (diff) | |
| download | sloth-7c53e65cad365ec112d2ec1bd9c3091dbed05720.tar.gz | |
Changes
Diffstat (limited to 'examples/mandelbrot.sloth')
| -rw-r--r-- | examples/mandelbrot.sloth | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/examples/mandelbrot.sloth b/examples/mandelbrot.sloth index 391e86e..c52f5de 100644 --- a/examples/mandelbrot.sloth +++ b/examples/mandelbrot.sloth @@ -1,32 +1,35 @@ -#foreign fn print(str: String); -#foreign fn printint(i: Int); -#foreign fn as_int(x: Float) Int; +fn main() Int { + # Configuration related variables + var size: Float = 800.0; + var maxVal = 4.0; + var maxIter = 50.0; + var plane = 4.0; -#foreign fn termpos(x: Int, y: Int) Void; - -fn main() Int{ - var size: Float = 1000.0; - var maxVal: Float = 4.0; - var maxIter: Float = 50.0; - var plane: Float = 4.0; - var x: Float = 0.0; + # Loop over X the configured size + var x = 0.0; while x < size { - var y: Float = 0.0; + # Loop over Y for the configured size + var y = 0.0; while y < size { - var cReal: Float = (x * plane / size) - 2.0; - var cImg: Float = (y * plane / size) - 2.0; - var zReal: Float = 0.0; - var zImg: Float = 0.0; - var count: Float = 0.0; + # Get variables ready + var cReal = (x * plane / size) - 2.0; + var cImg = (y * plane / size) - 2.0; + var zReal = 0.0; + var zImg = 0.0; + var count = 0.0; + + # Loop over and finish mandelbrot calculations while (zReal * zReal + zImg * zImg) <= maxVal && count < maxIter { - var temp: Float = (zReal * zReal) - (zImg * zImg) + cReal; + var temp = (zReal * zReal) - (zImg * zImg) + cReal; zImg = 2.0 * zReal * zImg + cImg; zReal = temp; count = count + 1.0; - } - if as_int(count) == as_int(maxIter) { - termpos(as_int(x), as_int(y)); - print("*"); + + # Display the mandelbrot to the actual screen + if as_int(count) == as_int(maxIter) { + termpos(as_int(x), as_int(y)); + print("█"); + } } y = y + 1.0; } @@ -34,3 +37,4 @@ fn main() Int{ } return 0; } + |
