214 Introduction to C++ Programming and Graphics
void drawshape(int fill)
{
polyfill(fill);
if (!fill)
for (int i=0; i<20; i++)
{
if (fill)
{
color(i+1);
}
makepoly();
move(xyz[ncon[i][0]-1][0], xyz[ncon[i][0]-1][1], xyz[ncon[i][0]-1][2]);
draw(xyz[ncon[i][1]-1][0], xyz[ncon[i][1]-1][1], xyz[ncon[i][1]-1][2]);
draw(xyz[ncon[i][2]-1][0], xyz[ncon[i][2]-1][1], xyz[ncon[i][2]-1][2]);
closepoly();
}
}
Figure 7.3.1(b) shows a snapshot of the animation. The code features the fol-
lowing implementations:
- A function is used to draw the icosahedron based on hard-coded data for
the vertex coordinates and a connectivity table relating faces to vertices. - When the “p” key is pressed, a postscript file of the current shape is
produced. - When the “x”, “y”, or “z” key is pressed, the icosahedron translates by a
specified shift in the respective directions. When the “-” key is pressed,
the direction of translation is reversed, and when the “+” key is pressed,
the direction of translation is reinstated. - When either the Escape or the “q” key is pressed, the execution termi-
nates.
Problems
7.3.1. Modify the polygon animation code to implement a rotating regular
hexagon.
7.3.2. Modify the polygon animation code to insert a second rotating polygon.
7.3.3. Translate into C++ aVogledistribution animation code of your choice.