aboutsummaryrefslogtreecommitdiff
path: root/examples/mandelbrot.sloth
diff options
context:
space:
mode:
authorCody <cody@codyq.dev>2023-04-27 18:42:28 -0500
committerGitHub <noreply@github.com>2023-04-27 18:42:28 -0500
commit86eab2dc7dc2f88e0f56d09ae3b5f36cf8d9706e (patch)
treed312fd5c0981df90aef29a4131703ae89f328268 /examples/mandelbrot.sloth
parent448babe8090c2bcf177c23efd2257a926a1d07f7 (diff)
parentd6b12291db70ea19d37d84226161f964400ae0b2 (diff)
downloadsloth-86eab2dc7dc2f88e0f56d09ae3b5f36cf8d9706e.tar.gz
Merge pull request #5 from slothlang/standard-library
Standard Library
Diffstat (limited to 'examples/mandelbrot.sloth')
-rw-r--r--examples/mandelbrot.sloth24
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/mandelbrot.sloth b/examples/mandelbrot.sloth
new file mode 100644
index 0000000..bc95e2f
--- /dev/null
+++ b/examples/mandelbrot.sloth
@@ -0,0 +1,24 @@
+val size: int = 200;
+val maxVal: float = 4.0;
+val maxIter: int = 50;
+val plane: float = 4.0;
+
+for x in 0 .. size {
+ for y in 0 .. size {
+ var cReal: float = (x * plane / size) - 2;
+ var cImg: float = (y * plane / size) - 2;
+ var zReal: float = 0;
+ var zImg: float = 0;
+ var count: float = 0;
+ while (zReal * zReal + zImg * zImg) <= maxVal && count < 4{
+ var temp: float = (zReal * zReal) - (zImg * zImg) + cReal;
+ zImg = 2 * zReal * zImg + cImg;
+ zReal = temp;
+ count += 1;
+ }
+ if count == maxIter {
+ term_setpos(x, y);
+ print("*");
+ }
+ }
+}