23.09.2015, 20:07
|
|
I Like it!
|
|
Регистрация: 12.12.2009
Адрес: Россия, г. Новосибирск
Сообщения: 660
Версия Delphi: D6/D7
Репутация: 26643
|
|
Внес некоторые коррективы. Основная проблема в том, что Canvas у объекта TGeometryFigure не задан и в методе Show ты рисуешь "ниначем".
Код:
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:TGeometryFigure;
implementation
{$R *.dfm}
//создаёт форму
procedure TForm1.FormCreate(Sender: TObject);
begin
Width:=960; //Ширина формы
Height:=600; //Высота формы
end;
procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
MyLine1:=TGeometryFigure.Create(PaintBox1.Canvas, 270, ((PaintBox1.Left+PaintBox1.Width) div 2), ((PaintBox1.Left+PaintBox1.Height) div 2), ClBlack, (PaintBox1.Width div 2-10), 10);
MyLine1.Show(); //Рисует линию
PaintBox1.Canvas.Rectangle(8,8,208,208); //Рисует квадрат в паинтбоксе
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Timer1.Enabled := not Timer1.Enabled;
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
FCanvas:TCanvas;
{ Private declarations }
w:real; //Ширина фигуры
h:real; //Высота фигуры
ang:real; //угол поворота фигуры
x:integer; //Координата Х (Докуда рисовать фигуру)
y:integer; //Координата У (Докуда рисовать фигуру)
public
{ Public declarations }
procedure Show(); //Отображает фигуру
constructor Create(Destination: TCanvas; Newang:real; Newpx:integer; Newpy:integer; Newcvet:TColor; Neww:real; Newh:real);
end;
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(Destination: TCanvas; Newang:real; Newpx:integer; Newpy:integer; Newcvet:TColor; Neww:real; Newh:real);
begin
inherited Create(Newpx, Newpy, Newcvet);
w:=Neww;
h:=Newh;
ang:=Newang;
FCanvas := Destination;
end;
procedure TGeometryFigure.Show();
begin
if not Assigned(FCanvas) then Exit;
FCanvas.LineTo(px,py);
FCanvas.MoveTo(x,y);
end;
end.
__________________
Грамотно поставленный вопрос содержит не менее 50% ответа.
Грамотно поставленная речь вызывает уважение, а у некоторых даже зависть.
|