///|
let canvas = @lib.canvas
///|
let color = @lib.color
///|
let point = @lib.point
///|
let point_light = @lib.point_light
///|
let ray = @lib.ray
///|
let sphere = @lib.sphere
///|
async fn main {
let width = 300
let height = 300
let c = canvas(width, height)
// start the ray at z = -5
let ray_origin = point(0, 0, -5)
// put the wall at z = 10
let wall_z = 10.0
let wall_size = 7.0
let pixel_size = wall_size / width.to_double()
let half = wall_size / 2
let shape = sphere()
shape.material.color = color(1, 0.2, 1)
// shape.set_transform(mat4ident().scale(1, 0.5, 1))
// shape.set_transform(mat4ident().scale(0.5, 1, 1))
// shape.set_transform(mat4ident().scale(0.5, 1, 1).rotate_z(@math.PI / 4))
// shape.set_transform(mat4ident().scale(0.5, 1, 1).shear(1, 0, 0, 0, 0, 0))
let light = point_light(point(-10, 10, -10), color(1, 1, 1))
// for each row of pixels in the canvas
for y in 0.. {
let point = r.position(hit.t)
let normal = hit.shape.normal_at(point)
let eye = r.direction
let clr = hit.shape.material.lighting(light, point, eye, normal)
c.write_pixel(x, y, clr)
}
_ => ()
}
}
}
//
try {
@fs.write_file("ch6.ppm", c.to_ppm(), permission=0o644)
@fs.write_file("ch6.png", c.to_png(), permission=0o644)
} catch {
_ => println("error writing ch6.png")
}
}