8SHADED TRIANGLES

image

In the previous chapter, we developed an algorithm to draw a triangle filled with a solid color. Our goal for this chapter is to draw a shaded triangle—that is, a triangle filled with a color gradient.

Defining Our Problem

We want to fill the triangle with different shades of a single color. It will look like Figure 8-1.

We need a more formal definition of what we’re trying to draw. We have a base color C: for example, 0,255,0, pure green. We’ll assign a real value h to each vertex, denoting the intensity of the color at the vertex. h is in the [0.0,1.0] range, where 0.0 represents the darkest possible shade (that is, black) ...

Get Computer Graphics from Scratch 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.