program rotatetank;
{
Rotates a 32x32 tile
}
uses
ptccrt,
ptcgraph,
Math;
const
MAXCOL = 31;
blueNorth: array [0..MAXCOL, 0..MAXCOL] of byte =
((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 41, 41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 20, 20, 20, 26, 26, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 20, 190, 190, 190, 26, 26, 190, 190, 190, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 190, 190, 190, 26, 26, 190, 190, 190, 190, 190,20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 190, 190, 190, 26, 26, 190, 190, 190, 190, 190,20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 190, 190, 190, 26, 26, 190, 190, 190, 190, 190,20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 190, 190, 21, 26, 26, 21, 190, 190, 190, 190, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 190, 21, 23, 23, 23, 23, 21, 190, 190, 190, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 21, 23, 23, 23, 23, 23, 23, 21, 190, 190, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 21, 23, 1, 1, 1, 1, 23, 21, 190, 190, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 21, 23, 1, 1, 1, 1, 23, 21, 190, 190, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 21, 23, 1, 1, 1, 1, 23, 21, 190, 190, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 21, 23, 1, 1, 1, 1, 23, 21, 190, 190, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 21, 23, 23, 23, 23, 23, 23, 21, 190, 190, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 190, 21, 21, 21, 21, 21, 21, 190, 190, 190, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190,190, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190,190, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190,190, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
type
TSinglePoint = record
x, y: single;
end;
linedata = record
P: Tsinglepoint;
color: byte;
end;
var
x, y: integer;
r, c: integer;
b: array[0..MAXCOL, 0..MAXCOL] of linedata;
gmode, gdriver: smallint;
procedure rotatepoint(var P: Tsinglepoint; degrees, centerx, centerY: float);
var
rr: integer;
w, d, newx, newy, angle: float;
cx, cy, y, x: single;
begin
angle := degTorad(degrees);
cx := centerx;
cy := centery;
x := p.x;
y := p.y;
x := x - cx;
Y := y - cy;
newx := (x * cos(angle)) - (y * sin(angle));
newy := (x * sin(angle)) + (y * cos(angle));
newx := newx + cx;
newy := newy + cy;
p.x := newx;
p.y := newy;
end;
begin
clrscr;
gdriver := vesa;
Gmode := installusermode(640,480, 256, 1, 8000, 6000);
WindowTitle := 'Rotation';
initgraph(gdriver, gmode, '');
// display the original while assigning x,y locations
y := 200;
for r := 0 to MAXCOL do
begin
x := 200;
for c := 0 to MAXCOL do
begin
b[r, c].color := bluenorth[r, c];
b[r, c].p.x := x + c;
b[r, c].p.y := y + r;
putpixel(round(b[r, c].p.x), round(b[r, c].p.y), b[r, c].color);
end;
end;
// rotate and display in new location
for r := 0 to MAXCOL do
begin
for c := 0 to MAXCOL do
begin
// rotate 80 degrees
rotatepoint(b[r, c].p, 80, 200, 200);
putpixel(round(b[r, c].p.x) + 100, round(b[r, c].p.y), b[r, c].color);
end;
end;
readkey;
closegraph;
end.