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 QuickPascal:
- Program Horloge;
-
- Uses Crt,DOS,MSGraph;
-
- 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
- Err,Hour,Min,Sec,Hund:Integer;
- 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;
- _SetColor(WHITE);
- _Rectangle(_GFillInterior,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;
- _SetColor(WHITE);
- _Rectangle(_GFillInterior,Tx,Ty,Tx+8,Ty+8);
- _SetTextPosition((Trunc(sin(R)*(Ry-15))+Cy+3+16)shr 4,(Trunc(cos(R)*(Rx-15))+Cx+3)shr 3);
- _SetColor(WHITE);
- Str(((I+2) mod 12 + 1),StrTime);
- _OutText(StrTime);
- End;
- End;
-
- BEGIN
- Err:=_SetVideoMode(_VRes16Color);
- 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(50);
- Until KeyPressed;
- END.
Voici en terminant un exemple du résultat de se petit programme :
Dernière mise à jour : Dimanche, le 4 mai 2014