20.03.2012, 02:47
|
|
.
|
|
Регистрация: 18.05.2011
Адрес: Омск
Сообщения: 3,970
Версия Delphi: 3,5,7,10,12,XE2
Репутация: выкл
|
|
Так пойдет?
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
TrackBar1: TTrackBar;
Image1: TImage;
procedure TrackBar1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure DrawCoo;
procedure DrawRect;
public
{ Public declarations }
end;
var
Form1: TForm1;
x0, y0 : Integer;
cosa, sina : Double;
RectCooOrg,
RectCooLast : array[0..4] of TPoint;
const
pi2 = 2 * pi;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
x0 := Image1.Width div 2; // центр координатной плоскости по х оси
y0 := Image1.Height div 2; // центр координатной плоскости по у оси
RectCooOrg[0].X := - 150;
RectCooOrg[0].Y := - 75;
RectCooOrg[1].X := 150;
RectCooOrg[1].Y := - 75;
RectCooOrg[2].X := 150;
RectCooOrg[2].Y := 75;
RectCooOrg[3].X := - 150;
RectCooOrg[3].Y := 75;
RectCooOrg[4].X := - 150;
RectCooOrg[4].Y := - 75;
RectCooLast[0].X := - 150;
RectCooLast[0].Y := - 75;
RectCooLast[1].X := 150;
RectCooLast[1].Y := - 75;
RectCooLast[2].X := 150;
RectCooLast[2].Y := 75;
RectCooLast[3].X := - 150;
RectCooLast[3].Y := 75;
RectCooLast[4].X := - 150;
RectCooLast[4].Y := - 75;
DrawCoo;
cosa := cos(pi2 * trackBar1.Position / 360);
sina := sin(pi2 * trackBar1.Position / 360);
DrawRect;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
label1.Caption := Inttostr(TrackBar1.Position);
Image1.Canvas.FillRect(Rect(0, 0, Width, Height));
DrawCoo;
cosa := cos(pi2 * trackBar1.Position / 360);
sina := sin(pi2 * trackBar1.Position / 360);
DrawRect;
end;
procedure TForm1.DrawCoo;
var
m, i : Integer;
begin
m := 25; // масштаб
Image1.Canvas.Pen.Color := clBlack;
// координатная плоскость
Image1.Canvas.MoveTo(0, y0);
Image1.Canvas.LineTo(ClientWidth, y0);
Image1.Canvas.MoveTo(x0, 0);
Image1.Canvas.LineTo(x0, ClientHeight);
// шкалирование осей
for i := -7 to 7 do
begin
Image1.Canvas.MoveTo(x0 + i * m, y0 - 5);
Image1.Canvas.LineTo(x0 + i * m, y0 - (-5));
if I <> 0 then
Image1.Canvas.TextOut(x0 + i * m - 5, y0 + 10, IntToStr(i));
Image1.Canvas.MoveTo(x0 + 5, y0 - m * i);
Image1.Canvas.LineTo(x0 - 5, y0 - m * i);
if I <> 0 then
Image1.Canvas.TextOut(x0 - 20, y0 + i * m - 5, IntToStr(-i));
end;
end;
procedure TForm1.DrawRect;
var
I : Integer;
begin
Image1.Canvas.Pen.Color := clLime;
for I := 0 to 3 do
begin
Image1.Canvas.MoveTo(RectCooLast[i].X + x0, RectCooLast[i].Y + y0);
Image1.Canvas.LineTo(RectCooLast[I + 1].X + x0, RectCooLast[I + 1].Y + y0);
end;
for I := 0 to 4 do
begin
RectCooLast[i].X := Round(RectCooOrg[i].X * cosa - RectCooOrg[i].Y * sina);
RectCooLast[i].Y := Round(RectCooOrg[i].Y * cosa + RectCooOrg[i].X * sina);
end;
end;
end.
__________________
Je venus de nulle part
55.026263 с.ш., 73.397636 в.д.
|