#include #include #include #include using namespace std; int points = 3, noShapes = 2, noPoints; double * red, * green, * blue; int * x, * y, * state; string shape; double WIDTH = 400, HEIGHT = 400; double HMIN = -WIDTH/2, HMAX = WIDTH/2, KMIN = -HEIGHT/2, KMAX = HEIGHT/2; double startTime = 0; void drawString (GLfloat x, GLfloat y, void *font, string s) { glRasterPos3f (x, y, 0); for (int i = 0; i < (signed int)s.length(); i++) { glutBitmapCharacter (font, s[i]); } } void display () { glClear(GL_COLOR_BUFFER_BIT); int n = noShapes; for (int i = 0; i < n * points; i = i + points) { glPushMatrix(); glTranslatef(HMIN + i * (HMAX - HMIN) / n, KMAX - i * (KMAX - KMIN) / n, 0); glRotatef (i * 360.0 / n, 0, 0, 1); if(points == 3) { glBegin (GL_TRIANGLES); glColor3f (red[0], green[0], blue[0]); glVertex3f (x[0], y[0], 0); glColor3f (red[1], green[1], blue[1]); glVertex3f (x[1], y[1], 0); glColor3f (red[2], green[2], blue[2]); glVertex3f (x[2], y[2], 0); glEnd (); glPopMatrix (); } else { glBegin (GL_QUADS); glColor3f (red[0], green[0], blue[0]); glVertex3f (x[0], y[0], 0); glColor3f (red[1], green[1], blue[1]); glVertex3f (x[1], y[1], 0); glColor3f (red[2], green[2], blue[2]); glVertex3f (x[2], y[2], 0); glColor3f (red[3], green[3], blue[3]); glVertex3f (x[3], y[3], 0); glEnd (); glPopMatrix (); } } glColor3f(red[0], green[1], blue[2]); string s = "wow, the colors!"; drawString(0, 60, GLUT_BITMAP_HELVETICA_18, s); glutSwapBuffers (); glutPostRedisplay (); } //void motion(int x, int y) //{ //} void idle() { if (clock () - startTime >= 10) { startTime = clock(); for(int i = 0; i < points; i++) { switch(state[i]) { case 0: y[i]++; if(y[i] == 50) { state[i] = 1; } cout<<"point "<>shape; if(shape == "triangles") { points = 3; x = new int[3]; y = new int[3]; x[0] = 0; y[0] = 0; x[1] = 0; y[1] = 50; x[2] = 50; y[2] = 0; state = new int [3]; state[0] = 0; state[1] = 1; state[2] = 3; } else if(shape == "squares") { points = 4; x = new int[4]; y = new int[4]; x[0] = 0; x[1] = 50; x[2] = 50; x[3] = 0; y[0] = 0; y[1] = 0; y[2] = 50; y[3] = 50; /*state = new int [4]; for (int i = 0; i < 4; i++) { state[i] = i; }*/ } else { cout<<"invalid. Please re-enter\n"; } }while(shape != "triangles" && shape != "squares"); cout<<"how many shapes will you draw?\n"; cin>>noShapes; noPoints = noShapes * points; red = new double [points]; green = new double [points]; blue = new double [points]; for (int i = 0; i < points; i++) { } for (int i = 0; i < points; i++) { cout<<"enter the red value for point "<>red[i]; cout<<"enter the green value for point "<>green[i]; cout<<"enter the blue value for point "<>blue[i]; } glutInit (&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize (WIDTH, HEIGHT); glutInitWindowPosition (100, 100); glutCreateWindow ("Chris's Final Project"); glClearColor (0, 0, 0, 0); glMatrixMode (GL_MODELVIEW); glOrtho(HMIN, HMAX, KMIN, KMAX, -1, 1); glClear (GL_COLOR_BUFFER_BIT); glutKeyboardFunc (keyboard); glutMouseFunc(mouse); glutDisplayFunc (display); glutSpecialFunc(special); glutIdleFunc(idle); //glutMotionFunc(motion); //glutPassiveMotionFunc(); glutMainLoop (); return; }