Не отображается палочка на paintbox1, и как её заставить двигаться по кругу по законам которые описаны в TZakon? помогите пожалуйста а то я запутался
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, MyClasses;
type
TForm1 = class(TForm)
PaintBox1: TPaintBox;
Button1: TButton;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure PaintBox1Paint(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MyLine1: TMyLine;
implementation
{$R *.dfm}
//создаёт форму
procedure TForm1.FormCreate(Sender: TObject);
begin
Width:=960; //Ширина формы
Height:=600; //Высота формы
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
MyLine1:=MyClasses.TMyLine.Create(PaintBox1.Canvas, 270, ((PaintBox1.Left+PaintBox1.Width) div 2), ((PaintBox1.Left+PaintBox1.Height) div 2), ClBlack, (PaintBox1.Width div 2-10), 5);
PaintBox1.Canvas.Rectangle(8,8,208,208); //Рисует квадрат в паинтбоксе
MyLine1.Show(); //Рисует линию
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Timer1.Enabled then
Timer1.Enabled := False //Таймер выкл
else
Timer1.Enabled := true;//Таймер вкл
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
PaintBox1.Invalidate;
end;
end.
Код:
unit MyClasses;
interface
uses
SysUtils, Classes, Graphics;
type
TZakon=class
private
{ Private declarations }
v:real; //скорость
a:real; //ускорение
s:real; //путь
public
{ Public declarations }
procedure FindSpeed(t:real); //находит скорость
procedure FindAcc(t:real); //Находит ускорение
procedure FindPut(t:real); //Находит путь
end;
//класс точка
type
TMyPoint=class
private
{ Private declarations }
px:integer; // Координата Х точки
py:integer; // Координата У точки
cvet:TColor; //Цвет точки
public
{ Public declarations }
constructor Create(Newpx:integer; Newpy:integer; Newcvet:TColor);
end;
//Класс геометрическая фигура
type
TGeometryFigure=class(TMyPoint)
private
{ Private declarations }
w:real; //Ширина фигуры
h:real; //Высота фигуры
ang:real; //угол поворота фигуры
x:integer; //Координата Х (Докуда рисовать фигуру)
y:integer; //Координата У (Докуда рисовать фигуру)
public
{ Public declarations }
constructor Create(Newang:real; Newpx:integer; Newpy:integer; Newcvet:TColor; Neww:real; Newh:real);
end;
//Класс Линия
type
TMyLine=class(TGeometryFigure)
private
{ Private declarations }
FCanvas:TCanvas; //Холст для рисования
public
{ Public declarations }
procedure Show(); //рисует линию
constructor Create(Destination:TCanvas; Newang:real; Newpx:integer; Newpy:integer; Newcvet:TColor; Neww:real; Newh:real);
end;
var
MyLine1:TGeometryFigure;
implementation
{TZakon1}
procedure TZakon.FindAcc(t:real); //Находит ускорение
begin
a:=sin(t);
end;
procedure TZakon.FindPut(t:real); //Находит путь
begin
s:=t-sin(t);
end;
procedure TZakon.FindSpeed(t:real); //Находит ускорение
begin
v:=-cos(t)+1;
end;
{ TMyPoint }
constructor TMyPoint.Create(Newpx:integer; Newpy:integer; Newcvet:TColor);
begin
px:=Newpx;
py:=Newpy;
cvet:=Newcvet;
end;
{ TGeometryFigure }
constructor TGeometryFigure.Create(Newang:real; Newpx:integer; Newpy:integer; Newcvet:TColor; Neww:real; Newh:real);
begin
inherited Create(Newpx, Newpy, Newcvet);
w:=Neww;
h:=Newh;
ang:=Newang;
end;
constructor TMyLine.Create(Destination: TCanvas; Newang:real; Newpx:integer; Newpy:integer; Newcvet:TColor; Neww:real; Newh:real);
begin
FCanvas:=Destination;
end;
procedure TMyLine.Show();
begin
if not Assigned(FCanvas) then Exit;
x:=Round(px+w*cos(ang*pi/180));
y:=Round(py+w*sin(ang*pi/180));
FCanvas.MoveTo(px,py);
FCanvas.LineTo(x,y);
end;
end.