Аналоговые часы на PascalABC.NET

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Fluttershy :3
program Clock;
uses
GraphABC, Timers, System;
var
Rad : integer := 200;
S : integer;
BigLines : array[0..12, 0..3] of integer;
LittleLines : array[0..60, 0..3] of integer;
COORD : array[0..60, 0..5] of integer;
Date1 : DateTime;
procedure TimerProc;
begin
Date1 := DateTime.Now;
Window.Clear;
for var i := 0 to 12 do
begin
Line(BigLines[i, 0], BigLines[i, 1], BigLines[i, 2], BigLines[i, 3], clBlack);
end;
for var i := 0 to 60 do
begin
Line(LittleLines[i, 0], LittleLines[i, 1], LittleLines[i, 2], LittleLines[i, 3], clBlack);
end;
SetPenColor(clBrown);
Line(0, 0, COORD[Date1.Second, 4], COORD[Date1.Second, 5]);
SetPenColor(clBlack);
SetPenWidth(2);
Line(0, 0, COORD[Date1.Minute, 2], COORD[Date1.Minute, 3]);
case Date1.Minute of
5..15: S:= 1;
16..30: S:= 2;
31..45: S:= 3;
46..59: S:= 4;
end;
Line(0, 0, COORD[Date1.Hour mod 12 *5 + S, 0], COORD[Date1.Hour mod 12 *5 + S, 1]);
SetPenWidth(1);
Redraw;
end;
begin
LockDrawing;
Window.Title := 'Часы v1.0';
SetCoordinateOrigin(Window.Width div 2, Window.Height div 2);
var t := new Timer(1000, TimerProc);
t.Start();
{Process }
// Рисуем наш циферблат // Здоровые по 30
for var i := 0 to 12 do
begin
//
BigLines[i, 0] := Round((Rad - 5) * Cos(((i * 30) - 90) * pi / 180));
BigLines[i, 1] := Round((Rad - 5) * Sin(((i * 30) - 90) * pi / 180));
//
BigLines[i, 2] := Round((Rad + 5) * Cos(((i * 30) - 90) * pi / 180));
BigLines[i, 3] := Round((Rad + 5) * Sin(((i * 30) - 90) * pi / 180));
//
end;
// Рисуем наш циферблат // Маленькие по 6
for var i := 0 to 60 do
begin
//
LittleLines[i, 0] := Round((Rad - 1) * Cos(((i * 6) - 90) * pi / 180));
LittleLines[i, 1] := Round((Rad - 1) * Sin(((i * 6) - 90) * pi / 180));
//
LittleLines[i, 2] := Round((Rad + 1) * Cos(((i * 6) - 90) * pi / 180));
LittleLines[i, 3] := Round((Rad + 1) * Sin(((i * 6) - 90) * pi / 180));
//
// Массивы для координат стрелок // !!! Говнокод
// hours
COORD[i, 0] := Round((Rad - 40) * Cos(((i * 6) - 90) * pi / 180));
COORD[i, 1] := Round((Rad - 40) * Sin(((i * 6) - 90) * pi / 180));
// minutes
COORD[i, 2] := Round((Rad - 15) * Cos(((i * 6) - 90) * pi / 180));
COORD[i, 3] := Round((Rad - 15) * Sin(((i * 6) - 90) * pi / 180));
// seconds
COORD[i, 4] := Round((Rad - 15) * Cos(((i * 6) - 90) * pi / 180));
COORD[i, 5] := Round((Rad - 15) * Sin(((i * 6) - 90) * pi / 180));
end;
end.