Codice:
#include <stdlib.h>
#include <string>
#include "Video.h"
Video *vd = new Video(800,600,32);
struct tm *m_tmCurrent;
time_t m_tNow;
char m_cTime[50];
double sec_angle = -64; //64=90° - 128=180° - 192=270° - 256=360°
double min_angle = -50;
double hour_angle = -30;
float x = 400;
float y = 300;
int sec_lenght = 100; //Lunghezza della lancetta dei secondi
int min_lenght = 90;
int hour_lenght = 70;
int main(){
vd->Init();
while(!key[KEY_ESC]){
// Disegna la lancetta dei secondi
line(vd->GetBuffer(),x,y,x+sec_lenght*cos(fix(sec_angle)),y+sec_lenght*sin(fix(sec_angle)),makecol(255,255,255));
// Disegna la lancetta dei minuti
//line(vd->GetBuffer(),x,y,x+min_lenght*cos(fix(min_angle)),y+min_lenght*sin(fix(min_angle)),makecol(255,255,255));
// Disegna la lancetta delle ore
//line(vd->GetBuffer(),x,y,x+hour_lenght*cos(fix(hour_angle)),y+hour_lenght*sin(fix(hour_angle)),makecol(255,255,255));
// Disegna il quadrante
circle(vd->GetBuffer(),x,y,sec_lenght,makecol(255,0,0));
line(vd->GetBuffer(),x,y-110,x,y-90,makecol(0,0,255));
line(vd->GetBuffer(),x,y+90,x,y+110,makecol(0,0,255));
line(vd->GetBuffer(),x-110,y,x-90,y,makecol(0,0,255));
line(vd->GetBuffer(),x+90,y,x+110,y,makecol(0,0,255));
//Stampa l'ora corrente
time(&m_tNow);
m_tmCurrent = localtime(&m_tNow);
sprintf(m_cTime,"%i:%i:%i",m_tmCurrent->tm_hour,m_tmCurrent->tm_min,m_tmCurrent->tm_sec);
textout(vd->GetBuffer(),font,m_cTime,380,100,makecol(255,255,255));
//Calcolo l'angolo della lancetta dei secondi in base ai secondi dell'ora corrente
sec_angle = m_tmCurrent->tm_sec;
sec_angle *= 256/60;
sec_angle -= 64;
vd->Draw();
}
return 0;
}END_OF_MAIN();