-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrotate2.pas
More file actions
60 lines (47 loc) · 1.47 KB
/
rotate2.pas
File metadata and controls
60 lines (47 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
program AggEx;
uses
SysUtils,
AggExample,
agg_2D,
agg_basics;
{
https://www.crossgl.com/aggpas/documentation/index.html#Rotate
}
type
TAggExample1 = class(TAggExample)
protected
procedure Draw(agg: Agg2D_ptr); override;
end;
const
SURFACE_WIDTH = 240;
SURFACE_HEIGHT = 180;
procedure TAggExample1.Draw(agg: Agg2D_ptr);
begin
{
One frequent case for rotation transformation is rotating something around it's own axis. For example, if user wants to rotate the whole TBitmap surface (around it's axis), two more translations must be involved, because before rotation the center of rotation is in coordinates origin (which is Top Left or Bottom Left corner). So the transformation sequence changes like this:
}
agg^.clearAll(0, 0, 0, 0);
//agg^.noFill;
agg^.noLine;
// First rectangle
agg^.fillColor($00, $00, $FF, $7F);
agg^.rectangle(70, 40, 170, 140);
// [!] set center point to the middle of TBitmap surface
agg^.Translate(-SURFACE_WIDTH / 2, -SURFACE_HEIGHT / 2);
// Rotate by 15 degrees
agg^.rotate(Deg2Rad(15));
// [!] return coordinates system back
agg^.Translate(SURFACE_WIDTH / 2, SURFACE_HEIGHT / 2);
// The same rectangle in a new coordinates
//agg^.lineColor($FF, $00, $00);
agg^.fillColor($FF, $00, $00, $7F);
agg^.rectangle(70, 40, 170, 140);
end;
var
p: TAggExample1;
begin
p := TAggExample1.Create(SURFACE_WIDTH, SURFACE_HEIGHT, ChangeFileExt({$I %FILE%}, '.png'));
p.DrawImage;
p.SaveToPng;
p.Free;
end.