diff options
| author | Cody <cody@codyq.dev> | 2023-07-20 18:13:34 -0500 |
|---|---|---|
| committer | Cody <cody@codyq.dev> | 2023-07-20 18:13:34 -0500 |
| commit | 1219f5ed8aed0bcb6a416a194fce70f0a290309d (patch) | |
| tree | 5759c263bc626d288cb69434d1f46e20af49f2de /examples | |
| parent | 7c53e65cad365ec112d2ec1bd9c3091dbed05720 (diff) | |
| parent | 52d6bc8533616dd642c96f8b6e72f459e1b4d465 (diff) | |
| download | sloth-1219f5ed8aed0bcb6a416a194fce70f0a290309d.tar.gz | |
Merge branch 'master' of github.com:slothlang/slothlang
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/arguments.sloth | 2 | ||||
| -rw-r--r-- | examples/cgol.sloth | 16 | ||||
| -rw-r--r-- | examples/mandelbrot.sloth | 68 | ||||
| -rw-r--r-- | examples/read.sloth | 2 |
4 files changed, 36 insertions, 52 deletions
diff --git a/examples/arguments.sloth b/examples/arguments.sloth index 3e44dcc..9daaec7 100644 --- a/examples/arguments.sloth +++ b/examples/arguments.sloth @@ -1,7 +1,7 @@ fn main(argc: Int, argv: [String]) Int { if argc == 2 { print("The argument supplied is "); - println(argv); + println(vgets(argv, 1)); } else { println("Wrong # of args"); } diff --git a/examples/cgol.sloth b/examples/cgol.sloth index 4021e58..17ef31e 100644 --- a/examples/cgol.sloth +++ b/examples/cgol.sloth @@ -76,22 +76,6 @@ fn update(life: [Int], new: [Int]) { fn display(life: [Int]) { # Iterate through life - #termclear(); - #var x: Int = 0; - #while x < 59 { - # var y: Int = 0; - # while y < 240 { - # # if the cell is alive, print - # termpos(x, y); - # if cval(x, y, life) == 1{ - # print("█"); - # } else { - # print(" "); - # } - # y = y+1; - # } - # x = x+1; - #} for x in 3..62 { for y in 0..240 { termpos(x-3, y); 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; } diff --git a/examples/read.sloth b/examples/read.sloth index cf947f8..df398bb 100644 --- a/examples/read.sloth +++ b/examples/read.sloth @@ -1,4 +1,4 @@ fn main() Int { - print(filer("examples/read.txt")); + print(filer("examples/server.sloth")); return 0; } |
