#include #include #include #include #include "canvas.h" const int screenWidth = 640; const int screenHeight = 480; const int maxVertices = 1000; Canvas cvs(screenWidth, screenHeight, "Tweening two polygons"); void drawPolygon(int numVertices, Point2 vertices[]) { glBegin(GL_LINE_STRIP); for(int i = 0; i <= numVertices; i++) glVertex2f(vertices[i].getX(), vertices[i].getY() ); glEnd(); glFlush(); } void display(void) { cvs.clearScreen(); cvs.setWindow(-5.0, 5.0, -5.0, 5.0); cvs.setViewport(10, 460, 10, 460); Point2 polyA[maxVertices]; Point2 polyB[maxVertices]; polyA[0].set (0,0); polyA[1].set (1,0); polyA[2].set (1,1); polyA[3].set (2,1); polyA[4].set (2,-1); polyA[5].set (0,-1); polyA[6].set (0,0); polyB[0].set (0,0); polyB[1].set (1,0); polyB[2].set (2,0); polyB[3].set (2,1); polyB[4].set (2,2); polyB[5].set (0,2); polyB[6].set (0,0); for (float j=0; j<= 1.0; j += 0.1) { cvs.setColor(0.0, 0.0, 1.0); drawPolygon(6, polyA); cvs.setColor(1.0, 0.0, 0.0); drawPolygon(6, polyB); cvs.setColor(j, 0.0, 1-j); cvs.drawTween(polyA, polyB, 6, j); } } int main(void) { cvs.setBackgroundColor(1.0, 1.0, 1.0); cvs.setColor(0.0, 0.0, 1.0); glutDisplayFunc(display); glutMainLoop(); }