Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program FIX_ME;
- {$i srl/osr.simba}
- function TSRL.RandomPointEx(From: TPoint; Rect: TRectangle; Force:Double=0.35): TPoint; constref; overload;
- var
- cx,cy,fx,fy,t,r,a,x,y,x1,y1,x2,y2: Double;
- begin
- with rect do
- begin
- a := ArcTan2(Left.Y-Top.Y, Left.X-Top.X);
- X := (Top.X + Right.X + Btm.X + Left.X) / 4;
- Y := (Top.Y + Right.Y + Btm.Y + Left.Y) / 4;
- x1 := X-Hypot(Left.y-Top.y, Left.x-Top.x) / 2;
- y1 := Y-Hypot(Left.y-Btm.y, Left.x-Btm.x) / 2;
- x2 := X+Hypot(Left.y-Top.y, Left.x-Top.x) / 2;
- y2 := Y+Hypot(Left.y-Btm.y, Left.x-Btm.x) / 2;
- end;
- fx := From.X;
- fy := From.Y;
- if fx < x1 then fx := x1 else if fx > x2 then fx := x2;
- if fy < y1 then fy := y1 else if fy > y2 then fy := y2;
- cy := (Y2 + Y1) / 2;
- cx := (X2 + X1) / 2;
- r := Hypot(fx-cx, fy-cy) * Force;
- t := ArcTan2(cy-fy, cx-fx);
- fx += (Cos(t) * r);
- fy += (Sin(t) * r);
- Result.x := Round(SkewedRand(fx, x1+1, x2-1, srl.GAUSS_CUTOFF));
- Result.y := Round(SkewedRand(fy, y1+1, y2-1, srl.GAUSS_CUTOFF));
- Result := RotatePoint(Result, a, (X2+X1)/2+Random()-0.5, (Y2+Y1)/2+Random()-0.5);
- end;
- var
- BMP: TMufasaBitmap;
- P: TPoint;
- R: TRectangle;
- B: TBox;
- begin
- BMP := GetMufasaBitmap(CreateBitmap(500, 500));
- BMP.Debug();
- R := Box(Random(100, 250), Random(100, 250), Random(250, 400), Random(250, 400)).ToRectangle.Rotate(Radians(Random(360)));
- while True do
- begin
- P.X := Random(5, 495);
- P.Y := Random(5, 495);
- BMP.Clear();
- BMP.DrawRect(R, clOrange);
- BMP.DrawCircle(P, 5, True, clRed);
- for 0 to 1000 do
- with srl.RandomPointEx(P, R) do
- BMP.SetPixel(X, Y, clLime);
- BMP.UpdateDebugImage();
- Wait(1000);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement