Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function TPACircle(center: TPoint; radius: Extended): TPointArray;
- var
- l, i, j, r: Integer;
- begin
- r := Floor(radius);
- SetLength(Result, Trunc((((r * 2) + 1) * ((r * 2) + 1)) * 0.8));
- l := 0;
- Result[0] := center;
- for i := 1 to r do
- begin
- Result[(l + 1)] := Point((center.X - i), center.Y);
- Result[(l + 2)] := Point((center.X + i), center.Y);
- Result[(l + 3)] := Point(center.X, (center.Y - i));
- Result[(l + 4)] := Point(center.X, (center.Y + i));
- l := (l + 4);
- for j := 1 to r do
- if (Sqr((j / radius)) + Sqr((i / radius)) <= 1) then
- begin
- Result[(l + 1)] := Point((center.X - j), (center.Y - i));
- Result[(l + 2)] := Point((center.X - j), (center.Y + i));
- Result[(l + 3)] := Point((center.X + j), (center.Y - i));
- Result[(l + 4)] := Point((center.X + j), (center.Y + i));
- l := (l + 4);
- end else
- Break;
- end;
- SetLength(Result, (l + 1));
- end;
- function TPACircleFilled(const C:TPoint; Rad:Integer): TPointArray;
- var
- x, y, i: Integer;
- sqrad: single;
- B: TBox;
- begin
- sqrad := Trunc(Sqr(Rad+0.5));
- B := IntToBox(C.x-Rad, C.y-Rad, C.x+Rad, C.y+Rad);
- SetLength(Result, (B.x2-B.x1+1)*(B.y2-B.y1+1));
- i := 0;
- for y:=B.y1 to B.y2 do
- for x:=B.x1 to B.x2 do
- if Sqr(x-c.x) + Sqr(y-c.y) < SqRad then
- begin
- Result[i] := Point(x,y);
- i := i+1;
- end;
- SetLength(Result, i);
- end;
- var
- t, i, b: Integer;
- a: TPointArray;
- begin
- ClearDebug;
- b := CreateBitmap(1000, 500);
- DisplayDebugImgWindow(1000, 500);
- DrawTPABitmap(b, TPACircle(Point(250, 250), 50.5), 16777215);
- DrawTPABitmap(b, TPACircleFilled(Point(750, 250), 50), 255);
- DrawBitmapDebugImg(b);
- for i := 0 to 9 do
- begin
- t := GetSystemTime;
- a := TPACircle(Point(100, 100), 2000.5);
- WriteLn(GetSystemTime - t, ' ms. for TPACircle. [', Length(a), ']');
- SetLength(a, 0);
- t := GetSystemTime;
- a := TPACircleFilled(Point(100, 100), 2000);
- WriteLn(GetSystemTime - t, ' ms. for TPACircleFilled. [', Length(a), ']');
- SetLength(a, 0);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement