aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorCody <cody@codyq.dev>2023-05-24 00:23:13 -0500
committerCody <cody@codyq.dev>2023-05-24 00:23:13 -0500
commit9c41dd96cd3652ce9c46307184e8055704655338 (patch)
tree07071d74da7398593fc5b9cfe5c4df0229ee4eb0 /examples
parent2418d68631f6e338251f2d988de2d3fde206982b (diff)
parentdf00e9ff2c2b563c79beb71ba8c510233b04f3bf (diff)
downloadsloth-9c41dd96cd3652ce9c46307184e8055704655338.tar.gz
Merge branch 'master' into compiler
Diffstat (limited to 'examples')
-rw-r--r--examples/mandelbrot.sloth24
-rw-r--r--examples/snake.sloth40
2 files changed, 64 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("*");
+ }
+ }
+}
diff --git a/examples/snake.sloth b/examples/snake.sloth
new file mode 100644
index 0000000..c60819d
--- /dev/null
+++ b/examples/snake.sloth
@@ -0,0 +1,40 @@
+var xPos = 0;
+var yPos = 0;
+# 0=right 1=down 2=left 3=up
+var direction = 0;
+
+while true {
+ if direction == 0{
+ var x = xPos + 1;
+ xPos = x;
+ }
+ if direction == 1 {
+ var y = yPos + 1;
+ yPos = y;
+ }
+ if direction == 2{
+ var x = xPos - 1;
+ xPos = x;
+ }
+ if direction == 3 {
+ var y = yPos - 1;
+ yPos = y;
+ }
+
+ var input = readln();
+ if input == "w" && direction != 1 {
+ direction = 3;
+ }
+ if input == "a" && direction != 0 {
+ direction = 2;
+ }
+ if input == "s" && direction != 3 {
+ direction = 1;
+ }
+ if input == "d" && direction != 2 {
+ direction = 0;
+ }
+
+ term_setpos(x, y);
+ print("*");
+}