- 4.51.2.4.42. -
Table of Contents
4. Standard Units
4.51. ObjGfx40 - ObjectGraphics 4.0 Unit
4.51.2. ObjGfx40 Unit Object Types
4.51.2.4. ogSurface object
4.51.2.4.42. ogPolygon()
4.51.2.4.42. ogPolygon()
Targets: MS-DOS, Win32 console
ObjGfx40 Unit
Draws the outline of a polygon.
Declaration:
procedure ogPolygon(numPoints:uInt32; var polyPoints: array of
ogPoint2d; colour:uInt32);
Remarks:
PolyPoints is an array of ogPoint that contains the coordinates of each
intersection in the polygon. NumPoints specifies the number of coordinates
in polyPoints. A coordinate consists of two integers, an X and a Y value.
Because ogPolygon is line based, the anti-alias setting will affect whether the
polygon is drawn with anti-aliased lines.
See also:
Sample code:
{ogPolygon.pas}
uses
ObjGfx40, CRT;
const MAX_POINTS=10;
var
points: array [ 0..MAX_POINTS-1 ] of ogPoint2d;
pointsDir:array [ 0..MAX_POINTS-1 ] of ogPoint2d;
count:int32;
r, g, b:uInt8;
rDir,gDir,bDir:int32;
buf:^ogSurface;
begin
randomize;
new(buf, ogInit);
if not screen^.ogCreate(640,400,OG_PIXFMT_32BPP) then
begin
writeln('Error setting video mode');
halt
end;
buf^.ogClone(screen^);
r := random(254)+1;
g := random(254)+1;
b := random(254)+1;
rDir := 1;
gDir := -1;
bDir := 1;
for count:=0 to MAX_POINTS-1 do
with points[count] do
begin
x := random(screen^.ogGetMaxX-1)+1;
y := random(screen^.ogGetMaxY-1)+1;
end;
for count:=0 to MAX_POINTS-1 do
with pointsDir[count] do
begin
if (random(100)>50) then x := -1 else x := 1;
if (random(100)>50) then y := -1 else y := 1;
end;
repeat
if (r = 0) or (r = 255) then rDir := -rDir else
if (random(100) > 97) then rDir := -rDir;
if (g = 0) or (g = 255) then gDir := -gDir else
if (random(100) > 97) then gDir := -gDir;
if (b = 0) or (b = 255) then bDir := -bDir else
if (random(100) > 97) then bDir := -bDir;
inc(r, rDir);
inc(g, gDir);
inc(b, bDir);
for count:=0 to MAX_POINTS-1 do
begin
inc(points[count].x, pointsDir[count].x);
if ((points[count].x = 0) or (points[count].x = screen^.ogGetMaxX)) then
pointsDir[count].x := -pointsDir[count].x;
inc(Points[count].y, pointsDir[count].y);
if ((Points[count].y = 0) or (points[count].y = screen^.ogGetMaxY)) then
pointsDir[count].y := -pointsDir[count].y;
end;
buf^.ogPolygon(MAX_POINTS, points, buf^.ogRGB(r, g, b));
screen^.ogCopy(Buf^);
buf^.ogPolygon(MAX_POINTS, points, buf^.ogRGB(0, 0, 0));
until keyPressed;
while keyPressed do readKey;
dispose(buf, ogDone);
end.
- 4.51.2.4.42. -