#include #include #include using namespace std; typedef unsigned char uchar; // number of line segments static int num_lines = 35; static int num_circ = 20; static GLdouble rot_angle = 0; // callback prototypes void disp(void); void keyb(uchar k, int x, int y); void reshape(int x, int y); void idle(void); //////////////////////////////// // main int main(int argc, char **argv){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutInitWindowSize(400,400); glutInitWindowPosition(100,100); glutCreateWindow("spiral.cpp"); glClearColor(0.0,0.0,0.0,0.0); glutDisplayFunc(disp); glutKeyboardFunc(keyb); glutReshapeFunc(reshape); glutIdleFunc(idle); glutMainLoop(); return 0; } //////////////// // disp void disp(void){ double angle, length; glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glRotated(rot_angle, 0.0,0.0,1.0); // no GL_LINE_LOOP since it isn't a closed loop glBegin(GL_LINE_STRIP); for(int i =0;i 360) rot_angle -= 360; // redisplay glutPostRedisplay(); } /////////////////////////////////// // keyb void keyb(uchar k, int x, int y){ /* Commands: -> q: quit -> s: start rotate -> S: stop rotate -> c: more circles -> C: less circles -> l: more lines -> L: less lines */ switch (k){ case 'q': exit(0); break; case 'c': if(num_lines < 99){ num_circ++; cout << "Spiral consists of " << num_circ << " circles " << endl; glutPostRedisplay(); } break; case 'C': if(num_circ >3){ num_circ--; cout << "Spiral consists of " << num_circ << " circles " << endl; glutPostRedisplay(); } break; case 'l': if(num_lines < 99){ num_lines++; cout << "Circle consists of " << num_lines << " lines " << endl; glutPostRedisplay(); } break; case 'L': if(num_lines >3){ num_lines--; cout << "Circle consists of " << num_lines << " lines " << endl; glutPostRedisplay(); } break; case 's': glutIdleFunc(idle); cout << "Rotating " << endl; break; case 'S': glutIdleFunc(NULL); cout << "Not rotating" << endl; break; } } ////////////////////////// // reshape void reshape(int x,int y){ if(x