7.3 A rotating polygon in animation 209
//--- Animation loop:backbuffer(); // draw in the back bufferrepeat:color(BLUE);
clear();float dot = omega*Dt;
float cs = cos(dot);
float sn = sin(dot);//--- Rotate the polygon by the angle dot around the rotation center:for (int i=0; i<n; i++)
{
float xtemp = x[i]-xcrot;
float ytemp = y[i]-ycrot;
x[i] = xtemp*cs + ytemp*sn + xcrot;
y[i] = -xtemp*sn + ytemp*cs + ycrot;
points[i][0]=x[i];
points[i][1]=y[i];
}//--- Paint the polygon:color (RED);
poly2 (n,points);//--- Swap the buffers:swapbuffers();//--- check the keyboard:char kbd = char(checkkey()); // any key pressed?//--- If s is pressed, wait for another key:if(kbd == ’s’)
{
char kbd1 = char(getkey());
}//--- If q is pressed, quit:if(kbd == ’q’)