diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/cgol.sloth | 42 | ||||
| -rw-r--r-- | examples/mandelbrot.sloth | 48 |
2 files changed, 52 insertions, 38 deletions
diff --git a/examples/cgol.sloth b/examples/cgol.sloth index 6cfe72d..4021e58 100644 --- a/examples/cgol.sloth +++ b/examples/cgol.sloth @@ -5,7 +5,7 @@ fn populate() [Int] { # Fill the vector with random values var i: Int = 0; - while i < 2500 { + while i < 57600 { var n: Int = randGen(0,1); vpushi(life, n); i = i+1; @@ -18,7 +18,7 @@ fn coord(x: Int, y: Int) Int { var res: Int = -1; # Calculate index based on coordinates if x >= 0 && y >= 0 { - res = y*50 + x; + res = y*240+ x; } # if coordinate is invalid, return -1 return res; @@ -37,9 +37,9 @@ fn cval(x: Int, y: Int, life: [Int]) Int { fn update(life: [Int], new: [Int]) { # Iterate through life var x: Int = 0; - while x < 50 { + while x < 64 { var y: Int = 0; - while y < 50 { + while y < 240 { # Calculate total score around selected cell var total: Int = cval(x-1, y-1, life) + # Top Left @@ -77,20 +77,30 @@ fn update(life: [Int], new: [Int]) { fn display(life: [Int]) { # Iterate through life #termclear(); - var x: Int = 0; - while x < 50 { - var y: Int = 0; - while y < 50 { - # if the cell is alive, print - termpos(x, y); - if cval(x, y, life) == 1{ - print("#"); + #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); + if cval(x-3, y, life) == 1 { + print("█"); } else { - print(" "); - } - y = y+1; + print(" "); + } } - x = x+1; } } 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; } + |
