diff --git a/.gitignore b/.gitignore index 9cbb8dc..3c1c33f 100644 --- a/.gitignore +++ b/.gitignore @@ -57,3 +57,6 @@ $RECYCLE.BIN/ *.lnk # End of https://www.toptal.com/developers/gitignore/api/code,nim,linux,windows + +raytracer_nim +output.ppm \ No newline at end of file diff --git a/src/raytracer_nim.nim b/src/raytracer_nim.nim index 862d40c..73b3d6f 100644 --- a/src/raytracer_nim.nim +++ b/src/raytracer_nim.nim @@ -1,5 +1,25 @@ -# This is just an example to get you started. A typical binary package -# uses this file as the main entry point of the application. +import "./tuple", "./canvas" + +type + Projectile = object + position: Tuple4 + velocity: Tuple4 + Environment = object + gravity: Tuple4 + wind: Tuple4 + +proc tick(proj: Projectile, env: Environment): Projectile = Projectile(position: proj.position + proj.velocity, velocity: proj.velocity + env.gravity + env.wind) when isMainModule: - echo("Hello, World!") + var world = canvas(800, 600) + let start = point(0, 1, 0) + let velocity = normalize(vector(0.5, 1.2, 0)) * 11.25 + var projectile = Projectile(position: start, velocity: velocity) + let environment = Environment(gravity: vector(0, -0.1, 0), wind: vector(-0.01, 0, 0)) + let colour = colour(1, 0, 0) + while projectile.position.x >= 0 and projectile.position.x < 800 and projectile.position.y >= 0 and projectile.position.y < 600: + world.writePixel(projectile.position.x, 600 - projectile.position.y, colour) + projectile = projectile.tick(environment) + writeFile("output.ppm", world.toPPM()) + +