mirror of
https://git.sr.ht/~rabbits/macintosh_cookbook
synced 2025-01-14 20:30:31 +00:00
77 lines
1.6 KiB
ObjectPascal
77 lines
1.6 KiB
ObjectPascal
program ExampleRotate;
|
|
|
|
uses
|
|
FixMath;
|
|
|
|
const
|
|
PI = 3.141592654;
|
|
RADDEG = 0.017453292; { PI/180 }
|
|
DEGRAD = 57.29577951; { 180/PI }
|
|
|
|
type
|
|
Point2D = record
|
|
x: Fixed;
|
|
y: Fixed;
|
|
end;
|
|
|
|
var
|
|
origin, target: Point2D;
|
|
|
|
procedure SetPoint2D (var point: Point2D; x, y: Fixed);
|
|
begin
|
|
point.x := Long2Fix(x);
|
|
point.y := Long2Fix(y);
|
|
end;
|
|
|
|
function Distance2D (a, b: Point2D): Fixed;
|
|
var
|
|
val: Fixed;
|
|
begin
|
|
val := FracMul((b.x - a.x), (b.x - a.x)) + FracMul((b.y - a.y), (b.y - a.y));
|
|
Distance2D := Frac2Fix(FracSqrt(val));
|
|
end;
|
|
|
|
procedure RotatePoint2D (var target, origin: Point2D; angle: Fixed);
|
|
var
|
|
radians, cos, sin, x, y, r: Fixed;
|
|
begin
|
|
radians := FixRatio(angle, 314);
|
|
r := Distance2D(target, origin);
|
|
target.x := origin.x + FixMul(r, FracCos(radians));
|
|
target.y := origin.y + FixMul(r, FracSin(radians));
|
|
end;
|
|
|
|
procedure DrawPoint2D (point: Point2D);
|
|
var
|
|
dotRect: Rect;
|
|
radius: Integer;
|
|
begin
|
|
SetRect(dotRect, Fix2Long(point.x), Fix2Long(point.y), Fix2Long(point.x) + 5, Fix2Long(point.y) + 5);
|
|
PaintOval(dotRect);
|
|
end;
|
|
|
|
begin
|
|
|
|
ShowDrawing;
|
|
|
|
{ origin }
|
|
SetPoint2D(origin, 100, 100);
|
|
DrawPoint2D(origin);
|
|
|
|
{ origin }
|
|
SetPoint2D(target, 150, 100);
|
|
RotatePoint2D(target, origin, 0);
|
|
DrawPoint2D(target);
|
|
SetPoint2D(target, 150, 100);
|
|
RotatePoint2D(target, origin, 90);
|
|
DrawPoint2D(target);
|
|
SetPoint2D(target, 150, 100);
|
|
RotatePoint2D(target, origin, 180);
|
|
DrawPoint2D(target);
|
|
SetPoint2D(target, 150, 100);
|
|
RotatePoint2D(target, origin, 270);
|
|
DrawPoint2D(target);
|
|
|
|
end.
|
|
|
|
{ note: This project requires the FixMath library. } |