/* binary_clock.c show date and time */ #include #include #include #include #include static int points[6][4]; static int width=200; static int height=75; static char date[] = "month day year"; static int oldsec = 0; static int tohex[10][4] = {{0, 0, 0, 0}, {1, 0, 0, 0}, {0, 1, 0, 0}, {1, 1, 0, 0}, {0, 0, 1, 0}, {1, 0, 1, 0}, {0, 1, 1, 0}, {1, 1, 1, 0}, {0, 0, 0, 1}, {1, 0, 0, 1}}; static void display(void) { char *p; int i, j, nj; /* clear window */ glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity (); glColor3f(0.0, 0.0, 0.0); /* draw text, in its own context */ glPushMatrix(); glLoadIdentity (); glColor3f(0.0, 0.0, 0.0); glTranslatef(0.05, 0.8, 0.0); glScalef(0.00075, 0.0015, 0.0); for(p=date; *p; p++) glutStrokeCharacter(GLUT_STROKE_ROMAN, *p); glPopMatrix(); /* Draw the binary time */ glColor3f(0.0, 1.0, 0.0); glPointSize(8.0); for(i=0; i<6; i++) { nj = 4; if(i==0) nj=2; if(i==2 || i==4) nj=3; for(j=0; jtm_sec; while(nowsec==oldsec) { mytime = time(&mytime); today = localtime(&mytime); nowsec = today->tm_sec; } oldsec = nowsec; hour = today->tm_hour; if(hour>12) hour = hour-12; d[0] = hour/10; d[1] = hour%10; d[2] = today->tm_min/10; d[3] = today->tm_min%10; d[4] = today->tm_sec/10; d[5] = today->tm_sec%10; for(i=0; i<6; i++) { for(j=0; j<4; j++) { points[i][j]=tohex[d[i]][j]; } } sprintf(date,"%d / %d / %d \n", today->tm_mon+1, today->tm_mday, today->tm_year+1900); glutPostRedisplay(); } /* end tick */ int main(int argc, char* argv[]) { glutInit(&argc,argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(width, height); glutInitWindowPosition(600,40); glutCreateWindow(argv[0]); glutDisplayFunc(display); glutReshapeFunc(reshape); glutIdleFunc(tick); init(); glutMainLoop(); return 0; } /* end main of binary_clock.c */