7FILLED TRIANGLES

image

In the previous chapter, we took our first steps toward drawing simple shapes—namely, straight line segments—using only PutPixel and an algorithm based on simple math. In this chapter, we’ll reuse some of the math to draw something more interesting: a filled triangle.

Drawing Wireframe Triangles

We can use the DrawLine method to draw the outline of a triangle:

DrawWireframeTriangle (P0, P1, P2, color) {     DrawLine(P0, P1, color);     DrawLine(P1, P2, color);     DrawLine(P2, P0, color); }

This kind of outline is called a wireframe, because it looks like a triangle made of wires, as you can see in Figure 7-1.

Figure 7-1: A ...

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.