diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/mandelbrot.sloth | 24 | ||||
| -rw-r--r-- | examples/webserver.html | 10 | ||||
| -rw-r--r-- | examples/webserver.sloth | 12 |
3 files changed, 34 insertions, 12 deletions
diff --git a/examples/mandelbrot.sloth b/examples/mandelbrot.sloth index c7c559a..275d32b 100644 --- a/examples/mandelbrot.sloth +++ b/examples/mandelbrot.sloth @@ -1,25 +1,25 @@ fn main() Int { # Configure - var size: Float = 1000.0; - var maxVal: Float = 4.0; - var maxIter: Float = 50.0; - var plane: Float = 4.0; + var size = 1000.0; + var maxVal = 4.0; + var maxIter = 50.0; + var plane = 4.0; # loop over coordinates - var x: Float = 0.0; + var x = 0.0; while x < size { - var y: Float = 0.0; + var y = 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; + 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; # Calculate 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; diff --git a/examples/webserver.html b/examples/webserver.html new file mode 100644 index 0000000..a934b67 --- /dev/null +++ b/examples/webserver.html @@ -0,0 +1,10 @@ +<!DOCTYPE html> +<head> + <title>sloth</title> +</head> +<html> + <body> + <h1>Sloth</h1> + <p>paragraph</p> + </body> +</html> diff --git a/examples/webserver.sloth b/examples/webserver.sloth new file mode 100644 index 0000000..a0c7f17 --- /dev/null +++ b/examples/webserver.sloth @@ -0,0 +1,12 @@ +fn main() Int { + var port: Int = 8080; + var addr: String = "auto"; + while true { + var server: Int = serversock(port, addr, 10, true); + sendsock("HTTP/1.0 200 OK\r\nServer: webserver-c\r\nContent-type: text/html\r\n\r\n<html>hello, world</html>\r\n", server); + wait(0.5); + closesock(server, false); + } + + return 0; +} |
