#include using namespace std; #include #include #include #include #include #include void display(void); void animate(void); void mouse(int button, int state, int x, int y); struct square { float c1[2]; float c2[2]; float velocity[2]; float rgb[3]; } sq[500]; struct colormaster { bool rgb[3]; } colors; int main(int argc,char *argv[]) { glutInit(&argc, argv); // initializes GLUT and processes any command line arguments // Note: glutInit() should be called before any other GLUT routine for (int i=0;i<3;i++) if (rand() % 2) colors.rgb[i] = true; else colors.rgb[i] = false; glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); //chooses double buffered and RGBA mode glutInitWindowPosition(10, 10); //specifies the upper-left corner of window (with respect to screen) glutInitWindowSize(700, 700); //specifies the size, in pixels, of window glutCreateWindow("Screensaver!"); //creates a window of name given by input string glClearColor (0, 0, 0, 0); //set clear window color black glShadeModel (GL_FLAT); glutDisplayFunc(display); //registers display callback function, which is display() glutIdleFunc(animate); glutMouseFunc(mouse); glutMainLoop(); return 0; } void display(void) { int num = 500; glClear(GL_COLOR_BUFFER_BIT); // clear the buffer background color for (int k=0;k= 1) { sq[k].velocity[0] *= -1; swap = true; } if (sq[k].c1[1] <= -1 || sq[k].c2[1] >= 1) { sq[k].velocity[1] *= -1; swap = true; } if (swap) { for (int i=0;i<3;i++) if (colors.rgb[i]) sq[k].rgb[i] = (float)((rand())/(RAND_MAX+1.0)); else sq[k].rgb[i] = 0; } */ // this code creates perpetual square fountain if (sq[k].c2[0] <= -1 || sq[k].c1[0] >= 1 || sq[k].c2[1] <= -1 || sq[k].c1[1] >= 1) { sq[k].c1[0] = sq[k].c1[1] = -.1; sq[k].c2[0] = sq[k].c2[1] = .1; for (int i=0;i<3;i++) if (colors.rgb[i]) sq[k].rgb[i] = (float)((rand())/(RAND_MAX+1.0)); else sq[k].rgb[i] = 0; } sq[k].c1[0] += sq[k].velocity[0]; sq[k].c1[1] += sq[k].velocity[1]; sq[k].c2[0] += sq[k].velocity[0]; sq[k].c2[1] += sq[k].velocity[1]; } glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); for (int k=0;k