Day 10, A world full of spheres
With the development environment fixed, using the previous progress to render a world with multiple is as simple as creating the camera:
camera = Camera.new(128, 128, '1/4'.to_r) do |camera|
origin = Point[0, 0, -1.7]
look_at = Point[0, 0, 0]
up = Vector[0, 1, 0]
camera.transform = ViewTransform[origin, look_at, up]
end
Populating a world with some objects:
world = World.new do |world|
world.objects << Sphere.new do |sphere|
sphere.material.color = Color[1, 0.3, 0.1]
sphere.transform = identity.translate(-0.5, -0.5, 0)
end
world.objects << Sphere.new do |sphere|
sphere.material.color = Color[1, 1.0, 0.1]
sphere.material.shininess = 20
sphere.transform = identity.translate(1, 1, 1)
end
world.objects << Sphere.new do |sphere|
sphere.material.color = Color[0.2, 0.5, 1.0]
sphere.transform = identity.scale(2, 2, 2).translate(-2, 2, 4)
end
end
And finally rendering the result to an image file.
File.open('spheres.ppm', 'w') do |file|
camera.render(world).to_ppm(file)
end
Next related
Day 11, Into the Shadows
After todays work we can render the shadows cast by objects in our scenes!
Previous related
Day 9, lost to Ruby environment trouble
No progress because it turned out that the Ruby / bundler environment on my laptop was not functional anymore, so the little time I had while away over the weekend got wasted on debugging why nothing worked instead of doing something productive.
Day 8, Making a scene
Further steps toward more pixels, teaching the world to tell what color a ray will see, and creating the necessary transforms for positioning the world in front of the camera. Then have the camera cast a ray, for each pixel in the resulting image, into the world.
Day 7, Casting rays through the whole world
Lots of refactoring today, because old assumptions were smashed, and some cleanup of annoying duplications was needed. No new pixels yet, but maybe tomorrow? These where the previous two days pixel results, with the black background made transparent while converting them from ppm to png.