: -
41
3-78-2 ..
..., ..
2009
充.....3
.....3
腅...3
....3
.....8
.....9
̅...16
.......17
..18
1.
-
.(. 1.1)
. 1.1-
- .
.
( 1.2):
. 1.2-
, . () , , :
-.
TPoint x,y Pcolor. , , . Init, Show Destructor Rotate . :
, 0, 0 ; , ; ; OsX, OsY .
( ). , , , , .
TPoint : Constructor Init - ; Rotate, step, Show , .
|
|
graph Ellipse, , moveto lineto . TEllipse TPoint, det, EColor Show Rotate . :
x=a*cos(t); y=b*sin(t), t=
b , t i det. .
TLine TPoint, Show Rotate . x y, pn pk TPoint, , . Show Rotate Lcolor . , x y. , TLine pn, x y. , , . , , , .
TSquare () 4- Line, as Scolor , Show Rotate . .
TScreen, , , : , . , , TSquare, - ( Gdisp Gcolor) DrawGround , line0, sides0 , nom, OsX,OsY , . ShiftOsXY ShiftOsXY , . ShiftOsXY - . ShiftOsXY . step . X10Y1. CalcABC Dist. CalcABC Ax+By+C=0 X10Y1 (, ) :
|
|
A=yk - yn; B:= xn - xk; C:= xk * yn - xn * yk,
xn, yn, xk, yk .
Dist () ( ) :
|
, , . ShiftOsXY True. Rotateall . Go .
- TScreen.go:
program Lab;
uses
Forms,
Kurspas in 'Kurspas.pas' {Form1},
ElSq in 'ElSq.pas' {Form2};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
unit Kurspas;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ElSq;
Const
sizeSq = 100; { }
colorEl = clBlue; { }
colorSq = clYellow; { }
colorG = ClGreen; { }
type { }
TForm1 = class(TForm)
Image1: TImage;
Button1: TButton;
Button2: TButton;
Timer1: TTimer;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
Var screen: TScreen; { TScreen}
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); { Go}
begin
timer1.Enabled:=true; { }
end;
procedure TForm1.Button2Click(Sender: TObject); { Exit}
begin
screen.Done; { }
Close; { }
end;
procedure TForm1.Timer1Timer(Sender: TObject); { }
begin
Screen.Go; { }
end;
procedure TForm1.FormCreate(Sender: TObject); { }
begin
Screen.Init(sizeSq, colorEl, colorSq, colorG, Image1.height-30,Image1);
{ Screen}
end;
procedure TForm1.Button3Click(Sender: TObject); { Stop}
begin
timer1.Enabled:=false; { }
end;
end.
unit ElSq;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
Const
|
|
det = 36; { }
xrad = 40; { }
yrad = 25; { }
kv = 4; { }
speed1 = 0.9; { }
speed = 1.5; { }
one = pi/180; { }
step = one*speed; { }
step1 = one*speed1; { }
Type TPoint = Object {- }
x,y:Real; { }
Pcolor:Byte; { }
Constructor Init (xx,yy:Real; col:Byte);
Procedure Rotate (xOs, yOs, spd:real); Virtual;
Procedure Show (col:Byte; var image1:TImage); Virtual;
Destructor Done;
End;
TSide = array [1..det] of TPoint; { }
TEllipse=Object (TPoint) {- }
line:TSide; { }
EColor:Byte; { }
Constructor init (colE:byte);
procedure Rotate (xOsE, yOsE, spd:real); Virtual;
Procedure Show (col:Byte; var image1:TImage); Virtual;
Destructor Done;
end;
TLine = Object (TPoint) {- }
pn, pk:TPoint; { }
Lcolor:Byte; { }
Constructor Init (x1,y1,x2,y2:Real; col:Byte);
Procedure Rotate (xOs, yOs, spd:real); Virtual;
Procedure Show (col:Byte; var image1:TImage); Virtual;
Destructor Done;
End;
TSides = Array [ 0..kv-1 ] Of TLine; { }
TSquare = Object (TLine) {- }
as:Byte; { }
Sides:TSides; { }
Scolor:Byte; { }
Constructor Init (aa, colK:Byte);
Procedure Rotate (xOs, yOs, spd:real); Virtual;
Procedure Show (col:Byte; var image1:TImage); Virtual;
Destructor Done;
End;
TScreen = Object (TEllipse) {- }
image1:TImage; { }
Elps:TEllipse; {}
Sqre:Tsquare; {}
Gdisp:Integer; { }
Gcolor:TColor; { }
line0:TSide; { }
sides0:TSides;
OsXE,OsYE,nom:Integer; { }
Constructor Init (aa:Byte; colE, colK, colG:TColor; dG:Integer; var image:TImage);
Function ShiftOsXY:Boolean; Virtual;
Function ShiftOsXYE:Boolean;
Procedure CalcABC(Var S1,S2:TLine; Var A,B,C:Real);
Function Dist(A,B,C, xx,yy:Real):Real;
Procedure Rotateall(xOs,yOs:Integer; spd:real);
Procedure Go; Virtual;
Procedure DrawGround; Virtual;
Destructor Done;
End;
{TForm2 = class(TForm)
private }
{ Private declarations}
{ public }
{ Public declarations }
{ end;
var
Form2: TForm2;}
implementation
{---------------------------------------------------------------}
Constructor TPoint.Init (xx, yy:Real; col:TColor);
Begin x:=xx; y:=yy; Pcolor:= col; End;
Procedure TPoint.Rotate (xOs,yOs:Integer; spd:real);
Var xx, yy:Real;
Begin xx:= (x - xOs)*Cos(spd) - (y - yOs)*Sin(spd) + xOs;
yy:= (x - xOs)*Sin (spd) + (y - yOs)*Cos(spd) + yOs;
x:=xx; y:=yy;
End;
Procedure TPoint.Show;
Begin
Image1.Canvas.pixels[Round(x),Round(y)]:=col;
End;
Destructor TPoint.Done;
Begin End;
{---------------------------------------------------------------}
Constructor TLine.Init (x1,y1,x2,y2:Real; col:TColor);
Begin pn.Init(x1,y1,col); pk.Init(x2,y2,col); Lcolor:=col; End;
Procedure TLine.Rotate (xOs,yOs:Integer; spd:real);
Begin pn.Rotate(xOs,yOs,spd); pk.Rotate(xOs,yOs,spd); End;
Procedure TLine.Show;
Begin If col=clWhite Then image1.canvas.pen.color:= col Else image1.canvas.pen.color:= Lcolor;
|
|
image1.Canvas.MoveTo(Round(pn.x),Round(pn.y));
image1.canvas.LineTo(Round(pk.x),Round(pk.y));
End;
Destructor TLine.Done;
Begin End;
{---------------------------------------------------------------}
Constructor TEllipse.init(colE:byte); { }
var i:byte;
px,py:real;
Begin
EColor:=colE;
for i:=1 to det do begin
px:=xrad*cos((i-1)*2*pi/det); { }
py:=yrad*sin((i-1)*2*pi/det);
with line[i] do init(px,py,colE);
end;
end;
Procedure TEllipse.rotate(xOsE, yOsE, spd:real); { }
Var i:byte;
begin
for i:=1 to det do line[i].rotate(xOsE,yOsE,spd); { }
end; {}
procedure TEllipse.Show; { ()}
var i:byte; {}
begin image1.Canvas.Pen.Color:=col; { }
image1.canvas.moveto(Round(line[1].x),round(line[1].y));{ }
for i:=det downto 1 do
with line[i] do image1.canvas.lineto(round(x),round(y));{ }
end;
destructor TEllipse.done;
begin end;
{---------------------------------------------------------------}
Constructor TSquare.Init (aa, colK:Byte); { }
Begin
as:= aa; { }
Sides[0]. Init (as, as, 0, as, colK); { }
Sides[1]. Init (0, as, 0, 0, colK);
Sides[2]. Init (0, 0, as, 0, colK);
Sides[3]. Init (as, 0, as, as, colK);
Scolor:= colK;
End;
Procedure TSquare.Rotate (xOs, yOs, spd:real); { }
Var i:Byte;
Begin
For i:=0 To kv-1 Do Sides[i].Rotate (xOs,yOs,spd);
End;
Procedure TSquare.Show; {() }
Var i:Byte;
Begin For i:= 0 To kv-1 Do Sides[i].Show (col,image1); End;
Destructor TSquare.Done;
Begin End;
{---------------------------------------------------------------}
Constructor TScreen.Init (aa:Byte; colE, colK, colG:TColor; dG:Integer; var image:TImage);
Var i:Byte;
Begin
{ }
image1:=image; { }
image1.Canvas.Brush.Color:=clWhite;
Image1.Canvas.Brush.Style:=bsSolid;
image1.Canvas.FillRect(rect(0,0,image1.Width,image1.Height));
Sqre.Init (aa, colK); { }
Elps.init(colE); { }
Gdisp:= dG;
For i:= 0 To kv-1 Do With Sqre.Sides[i] Do Begin { }
pn.y:= pn.y + Gdisp - Sqre.ss-2*yrad-1;
pk.y:= pk.y + Gdisp - Sqre.ss-2*yrad-1;
pn.x:= pn.x + xrad;
pk.x:= pk.x + xrad;
End;
For i:=1 to Det do With Elps.line[i] do begin { }
y:=y+Gdisp-yrad;
x:=x+xrad; end;
Gcolor:= colG; { }
nom:=det-1; { }
OsXE:= xrad;
OsYE:= Gdisp;
DrawGround; { }
End;
Procedure TScreen.DrawGround; { }
Begin Image1.canvas.pen.color:= Gcolor; { }
Image1.Canvas.Brush.Color:=Gcolor; { }
image1.Canvas.MoveTo(0, Gdisp + 1); { }
Image1.canvas.LineTo(Image1.Width, Gdisp + 1);
Image1.Canvas.Brush.Style:=bsBDiagonal; { }
Image1.canvas.FloodFill(2,Gdisp+2,Gcolor, fsBorder); { }
image1.Canvas.Refresh;
End;
Function TScreen.ShiftOsXYE:Boolean; { }
var i:byte;
Begin
ShiftOsXYE:= False;
for i:=1 to det do { }
If elps.line[i].y>Gdisp Then { }
if Round(elps.line[i].x)>OsXE then Begin { }
elps.line:=line0; { }
sqre.Sides:=sides0;
OsXE:= Round(elps.line[i].x); { }
ShiftOsXYE:= True; End;
End;
{ 2 , }
Procedure TScreen.CalcABC(Var S1,S2:TLine; Var A,B,C:Real);
Var xn,yn,xk,yk:Real;
Begin xn:= (S1.pn.x+S2.pk.x)/2; yn:= (S1.pn.y+S2.pk.y)/2;
xk:= (S1.pk.x+S2.pn.x)/2; yk:= (S1.pk.y+S2.pn.y)/2;
A:= yk - yn; B:= xn - xk; C:= xk * yn - xn * yk;
End;
Function TScreen.Dist(A,B,C, xx,yy:Real):Real;
Begin Dist:= Abs((A*xx+B*yy+C) / Sqrt(A*A+B*B)); End;
Function TScreen.ShiftOsXY:Boolean; { }
Var Ax, Bx, Cx, Ay, By, Cy, xx, yy:Real;
i:Integer;
Begin
ShiftOsXY:= False;
{ }
|
|
CalcABC(Sqre.Sides[1], Sqre.Sides[3], Ax, Bx, Cx);
CalcABC(Sqre.Sides[0], Sqre.Sides[2], Ay, By, Cy);
For i:= 1 To Det Do { }
Begin
yy:= Dist(Ay, By, Cy, Elps.line[i].x, Elps.line[i].y); { }
xx:= Dist(Ax, Bx, Cx, Elps.line[i].x, Elps.line[i].y);
If (xx <= Sqre.ss/2) and (yy <= Sqre.ss/2) { }
Then If i<>nom then { }
Begin
nom:=i; { }
ShiftOsXY:= True;
sqre.Sides:=sides0; { }
Exit;
End;
End;
End;
Procedure TScreen.Rotateall(xOs,yOs:Integer; spd:real); { }
var xx,yy:real;
Begin Sqre.rotate(xOs,yOs,spd);
Elps.rotate(xOs,yOs,spd);
End;
Procedure TScreen.Go; { 1 }
Begin
Sqre.Show (clWhite,image1); { }
Elps.show (clWhite,image1);
sides0:=sqre.Sides; { }
repeat
sqre.Rotate (Round(elps.line[nom].x), Round(elps.line[nom].y), step); { }
until not ShiftOsXY; { }
sides0:=sqre.Sides; { }
line0:=elps.line;
Repeat
Rotateall(OsXE, OsYE, step1); { }
until not ShiftOsXYE; { }
Sqre.Show (Sqre.Scolor, Image1); { }
Elps.Show (Elps.Ecolor,image1); image1.Refresh;
If OsXE > Image1.Width then { , }
Init (Sqre.ss, Elps.Ecolor, Sqre.Scolor, Gcolor, Gdisp,image1);
{Until False;}
End;
Destructor TScreen.Done;
Begin End;
{---------------------------------------------------------------}
end.