aboutsummaryrefslogtreecommitdiff
path: root/examples/mandelbrot.sloth
diff options
context:
space:
mode:
authorCody <cody@codyq.dev>2023-07-20 18:13:34 -0500
committerCody <cody@codyq.dev>2023-07-20 18:13:34 -0500
commit1219f5ed8aed0bcb6a416a194fce70f0a290309d (patch)
tree5759c263bc626d288cb69434d1f46e20af49f2de /examples/mandelbrot.sloth
parent7c53e65cad365ec112d2ec1bd9c3091dbed05720 (diff)
parent52d6bc8533616dd642c96f8b6e72f459e1b4d465 (diff)
downloadsloth-1219f5ed8aed0bcb6a416a194fce70f0a290309d.tar.gz
Merge branch 'master' of github.com:slothlang/slothlang
Diffstat (limited to 'examples/mandelbrot.sloth')
-rw-r--r--examples/mandelbrot.sloth68
1 files changed, 34 insertions, 34 deletions
diff --git a/examples/mandelbrot.sloth b/examples/mandelbrot.sloth
index c52f5de..525f5eb 100644
--- a/examples/mandelbrot.sloth
+++ b/examples/mandelbrot.sloth
@@ -1,40 +1,40 @@
-fn main() Int {
- # Configuration related variables
- var size: Float = 800.0;
- var maxVal = 4.0;
- var maxIter = 50.0;
- var plane = 4.0;
+fn main() Int{
+ # Configure
+ var size: Float = 1000.0;
+ var maxVal: Float = 4.0;
+ var maxIter: Float = 50.0;
+ var plane: Float = 4.0;
- # Loop over X the configured size
- var x = 0.0;
- while x < size {
- # Loop over Y for the configured size
- var y = 0.0;
- while y < size {
- # 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 coordinates
+ var x: Float = 0.0;
+ while x < size {
+ var y: Float = 0.0;
+ while y < size {
+ # Initialize
+ 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;
- # Loop over and finish mandelbrot calculations
- while (zReal * zReal + zImg * zImg) <= maxVal && count < maxIter {
- var temp = (zReal * zReal) - (zImg * zImg) + cReal;
- zImg = 2.0 * zReal * zImg + cImg;
- zReal = temp;
- count = count + 1.0;
+ # Calculate
+ while (zReal * zReal + zImg * zImg) <= maxVal && count < maxIter {
+ var temp: Float = (zReal * zReal) - (zImg * zImg) + cReal;
+ zImg = 2.0 * zReal * zImg + cImg;
+ zReal = temp;
+ count = count + 1.0;
+ }
- # 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;
- }
- x = x + 1.0;
+ # Check
+ if as_int(count) == as_int(maxIter) {
+ termpos(as_int(x), as_int(y));
+ print("█");
+ }
+
+ y = y + 1.0;
}
- return 0;
+ x = x + 1.0;
+ }
+ return 0;
}