Advertisement
Vladislav8653

6.1 delphi

May 3rd, 2023
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 5.56 KB | None | 0 0
  1. Unit UnitMain;
  2.  
  3. Interface
  4.  
  5. Uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  7.   System.Classes, Vcl.Graphics,
  8.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Menus, Vcl.StdCtrls,
  9.   MMSystem, Vcl.Mask, DateUtils;
  10.  
  11. Type
  12.   TMainUnit = class(TForm)
  13.     ClockField: TPaintBox;
  14.     Timer: TTimer;
  15.     Menu: TMainMenu;
  16.     InfoAboutDeveloper: TMenuItem;
  17.     N1: TMenuItem;
  18.     Procedure FormCreate(Sender: TObject);
  19.     Procedure ClockFieldPaint(Sender: TObject);
  20.     Procedure DrawArrows(Color: TColor);
  21.     Procedure PrintDigits();
  22.     Procedure TimerTimer(Sender: TObject);
  23.     Procedure FormShow(Sender: TObject);
  24.     procedure InfoAboutDeveloperClick(Sender: TObject);
  25.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  26.     procedure N1Click(Sender: TObject);
  27.   End;
  28.  
  29. Var
  30.     MainUnit: TMainUnit;
  31.     CenterX, CenterY: Integer;
  32.     Radius: Integer;
  33.     HArrow, MArrow, SArrow: Integer;
  34.     HAngle, MAngle, SAngle: Real;
  35.     Hour, Min, Sec, MSec: Word;
  36.  
  37. Implementation
  38.  
  39. {$R *.dfm}
  40.  
  41. Procedure TMainUnit.FormCreate(Sender: TObject);
  42. Begin
  43.     CenterX := MainUnit.ClientWidth div 2;
  44.     CenterY := MainUnit.ClientHeight div 2;
  45.     Radius := CenterX - 30;
  46.     HArrow := Radius - 35;
  47.     MArrow := Radius - 20;
  48.     SArrow := Radius - 10;
  49. End;
  50.  
  51. Procedure TMainUnit.FormShow(Sender: TObject);
  52. Begin
  53.     DecodeTime(Time, Hour, Min, Sec, MSec);
  54.     SAngle := (Sec / 60) * (2 * Pi);
  55.     MAngle := (Min / 60) * (2 * Pi);
  56.     HAngle := (Hour mod 12) / 12 * (2 * Pi);
  57.     Timer.Enabled := True;
  58. End;
  59.  
  60. Procedure TMainUnit.ClockFieldPaint(Sender: TObject);
  61. Var
  62.     I: Integer;
  63. Begin
  64.     With (ClockField.Canvas) do
  65.     Begin
  66.         Brush.Color:= rgb(230, 230, 250);
  67.         FillRect(ClipRect);
  68.         Pen.Color := clBlack;
  69.         Pen.Width := 4;
  70.         Brush.Color := rgb(176, 196, 222);
  71.         Ellipse(20, 30, 40 + 2 * Radius, 47 + 2 * Radius);
  72.         Pen.Width := 5;
  73.         Radius := Radius + 5;
  74.         CenterY := CenterY + 7;
  75.         For I := 0 to 11 do
  76.         Begin
  77.             MoveTo(CenterX + Round((Radius - 25) * Sin(I * Pi / 6)), CenterY - Round((Radius - 25) * Cos(I * Pi / 6)));
  78.             LineTo(CenterX + Round((Radius) * Sin(I * Pi / 6)), CenterY - Round((Radius) * Cos(I * Pi / 6)));
  79.         End;
  80.         Pen.Width := 4;
  81.         For I := 0 to 59 do
  82.         Begin
  83.             MoveTo(CenterX + Round((Radius - 10) * Sin(I * Pi / 30)), CenterY - Round((Radius - 10) * Cos(I * Pi / 30)));
  84.             LineTo(CenterX + Round((Radius) * Sin(I * Pi / 30)), CenterY - Round((Radius) * Cos(I * Pi / 30)));
  85.         End;
  86.         PrintDigits();
  87.         Pen.Color := clBlack;
  88.         HAngle := 0;
  89.         MAngle := 0;
  90.         SAngle := 0;
  91.         MoveTo(CenterX, CenterY);
  92.         Pen.Width := 8;
  93.         LineTo(CenterX + Round(HArrow * Sin(HAngle) * 0.7), CenterY - Round(HArrow * Cos(HAngle) * 0.7));
  94.         MoveTo(CenterX, CenterY);
  95.         Pen.Width := 6;
  96.         LineTo(CenterX + Round(MArrow * Sin(MAngle) * 0.8), CenterY - Round(MArrow * Cos(MAngle) * 0.8));
  97.         MoveTo(CenterX, CenterY);
  98.         Pen.Width := 4;
  99.         LineTo(CenterX + Round(SArrow * Sin(SAngle) * 0.9), CenterY - Round(SArrow * Cos(SAngle) * 0.9));
  100.     End;
  101. End;
  102.  
  103. Procedure TMainUnit.TimerTimer(Sender: TObject);
  104. Begin
  105.     DrawArrows(rgb(176, 196, 222));
  106.     PrintDigits();
  107.     DecodeTime(Time, Hour, Min, Sec, MSec);
  108.     SAngle := (Sec / 60) * (2 * Pi);
  109.     MAngle := (Min / 60 * (2 * Pi)) + SAngle / 60;
  110.     HAngle := ((Hour mod 12) / 12 * (2 * Pi)) + MAngle / 12;
  111.     DrawArrows(clBlack);
  112. End;
  113.  
  114. Procedure TMainUnit.DrawArrows(Color: TColor);
  115. Begin
  116.     With (ClockField.Canvas) do
  117.     Begin
  118.         Pen.Color := Color;
  119.         MoveTo(CenterX, CenterY);
  120.         Pen.Width := 12;
  121.         LineTo(CenterX + Round(HArrow * Sin(HAngle) * 0.7), CenterY - Round(HArrow * Cos(HAngle) * 0.7));
  122.         MoveTo(CenterX, CenterY);
  123.         Pen.Width := 8;
  124.         LineTo(CenterX + Round(MArrow * Sin(MAngle) * 0.8), CenterY - Round(MArrow * Cos(MAngle) * 0.8));
  125.         MoveTo(CenterX, CenterY);
  126.         Pen.Width := 4;
  127.         LineTo(CenterX + Round(SArrow * Sin(SAngle) * 0.9), CenterY - Round(SArrow * Cos(SAngle) * 0.9));
  128.         SndPlaySound('tick.wav', SND_ASYNC);
  129.     End;
  130. End;
  131.  
  132. Procedure TMainUnit.PrintDigits();
  133. Begin
  134.     With (ClockField.Canvas) do
  135.     Begin
  136.         Font.Style := [fsBold];
  137.         Font.Size := 20;
  138.         TextOut(CenterX - TextWidth('XII') div 2, CenterY - Radius + 25, 'XII');
  139.         TextOut(CenterX + Radius - 25 - TextWidth('III'), CenterY - TextHeight('3') div 2, 'III');
  140.         TextOut(CenterX - TextWidth('VI') div 2, CenterY + Radius - 25 - TextHeight('VI'), 'VI');
  141.         TextOut(CenterX - Radius  + TextWidth('IX'), CenterY - TextHeight('IX') div 2, 'IX');
  142.     End;
  143. End;
  144.  
  145. procedure TMainUnit.InfoAboutDeveloperClick(Sender: TObject);
  146. begin
  147.     Application.MessageBox('Арефин Владислав гр.251004', 'Разрабочик', 0);
  148. end;
  149.  
  150. procedure TMainUnit.N1Click(Sender: TObject);
  151. begin
  152.     Application.MessageBox('Часы имеют звуковое сопровождение - иммитацию хода настоящих механических часов. Для получения уникального пользовательского опыта включите звук.', 'Информация', 0);
  153. end;
  154.  
  155. procedure TMainUnit.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  156. begin
  157.     CanClose := Application.MessageBox('Вы действительно хотите выйти?', 'Выход', MB_YESNO + MB_ICONQUESTION) = ID_YES;
  158. end;
  159.  
  160. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement