Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Unit UnitMain;
- Interface
- Uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
- System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls, Vcl.Menus, Vcl.StdCtrls,
- MMSystem, Vcl.Mask, DateUtils;
- Type
- TMainUnit = class(TForm)
- ClockField: TPaintBox;
- Timer: TTimer;
- Menu: TMainMenu;
- InfoAboutDeveloper: TMenuItem;
- N1: TMenuItem;
- Procedure FormCreate(Sender: TObject);
- Procedure ClockFieldPaint(Sender: TObject);
- Procedure DrawArrows(Color: TColor);
- Procedure PrintDigits();
- Procedure TimerTimer(Sender: TObject);
- Procedure FormShow(Sender: TObject);
- procedure InfoAboutDeveloperClick(Sender: TObject);
- procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- procedure N1Click(Sender: TObject);
- End;
- Var
- MainUnit: TMainUnit;
- CenterX, CenterY: Integer;
- Radius: Integer;
- HArrow, MArrow, SArrow: Integer;
- HAngle, MAngle, SAngle: Real;
- Hour, Min, Sec, MSec: Word;
- Implementation
- {$R *.dfm}
- Procedure TMainUnit.FormCreate(Sender: TObject);
- Begin
- CenterX := MainUnit.ClientWidth div 2;
- CenterY := MainUnit.ClientHeight div 2;
- Radius := CenterX - 30;
- HArrow := Radius - 35;
- MArrow := Radius - 20;
- SArrow := Radius - 10;
- End;
- Procedure TMainUnit.FormShow(Sender: TObject);
- Begin
- DecodeTime(Time, Hour, Min, Sec, MSec);
- SAngle := (Sec / 60) * (2 * Pi);
- MAngle := (Min / 60) * (2 * Pi);
- HAngle := (Hour mod 12) / 12 * (2 * Pi);
- Timer.Enabled := True;
- End;
- Procedure TMainUnit.ClockFieldPaint(Sender: TObject);
- Var
- I: Integer;
- Begin
- With (ClockField.Canvas) do
- Begin
- Brush.Color:= rgb(230, 230, 250);
- FillRect(ClipRect);
- Pen.Color := clBlack;
- Pen.Width := 4;
- Brush.Color := rgb(176, 196, 222);
- Ellipse(20, 30, 40 + 2 * Radius, 47 + 2 * Radius);
- Pen.Width := 5;
- Radius := Radius + 5;
- CenterY := CenterY + 7;
- For I := 0 to 11 do
- Begin
- MoveTo(CenterX + Round((Radius - 25) * Sin(I * Pi / 6)), CenterY - Round((Radius - 25) * Cos(I * Pi / 6)));
- LineTo(CenterX + Round((Radius) * Sin(I * Pi / 6)), CenterY - Round((Radius) * Cos(I * Pi / 6)));
- End;
- Pen.Width := 4;
- For I := 0 to 59 do
- Begin
- MoveTo(CenterX + Round((Radius - 10) * Sin(I * Pi / 30)), CenterY - Round((Radius - 10) * Cos(I * Pi / 30)));
- LineTo(CenterX + Round((Radius) * Sin(I * Pi / 30)), CenterY - Round((Radius) * Cos(I * Pi / 30)));
- End;
- PrintDigits();
- Pen.Color := clBlack;
- HAngle := 0;
- MAngle := 0;
- SAngle := 0;
- MoveTo(CenterX, CenterY);
- Pen.Width := 8;
- LineTo(CenterX + Round(HArrow * Sin(HAngle) * 0.7), CenterY - Round(HArrow * Cos(HAngle) * 0.7));
- MoveTo(CenterX, CenterY);
- Pen.Width := 6;
- LineTo(CenterX + Round(MArrow * Sin(MAngle) * 0.8), CenterY - Round(MArrow * Cos(MAngle) * 0.8));
- MoveTo(CenterX, CenterY);
- Pen.Width := 4;
- LineTo(CenterX + Round(SArrow * Sin(SAngle) * 0.9), CenterY - Round(SArrow * Cos(SAngle) * 0.9));
- End;
- End;
- Procedure TMainUnit.TimerTimer(Sender: TObject);
- Begin
- DrawArrows(rgb(176, 196, 222));
- PrintDigits();
- DecodeTime(Time, Hour, Min, Sec, MSec);
- SAngle := (Sec / 60) * (2 * Pi);
- MAngle := (Min / 60 * (2 * Pi)) + SAngle / 60;
- HAngle := ((Hour mod 12) / 12 * (2 * Pi)) + MAngle / 12;
- DrawArrows(clBlack);
- End;
- Procedure TMainUnit.DrawArrows(Color: TColor);
- Begin
- With (ClockField.Canvas) do
- Begin
- Pen.Color := Color;
- MoveTo(CenterX, CenterY);
- Pen.Width := 12;
- LineTo(CenterX + Round(HArrow * Sin(HAngle) * 0.7), CenterY - Round(HArrow * Cos(HAngle) * 0.7));
- MoveTo(CenterX, CenterY);
- Pen.Width := 8;
- LineTo(CenterX + Round(MArrow * Sin(MAngle) * 0.8), CenterY - Round(MArrow * Cos(MAngle) * 0.8));
- MoveTo(CenterX, CenterY);
- Pen.Width := 4;
- LineTo(CenterX + Round(SArrow * Sin(SAngle) * 0.9), CenterY - Round(SArrow * Cos(SAngle) * 0.9));
- SndPlaySound('tick.wav', SND_ASYNC);
- End;
- End;
- Procedure TMainUnit.PrintDigits();
- Begin
- With (ClockField.Canvas) do
- Begin
- Font.Style := [fsBold];
- Font.Size := 20;
- TextOut(CenterX - TextWidth('XII') div 2, CenterY - Radius + 25, 'XII');
- TextOut(CenterX + Radius - 25 - TextWidth('III'), CenterY - TextHeight('3') div 2, 'III');
- TextOut(CenterX - TextWidth('VI') div 2, CenterY + Radius - 25 - TextHeight('VI'), 'VI');
- TextOut(CenterX - Radius + TextWidth('IX'), CenterY - TextHeight('IX') div 2, 'IX');
- End;
- End;
- procedure TMainUnit.InfoAboutDeveloperClick(Sender: TObject);
- begin
- Application.MessageBox('Арефин Владислав гр.251004', 'Разрабочик', 0);
- end;
- procedure TMainUnit.N1Click(Sender: TObject);
- begin
- Application.MessageBox('Часы имеют звуковое сопровождение - иммитацию хода настоящих механических часов. Для получения уникального пользовательского опыта включите звук.', 'Информация', 0);
- end;
- procedure TMainUnit.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
- begin
- CanClose := Application.MessageBox('Вы действительно хотите выйти?', 'Выход', MB_YESNO + MB_ICONQUESTION) = ID_YES;
- end;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement