Putting It Together

Your final task in this chapter is to write a program that casts rays at a sphere and draws the picture to a canvas. Any ray that hits the sphere should result in a colored pixel (red, for example), and any miss should be drawn in black. The result will be a silhouette of the sphere—not three-dimensional, but definitely round!

Here are a few hints to help you along. Stop reading at any time if you feel like you’ve got a handle on the solution!

Hint #1

Think as if you’re trying to cast the shadow of your object onto some wall behind it, as in the following figure.

images/rays/silhouette.png

You cast each ray from some starting point toward some point on ...

Get The Ray Tracer Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.