Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program voronoi;
- {$I SRL/OSR.simba}
- function GenerateVoronoi(TPA: TPointArray): TMufasaBitmap;
- var
- w,h,x,y,i,d: Int32;
- B: TBox;
- p: TPoint;
- Tree: TSlackTree;
- begin
- B := TPA.Bounds();
- W := B.x2+1;
- H := B.y2+1;
- Tree.Init(TPA);
- Result.Init();
- Result.SetSize(W, H);
- for x:=0 to W-1 do
- for y:=0 to H-1 do
- begin
- p := Tree.Nearest(Point(x,y));
- d := Sqr(p.x-x) + Sqr(p.y-y);
- i := UInt32((p.y * $0f0f1f1f) xor p.x) and $FFFFFF;
- Result.SetPixel(x,y, i);
- end;
- for i:=0 to High(TPA) do
- Result.DrawCircleFilled(TPA[i], 2, 0);
- end;
- var
- TPA: TPointArray;
- im: TMufasaBitmap;
- begin
- TPA := RandomTPA(100, Box(0,0,500,500));
- im := GenerateVoronoi(TPA);
- im.Show();
- im.Free();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement