Хоть и чуть криво, но вродже бы проблему решил. Вот код.
| Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;
type TForm1 = class(TForm) Button1: TButton; Timer1: TTimer; Button2: TButton; ComboBox1: TComboBox; Label1: TLabel; Button3: TButton; procedure FormCreate(Sender: TObject); procedure FormPaint(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure ArrowDraw(DrawColor: TColor); procedure Timer1Timer(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1; CenterX , CenterY , Radius , HourArrow , MinArrow , SecArrow : integer; HourAngle , MinAngle , SecAngle : real; Hour , Min , Sec , MSec : word; tip: word; smx , smy : integer; kat1 , kat2 , kat3 , kat4 : integer;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject); begin Form1.BorderStyle := BsSingle; Form1.BorderIcons := [biSystemMenu,biMinimize]; Timer1.Interval := 1000; Timer1.Enabled := false; CenterY := Form1.ClientHeight div 2 - 35; CenterX := CenterY; Radius := CenterX - 20; HourArrow := Radius - 30; MinArrow := Radius - 20; SecArrow := Radius - 10; tip := 0; end;
procedure TForm1.FormPaint(Sender: TObject); var i : integer; begin with Form1.Canvas do begin Pen.Color := clBlue; Pen.Width := 2; Brush.Color :=clWhite; case tip of 0: begin smx := 0; smy := 0; Ellipse( 20 , 20 , 20 + 2 * Radius , 20 + 2 * Radius ); end; 1: begin smx := 0; smy := 0; Rectangle( 20 , 20 , 20 + 2 * Radius , 20 + 2 * Radius ); end; 2: begin smx := 0; smy := Radius div 4; Rectangle( 20 , 20 + smy , 20 + 2 * Radius , 20 + 2 * Radius - smy ); end; 3: begin smx := 0; smy := Radius div 4; Ellipse( 20 , 20 + smy , 20 + 2 * Radius , 20 + 2 * Radius - smy ); end; 4: begin smx := Radius div 4; smy := 0; Ellipse( 20 + smx , 20 , 20 + 2 * Radius - smx , 20 + 2 * Radius - smy); end; end; Pen.Width := 2; for i:=0 to 11 do begin if ( tip in [1,2] ) AND ( i in[1,2,4,5,7,8,10,11] ) then begin kat1 := CenterX + round( ( Radius + ( 2 + Radius - abs( Radius * sin( i / 6 * pi ) ) ) - 9 - smx ) * sin( i / 6 * pi ) ); kat2 := CenterX + round( ( Radius + ( 2 + Radius - abs( Radius * sin( i / 6 * pi ) ) ) - smx ) * sin( i / 6 * pi ) ); kat3 := CenterX + round( ( Radius + ( Radius - abs( Radius * cos( i / 6 * pi ) ) ) - 9 - smy ) * cos( i / 6 * pi ) ); kat4 := CenterX + round( ( Radius + ( Radius - abs( Radius * cos( i / 6 * pi ) ) ) - smy ) * cos( i / 6 * pi ) ); end else begin kat1 := CenterX + round( ( Radius - 9 - smx ) * sin( i / 6 * pi ) ); kat2 := CenterX + round( ( Radius - smx ) * sin( i / 6 * pi ) ); kat3 := CenterY - round( ( Radius - 9 - smy ) * cos( i / 6 * pi ) ); kat4 := CenterY - round( ( Radius - smy ) * cos( i / 6 * pi ) ); end; MoveTo( kat1 , kat3 ); LineTo( kat2 , kat4 ); end; Font.Height := 10; Font.Color := clBlack; Brush.Color := Form1.Color; TextOut( CenterX - textWidth('12') div 2 , CenterY - Radius - TextHeight('12') - 5 + smy, '12' ); TextOut( CenterX + Radius + 5 - smx, CenterY , '3' ); TextOut( CenterX - textWidth('6') div 2 , CenterY + Radius + 5 - smy, '6' ); TextOut( CenterX - textWidth('9') + smx - Radius - 5 , CenterY , '9' ); end; end;
procedure TForm1.Button1Click(Sender: TObject); begin if Button1.Caption = 'Ñòàðò' then begin FormPaint( Sender ); DecodeTime( Time , Hour , Min , Sec , MSec ); HourAngle := ( Hour mod 12 ) / 12 * 2 * pi; MinAngle := Min / 60 * 2 * pi; SecAngle := Sec / 60 * 2 * pi; ArrowDraw( clRed ); Button1.Caption := 'Ñòîï'; Timer1.Enabled := true; end else begin Button1.Caption := 'Ñòàðò'; Timer1.Enabled := false; end; end;
procedure TForm1.ArrowDraw(DrawColor: TColor); begin case tip of 0: begin smx := 0; smy := 0; end; 1: begin smx := 0; smy := 0; end; 2: begin smx := 0; smy := Radius div 4; end; 3: begin smx := 0; smy := Radius div 4; end; 4: begin smx := Radius div 4; smy := 0; end; end; with Form1.Canvas do begin Pen.Color := DrawColor; MoveTo( CenterX , CenterY ); Pen.Width := 8; if tip in [1,2] then LineTo( CenterX + round( ( HourArrow - smx + ( HourArrow - abs( HourArrow * sin( HourAngle ) ) ) ) * sin( HourAngle ) ) , CenterY - round( ( HourArrow - smy + ( HourArrow - abs( HourArrow * cos( HourAngle ) ) ) ) * cos( HourAngle ) ) ) else LineTo( CenterX + round( ( HourArrow - smx ) * sin( HourAngle ) ) , CenterY - round( ( HourArrow - smy ) * cos( HourAngle ) ) ); MoveTo( CenterX , CenterY ); Pen.Width := 4; if tip in [1,2] then LineTo( CenterX + round( ( MinArrow - smx + ( MinArrow - abs( MinArrow * sin( MinAngle ) ) ) ) * sin( MinAngle ) ) , CenterY - round( ( MinArrow - smy + ( MinArrow - abs( MinArrow * cos( MinAngle ) ) ) ) * cos( MinAngle ) ) ) else LineTo( CenterX + round( ( MinArrow - smx ) * sin( MinAngle ) ) , CenterY - round( ( MinArrow - smy ) * cos( MinAngle ) ) ); MoveTo( CenterX , CenterY ); Pen.Width := 1; if tip in [1,2] then LineTo( CenterX + round( ( SecArrow - smx + ( SecArrow - abs( SecArrow * sin( SecAngle ) ) ) ) * sin( SecAngle ) ) , CenterY - round( ( SecArrow - smy + ( SecArrow - abs( SecArrow * cos( SecAngle ) ) ) ) * cos( SecAngle ) ) ) else LineTo( CenterX + round( ( SecArrow - smx ) * sin( SecAngle ) ) , CenterY - round( ( SecArrow - smy ) * cos( SecAngle ) ) ); end; end;
procedure TForm1.Button2Click(Sender: TObject); begin Close; end;
procedure TForm1.Timer1Timer(Sender: TObject); begin ArrowDraw( clWhite ); DecodeTime( Time , Hour , Min , Sec , MSec ); HourAngle := ( Hour mod 12 ) / 12 * 2 * pi; MinAngle := Min / 60 * 2 * pi; SecAngle := Sec / 60 * 2 * pi; ArrowDraw( clRed ); end;
procedure TForm1.Button3Click(Sender: TObject); begin tip := ComboBox1.ItemIndex; Form1.Canvas.Brush.Color := Form1.Color; Form1.Canvas.Pen.Color := Form1.Color; Form1.Canvas.Rectangle(0,0,Form1.ClientWidth,Form1.ClientHeight-50); FormPaint( Sender ); end;
end. | |