Rien de tel que pour rendre intéressant l'affichage de l'heure, que d'effectuer l'affichage d'une horloge à aiguille! Voici le code source Free Pascal :
- Program Horloge;
-
- Uses Crt,DOS,Graph;
-
- Const
- Cx:Integer=320;
- Cy:Integer=240;
- Rx:Integer=200;
- Ry:Integer=200;
- XH:Integer=0;
- YH:Integer=0;
- XM:Integer=0;
- YM:Integer=0;
- XS:Integer=0;
- YS:Integer=0;
-
- Var
- Hour,_Min,Sec,Hund:Word;
- R:Real;
-
- Procedure drawClock;
- Var
- I,Tx,Ty:Integer;
- R:Real;
- StrTime:String;
- Begin
- For I := 0 To 59 do Begin
- R := I * Pi / 30;
- Tx := Trunc(cos(R) * Rx) + Cx;
- Ty := Trunc(sin(R) * Ry) + Cy;
- SetFillStyle(SolidFill,WHITE);
- Bar(Tx,Ty,Tx+5,Ty+5);
- End;
- For I := 0 to 11 do Begin
- R := I * Pi / 6;
- Tx := Trunc(cos(R) * Rx) + Cx;
- Ty := Trunc(sin(R) * Ry) + Cy;
- SetFillStyle(SolidFill,WHITE);
- Bar(Tx,Ty,Tx+8,Ty+8);
- SetColor(WHITE);
- Str(((I+2) mod 12 + 1),StrTime);
- OutTextXY((Trunc(cos(R)*(Rx-15))+Cx+3),(Trunc(sin(R)*(Ry-15))+Cy+3),StrTime);
- End;
- End;
-
- Var
- PiloteGraph:Integer;
- ModeGraph:Integer;
-
- BEGIN
- PiloteGraph:=Detect;
- ModeGraph:=Detect;
- InitGraph(PiloteGraph,ModeGraph,'');
- drawClock;
- Repeat
- GetTime(Hour,_Min,Sec,Hund);
- SetColor(BLACK);
- MoveTo(Cx, Cy);
- LineTo(XH, YH);
- MoveTo(Cx, Cy);
- LineTo(XM, YM);
- MoveTo(Cx, Cy);
- LineTo(XS, YS);
- R := Pi * ((30 * Hour + (_Min shr 1))/180 + 1.5);
- XH := Cx + Trunc(cos(R)*(Rx-35)) + 1;
- YH := Cy + Trunc(sin(R)*(Ry-35)) + 1;
- SetColor(LIGHTRED);
- MoveTo(Cx, Cy);
- LineTo(XH, YH);
- R := Pi * (_Min / 30 + 1.5);
- XM := Cx + Trunc(cos(R)*(Rx-20)) + 1;
- YM := Cy + Trunc(sin(R)*(Ry-20)) + 1;
- SetColor(YELLOW);
- MoveTo(Cx, Cy);
- LineTo(XM, YM);
- R := Pi * (Sec / 30 + 1.5);
- XS := Cx + Trunc(cos(R)*(Rx-25)) + 1;
- YS := Cy + Trunc(sin(R)*(Ry-25)) + 1;
- SetColor(LIGHTGREEN);
- MoveTo(Cx, Cy);
- LineTo(XS, YS);
- Delay(500);
- Until KeyPressed;
- END.
Voici en terminant un exemple du résultat de se petit programme :
Dernière mise à jour : Jeudi, le 29 décembre 2011