Added sample image output for transformations
This commit is contained in:
parent
a076b82bfc
commit
f2729c59c3
2
.gitignore
vendored
2
.gitignore
vendored
@ -154,4 +154,4 @@ modules.xml
|
|||||||
# End of https://www.toptal.com/developers/gitignore/api/intellij+all
|
# End of https://www.toptal.com/developers/gitignore/api/intellij+all
|
||||||
|
|
||||||
raytracer_nim
|
raytracer_nim
|
||||||
output.ppm
|
*.ppm
|
@ -1,4 +1,4 @@
|
|||||||
import "./tuple", "./canvas"
|
import "./tuple", "./canvas", "./matrix", "./transformations", math
|
||||||
|
|
||||||
type
|
type
|
||||||
Projectile = object
|
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)
|
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)
|
var world = canvas(800, 600)
|
||||||
let start = point(0, 1, 0)
|
let start = point(0, 1, 0)
|
||||||
let velocity = normalize(vector(0.5, 1.2, 0)) * 11.25
|
let velocity = normalize(vector(0.5, 1.2, 0)) * 11.25
|
||||||
@ -28,6 +28,21 @@ when isMainModule:
|
|||||||
if(600 - projectile.position.y + 1 < 600):
|
if(600 - projectile.position.y + 1 < 600):
|
||||||
world.writePixel(projectile.position.x, 600 - projectile.position.y + 1, colour)
|
world.writePixel(projectile.position.x, 600 - projectile.position.y + 1, colour)
|
||||||
projectile = projectile.tick(environment)
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user