From f2729c59c3a26aa8f6807e6fbc49e9846b2656e8 Mon Sep 17 00:00:00 2001 From: neviyn Date: Sun, 8 Nov 2020 22:08:38 +0000 Subject: [PATCH] Added sample image output for transformations --- .gitignore | 2 +- src/raytracer_nim.nim | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index c7eaa46..5172e96 100644 --- a/.gitignore +++ b/.gitignore @@ -154,4 +154,4 @@ modules.xml # End of https://www.toptal.com/developers/gitignore/api/intellij+all raytracer_nim -output.ppm \ No newline at end of file +*.ppm \ No newline at end of file diff --git a/src/raytracer_nim.nim b/src/raytracer_nim.nim index c4a7d86..f7e5d9c 100644 --- a/src/raytracer_nim.nim +++ b/src/raytracer_nim.nim @@ -1,4 +1,4 @@ -import "./tuple", "./canvas" +import "./tuple", "./canvas", "./matrix", "./transformations", math type Projectile = object @@ -10,7 +10,7 @@ type proc tick(proj: Projectile, env: Environment): Projectile = Projectile(position: proj.position + proj.velocity, velocity: proj.velocity + env.gravity + env.wind) -when isMainModule: +proc arc() = var world = canvas(800, 600) let start = point(0, 1, 0) let velocity = normalize(vector(0.5, 1.2, 0)) * 11.25 @@ -28,6 +28,21 @@ when isMainModule: if(600 - projectile.position.y + 1 < 600): world.writePixel(projectile.position.x, 600 - projectile.position.y + 1, colour) projectile = projectile.tick(environment) - writeFile("output.ppm", world.toPPM()) + writeFile("arc.ppm", world.toPPM()) + +proc clock() = + var world = canvas(200, 200) + var p = point(0.0, 0.0, 1.0) + let colour = colour(1, 1, 1) + let oneHourRotation = rotationY(PI / 6) + for i in 0..11: + let target = p.scale(60.0, 0.0, 60.0).translate(100.0, 0.0, 100.0) + world.writePixel(target.x, target.z, colour) + p = oneHourRotation * p + writeFile("clock.ppm", world.toPPM()) + +when isMainModule: + arc() + clock()