Simple Analog Clock
Ever wanted the most simple but elegant analog clock:
To get various effects or efficiency, you can do the following:
-
To efficiently update:
void update_clock() { set_color(background_color); render_arms(clock_x,clock_y,100,hour,minute,second,millisecond); get_time(&hour,&minute,&second,&millisecond); set_color(clock_color); render_arms(clock_x,clock_y,100,hour,minute,second,millisecond); }
You should declare the
hour
,minute
,second
andmillisecond
somewhere outside the render function where it can store the time of the previous render: - Shadow effect:
set_color(shadow_color); render_arms(clock_x,clock_y,100,hour,minute,second,millisecond); set_color(clock_color); render_arms(clock_x-2,clock_y-2,100,hour,minute,second,millisecond);
-
Using OpenGL1:
void line(x1,y1,x2,y2,width) { glLineWidth(width); glBegin(LINES); glVertex2f(x1,y1); glVertex2f(x2,y2); glEnd(); }
- Make the second arm red
- Make the clock transparent
-
This code uses the deprecated glBegin/glVertex functions. They should be changed to vertex buffers ↩