Advertisement
WarPie90

Not Working: TSRL.RandomPointEx->TRectangle

Mar 30th, 2018
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.71 KB | None | 0 0
  1. program FIX_ME;
  2. {$i srl/osr.simba}
  3.  
  4. function TSRL.RandomPointEx(From: TPoint; Rect: TRectangle; Force:Double=0.35): TPoint; constref; overload;
  5. var
  6.   cx,cy,fx,fy,t,r,a,x,y,x1,y1,x2,y2: Double;
  7. begin
  8.   with rect do
  9.   begin
  10.     a := ArcTan2(Left.Y-Top.Y, Left.X-Top.X);
  11.     X := (Top.X + Right.X + Btm.X + Left.X) / 4;
  12.     Y := (Top.Y + Right.Y + Btm.Y + Left.Y) / 4;
  13.     x1 := X-Hypot(Left.y-Top.y, Left.x-Top.x) / 2;
  14.     y1 := Y-Hypot(Left.y-Btm.y, Left.x-Btm.x) / 2;
  15.     x2 := X+Hypot(Left.y-Top.y, Left.x-Top.x) / 2;
  16.     y2 := Y+Hypot(Left.y-Btm.y, Left.x-Btm.x) / 2;
  17.   end;
  18.  
  19.   fx := From.X;
  20.   fy := From.Y;
  21.   if fx < x1 then fx := x1 else if fx > x2 then fx := x2;
  22.   if fy < y1 then fy := y1 else if fy > y2 then fy := y2;
  23.   cy := (Y2 + Y1) / 2;
  24.   cx := (X2 + X1) / 2;
  25.   r := Hypot(fx-cx, fy-cy) * Force;
  26.   t := ArcTan2(cy-fy, cx-fx);
  27.   fx += (Cos(t) * r);
  28.   fy += (Sin(t) * r);
  29.   Result.x := Round(SkewedRand(fx, x1+1, x2-1, srl.GAUSS_CUTOFF));
  30.   Result.y := Round(SkewedRand(fy, y1+1, y2-1, srl.GAUSS_CUTOFF));
  31.   Result := RotatePoint(Result, a, (X2+X1)/2+Random()-0.5, (Y2+Y1)/2+Random()-0.5);
  32. end;
  33.  
  34. var
  35.   BMP: TMufasaBitmap;
  36.   P: TPoint;
  37.   R: TRectangle;
  38.   B: TBox;
  39.  
  40. begin
  41.   BMP := GetMufasaBitmap(CreateBitmap(500, 500));
  42.   BMP.Debug();
  43.  
  44.   R := Box(Random(100, 250), Random(100, 250), Random(250, 400), Random(250, 400)).ToRectangle.Rotate(Radians(Random(360)));
  45.  
  46.   while True do
  47.   begin
  48.     P.X := Random(5, 495);
  49.     P.Y := Random(5, 495);
  50.  
  51.     BMP.Clear();
  52.     BMP.DrawRect(R, clOrange);
  53.     BMP.DrawCircle(P, 5, True, clRed);
  54.     for 0 to 1000 do
  55.       with srl.RandomPointEx(P, R) do
  56.       BMP.SetPixel(X, Y, clLime);
  57.     BMP.UpdateDebugImage();
  58.  
  59.     Wait(1000);
  60.   end;
  61. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement