void loop() { checkSerialAPI(); checkTimeout(); switch(toupper(CMD[0])){ case 'R': runningLights(DEL, BRI); break; case 'F': flashingLights(DEL, BRI); break; case 'P': police(DEL, BRI); break; case 'S': still(BRI); break; case 'D': disco(DEL, BRI); break; case 'G': glow(DEL, BRI); break; case 'O': default: off(); } }
void display(void) { glClear(GL_COLOR_BUFFER_BIT); if(lights) { //3 background colors glBegin(GL_POLYGON); glColor3f(0.42, 1.0, 0.87); //light blue glVertex2f(-1.0, -1.0); glVertex2f(-1.0, 1.0); glColor3f(0.14, 0.62, 0.76); //darker blue glVertex2f((-1.0/3.0), 1.0); glVertex2f((-1.0/3.0), -1.0); glEnd(); glBegin(GL_POLYGON); glColor3f(0.69, 0.29, 0.74); //purple glVertex2f((-1.0/3.0), -1.0); glVertex2f((-1.0/3.0), 1.0); glColor3f(0.92, 0.33, 0.38); //reddish glVertex2f((1.0/3.0), 1.0); glVertex2f((1.0/3.0), -1.0); glEnd(); glBegin(GL_POLYGON); glColor3f(0.99, 0.54, 0.41); //orange glVertex2f((1.0/3.0), -1.0); glVertex2f((1.0/3.0), 1.0); glColor3f(1.0, 0.82, 0.53); //yellow glVertex2f(1.0, 1.0); glVertex2f(1.0, -1.0); glEnd(); //help text glColor3f(0.92/3.0, 0.33/3.0, 0.38/3.0); //reddish bitmapText(-0.45, 0.85, "press <spacebar> to turn out the light!"); //shadows for (int i=0; i<totalNum; i++) { glColor4f(0.0,0.0,0.0,0.5); flatCircle(x[i]+x[i]/15,y[i]+(y[i]-1.0)/20, radius, 30); } //bsll body for (int i=0; i<totalNum; i++) { float gAlph = glowAlph[i]-0.3; circle(x[i], y[i], colorR[i]+gAlph, colorG[i]+gAlph, colorB[i]+gAlph, radius,30); if(glowAlph[i] > 0.0) { glowAlph[i] -= 0.02; glow(x[i], y[i], colorR[i]+glowAlph[i],colorG[i]+glowAlph[i],colorB[i]+glowAlph[i],glowAlph[i], radius+.1,30); } } //desk light. blinks when balls hit top of the screen glow(0, 1.0, 1,1,1, 0.8+lightGlow, 1, 30); if(lightGlow > 0.0) { lightGlow-=0.04; } } //lights out mode else { //corner lights glow(-1.0, 1.0, -0.08,0.5,0.37, 0.3+lightGlow, 0.2, 30); glow( 1.0, 1.0, 0.5, 0.32, 0.03, 0.3+lightGlow, 0.2, 30); glow( 1.0,-1.0, 0.5, 0.32, 0.03, 0.3+lightGlow, 0.2, 30); glow(-1.0,-1.0, -0.08,0.5,0.37, 0.3+lightGlow, 0.2, 30); //help text glColor4f(0.38, 0.92, 0.38, 0.1+lightGlow); bitmapText(-0.45, 0.85, "press <spacebar> to turn on the light!"); if(lightGlow > 0.0) { lightGlow-=0.04; } //circle outlines for (int i=0; i<totalNum; i++) { glow(x[i],y[i], colorR[i],colorG[i],colorB[i], 1.0, radius+.04, 30); glColor3f(0,0,0); flatCircle(x[i],y[i], radius,30); circleOutline(x[i], y[i], colorR[i]+glowAlph[i], colorG[i]+glowAlph[i], colorB[i]+glowAlph[i], radius,30); } //collision glow for (int i=0; i<totalNum; i++) { if(glowAlph[i] > 0.0) { glowAlph[i] -= 0.02; glow(x[i], y[i], colorR[i]+glowAlph[i],colorG[i]+glowAlph[i],colorB[i]+glowAlph[i],glowAlph[i], radius+.1,30); } } } //glColor3f(0.0,0.0,0.0); //bitmapText(-0.98,0.94,debug); glFlush(); //flush image to the screen }