Janilabo

TPA FloodFill [Simba]

Jul 21st, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 19.74 KB | None | 0 0
  1. // Original algorithms by slacky, optimized by Janilabo
  2.  
  3. const
  4.   POLYGON_EXAMPLE = 1; // 0-9.
  5.   DISPLAY_MAINPOINTS = True; // True or False.
  6.   OFFSET = 5; // Used for debug image..
  7.   FLOODFILL_8WAY = False; // Fills TPA bounds (polygon outlines)
  8.   FLOODFILL_COLOR = 65535; // ..with this color.
  9.  
  10. type
  11.   TFloodFill = (ff4Way, ff8Way);
  12.  
  13. procedure __TPAFloodFill4Way(var store: array of TBoolArray; skip: array of TBoolArray; X, Y, W, H: Integer);
  14. begin
  15.   if ((X > -1) and (Y > -1) and (X < W) and (Y < H)) then
  16.     if not skip[X][Y] then
  17.       if not store[X][Y] then
  18.       begin
  19.         store[X][Y] := True;
  20.         __TPAFloodFill4Way(store, skip, (X - 1), Y, W, H);
  21.         __TPAFloodFill4Way(store, skip, (X + 1), Y, W, H);
  22.         __TPAFloodFill4Way(store, skip, X, (Y - 1), W, H);
  23.         __TPAFloodFill4Way(store, skip, X, (Y + 1), W, H);
  24.       end;
  25. end;
  26.  
  27. procedure __TPAFloodFill8Way(var store: array of TBoolArray; skip: array of TBoolArray; X, Y, W, H: Integer);
  28. begin
  29.   if ((X > -1) and (Y > -1) and (X < W) and (Y < H)) then
  30.     if not skip[X][Y] then
  31.       if not store[X][Y] then
  32.       begin
  33.         store[X][Y] := True;
  34.         __TPAFloodFill8Way(store, skip, (X - 1), Y, W, H);
  35.         __TPAFloodFill8Way(store, skip, (X + 1), Y, W, H);
  36.         __TPAFloodFill8Way(store, skip, X, (Y - 1), W, H);
  37.         __TPAFloodFill8Way(store, skip, X, (Y + 1), W, H);
  38.         __TPAFloodFill8Way(store, skip, (X - 1), (Y - 1), W, H);
  39.         __TPAFloodFill8Way(store, skip, (X + 1), (Y + 1), W, H);
  40.         __TPAFloodFill8Way(store, skip, (X + 1), (Y - 1), W, H);
  41.         __TPAFloodFill8Way(store, skip, (X - 1), (Y + 1), W, H);
  42.       end;
  43. end;
  44.  
  45. procedure TPAFloodFill(var TPA: TPointArray; start: TPoint; method: TFloodFill);
  46. var
  47.   i, l, r, X, Y, W, H: Integer;
  48.   b: TBox;
  49.   store, skip: array of TBoolArray;
  50. begin
  51.   l := Length(TPA);
  52.   if (l > 0) then
  53.   begin
  54.     b := IntToBox(TPA[0].X, TPA[0].Y, TPA[0].X, TPA[0].Y);
  55.     if (l > 1) then
  56.     for i := 1 to (l - 1) do
  57.     begin
  58.       if (TPA[i].X < b.X1) then
  59.         b.X1 := TPA[i].X
  60.       else
  61.         if (TPA[i].X > b.X2) then
  62.           b.X2 := TPA[i].X;
  63.       if (TPA[i].Y < b.Y1) then
  64.         b.Y1 := TPA[i].Y
  65.       else
  66.         if (TPA[i].Y > b.Y2) then
  67.           b.Y2 := TPA[i].Y;
  68.     end;
  69.     if ((start.X >= b.X1) and (start.Y >= b.Y1) and (start.X <= b.X2) and (start.Y <= b.Y2)) then
  70.     begin
  71.       W := ((b.X2 - b.X1) + 1);
  72.       H := ((b.Y2 - b.Y1) + 1);
  73.       SetLength(store, W);
  74.       SetLength(skip, W);
  75.       for i := 0 to (W - 1) do
  76.       begin
  77.         SetLength(skip[i], H);
  78.         SetLength(store[i], H);
  79.       end;
  80.       for i := 0 to (l - 1) do
  81.         skip[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)] := True;
  82.       case method of
  83.         ff4Way: __TPAFloodFill4Way(store, skip, (start.X - b.X1), (start.Y - b.Y1), W, H);
  84.         ff8Way: __TPAFloodFill8Way(store, skip, (start.X - b.X1), (start.Y - b.Y1), W, H);
  85.       end;
  86.       SetLength(skip, 0);
  87.       SetLength(TPA, (W * H));
  88.       for Y := 0 to (H - 1) do
  89.         for X := 0 to (W - 1) do
  90.           if store[X][Y] then
  91.           begin
  92.             TPA[r] := Point((X + b.X1), (Y + b.Y1));
  93.             Inc(r);
  94.           end;
  95.       SetLength(TPA, r);
  96.     end;
  97.   end;
  98. end;
  99.  
  100. procedure TPAFloodFill4Way(var TPA: TPointArray; start: TPoint);
  101. var
  102.   i, l, r, X, Y, W, H: Integer;
  103.   b: TBox;
  104.   store, skip: array of TBoolArray;
  105. begin
  106.   l := Length(TPA);
  107.   if (l > 0) then
  108.   begin
  109.     b := IntToBox(TPA[0].X, TPA[0].Y, TPA[0].X, TPA[0].Y);
  110.     if (l > 1) then
  111.     for i := 1 to (l - 1) do
  112.     begin
  113.       if (TPA[i].X < b.X1) then
  114.         b.X1 := TPA[i].X
  115.       else
  116.         if (TPA[i].X > b.X2) then
  117.           b.X2 := TPA[i].X;
  118.       if (TPA[i].Y < b.Y1) then
  119.         b.Y1 := TPA[i].Y
  120.       else
  121.         if (TPA[i].Y > b.Y2) then
  122.           b.Y2 := TPA[i].Y;
  123.     end;
  124.     if ((start.X >= b.X1) and (start.Y >= b.Y1) and (start.X <= b.X2) and (start.Y <= b.Y2)) then
  125.     begin
  126.       W := ((b.X2 - b.X1) + 1);
  127.       H := ((b.Y2 - b.Y1) + 1);
  128.       SetLength(store, W);
  129.       SetLength(skip, W);
  130.       for i := 0 to (W - 1) do
  131.       begin
  132.         SetLength(skip[i], H);
  133.         SetLength(store[i], H);
  134.       end;
  135.       for i := 0 to (l - 1) do
  136.         skip[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)] := True;
  137.       __TPAFloodFill4Way(store, skip, (start.X - b.X1), (start.Y - b.Y1), W, H);
  138.       SetLength(skip, 0);
  139.       SetLength(TPA, (W * H));
  140.       for Y := 0 to (H - 1) do
  141.         for X := 0 to (W - 1) do
  142.           if store[X][Y] then
  143.           begin
  144.             TPA[r] := Point((X + b.X1), (Y + b.Y1));
  145.             Inc(r);
  146.           end;
  147.       SetLength(TPA, r);
  148.     end;
  149.   end;
  150. end;
  151.  
  152. procedure FloodFillBitmap8WayEx(var bmp: Integer; start: TPoint; oldColor, newColor, tol: Integer);
  153. begin
  154.   try
  155.     if SimilarColors(FastGetPixel(bmp, start.x, start.y), oldColor, tol) then
  156.     begin
  157.       FastSetPixel(bmp, start.x, start.y, newColor);
  158.       FloodFillBitmap8WayEx(bmp, Point((start.x - 1), start.y), oldColor, newColor, tol);
  159.       FloodFillBitmap8WayEx(bmp, Point((start.x + 1), start.y), oldColor, newColor, tol);
  160.       FloodFillBitmap8WayEx(bmp, Point(start.x, (start.y - 1)), oldColor, newColor, tol);
  161.       FloodFillBitmap8WayEx(bmp, Point(start.x, (start.y + 1)), oldColor, newColor, tol);
  162.       FloodFillBitmap8WayEx(bmp, Point((start.x - 1), (start.y - 1)), oldColor, newColor, tol);
  163.       FloodFillBitmap8WayEx(bmp, Point((start.x + 1), (start.y + 1)), oldColor, newColor, tol);
  164.       FloodFillBitmap8WayEx(bmp, Point((start.x + 1), (start.y - 1)), oldColor, newColor, tol);
  165.       FloodFillBitmap8WayEx(bmp, Point((start.x - 1), (start.y + 1)), oldColor, newColor, tol);
  166.     end;
  167.   except
  168.   end;
  169. end;
  170.  
  171. {==============================================================================]
  172.   Explanation: Returns polygon by given outlines (shape)
  173.   NOTE: Original algorithm by slacky (warpie)
  174. [==============================================================================}
  175. function TPAFromPolygon(shape: TPointArray): TPointArray;
  176. var
  177.   b: TBox;
  178.   x, y, h, i, l, r, z: Integer;
  179.   o: TPointArray;
  180.   f: Boolean;
  181.   t: array of TBoolArray;
  182.   e: Extended;
  183.   q, p, d: TPoint;
  184. begin
  185.   h := High(shape);
  186.   if (h > -1) then
  187.   begin
  188.     b := IntToBox(shape[0].X, shape[0].Y, shape[0].X, shape[0].Y);
  189.     for i := 0 to h do
  190.     begin
  191.       q := shape[i];
  192.       if (i < h) then
  193.         p := shape[(i + 1)]
  194.       else
  195.         p := shape[0];
  196.       r := Length(o);
  197.       if ((q.X <> p.X) or (q.Y <> p.Y)) then
  198.       begin
  199.         l := Max(Round(Abs(q.X - p.X)), Round(Abs(q.Y - p.Y)));
  200.         SetLength(o, ((r + l) + 1));
  201.         for z := 0 to l do
  202.           o[(r + z)] := Point((q.X + Round((p.X - q.X) * (z / Extended(l)))), (q.Y + Round((p.Y - q.Y) * (z / Extended(l)))));
  203.       end else
  204.       begin
  205.         SetLength(o, (r + 1));
  206.         o[r] := q;
  207.       end;
  208.       if (shape[i].X < b.X1) then
  209.         b.X1 := shape[i].X
  210.       else
  211.         if (shape[i].X > b.X2) then
  212.           b.X2 := shape[i].X;
  213.       if (shape[i].Y < b.Y1) then
  214.         b.Y1 := shape[i].Y
  215.       else
  216.         if (shape[i].Y > b.Y2) then
  217.           b.Y2 := shape[i].Y;
  218.     end;
  219.     SetLength(t, ((b.X2 - b.X1) + 1));
  220.     for i := 0 to (b.X2 - b.X1) do
  221.       SetLength(t[i], ((b.Y2 - b.Y1) + 1));
  222.     l := Length(o);
  223.     for i := 0 to (l - 1) do
  224.       if not t[(o[i].X - b.X1)][(o[i].Y - b.Y1)] then
  225.         t[(o[i].X - b.X1)][(o[i].Y - b.Y1)] := True;
  226.     SetLength(o, 0);
  227.     for y := 0 to (b.Y2 - b.Y1) do
  228.       for x := 0 to (b.X2 - b.X1) do
  229.       begin
  230.         f := t[x][y];
  231.         if not f then
  232.         begin
  233.           d := Point((x + b.X1), (y + b.Y1));
  234.           q := shape[0];
  235.           for i := 0 to (h + 1) do
  236.           begin
  237.             p := shape[(i mod (h + 1))];
  238.             if (d.Y > Min(q.Y, p.Y)) then
  239.               if (d.Y <= Max(q.Y, p.Y)) then
  240.                 if (d.X <= Max(q.X, p.X)) then
  241.                 begin
  242.                   if (q.y <> p.y) then
  243.                     e := ((d.Y - q.Y) * (p.X - q.X) / Extended((p.Y - q.Y)) + q.X);
  244.                   if ((q.X = p.X) or (d.X < e)) then
  245.                     f := not f;
  246.                 end;
  247.             q := p;
  248.           end;
  249.         end;
  250.         if f then
  251.         begin
  252.           l := Length(Result);
  253.           SetLength(Result, (l + 1));
  254.           Result[l] := Point((x + b.X1), (y + b.Y1));
  255.         end;
  256.       end;
  257.     SetLength(t, 0);
  258.   end else
  259.     SetLength(Result, 0);
  260. end;
  261.  
  262. {==============================================================================]
  263.   Explanation: Given a TPA - this function will connect each point, from first to last.
  264.   NOTE: Original algorithm by slacky (warpie)
  265. [==============================================================================}
  266. function TPAConnect(pts: TPointArray): TPointArray;
  267. var
  268.   i, j, h, l, r, a: Integer;
  269.   q, p: TPoint;
  270. begin
  271.   if (High(pts) > -1) then
  272.   begin
  273.     h := High(pts);
  274.     for i := 0 to h do
  275.     begin
  276.       j := (i + 1);
  277.       if (i = h) then
  278.         j := 0;
  279.       q := pts[i];
  280.       p := pts[j];
  281.       r := Length(Result);
  282.       if ((q.X <> p.X) or (q.Y <> p.Y)) then
  283.       begin
  284.         l := Max(Round(Abs(q.X - p.X)), Round(Abs(q.Y - p.Y)));
  285.         SetLength(Result, ((r + l) + 1));
  286.         for a := 0 to l do
  287.           Result[(r + a)] := Point((q.X + Round((p.X - q.X) * (a / Extended(l)))), (q.Y + Round((p.Y - q.Y) * (a / Extended(l)))));
  288.       end else
  289.       begin
  290.         SetLength(Result, (r + 1));
  291.         Result[r] := q;
  292.       end;
  293.     end;
  294.   end else
  295.     SetLength(Result, 0);
  296. end;
  297.  
  298. {==============================================================================]
  299.   Explanation: Check if a point is within a polygon/shape by the given outline points (shape)
  300.                The points MUST be in order, as if you would draw a line trough each point.
  301.   NOTE: Original algorithm by slacky (warpie)
  302. [==============================================================================}
  303. function InPolygon(pt: TPoint; shape: TPointArray): Boolean;
  304. var
  305.   b: TBox;
  306.   x, y, h, i, v, l, r, z: Integer;
  307.   o: TPointArray;
  308.   f: Boolean;
  309.   t: array of TBoolArray;
  310.   e: Extended;
  311.   q, p, d: TPoint;
  312. begin
  313.   h := High(shape);
  314.   Result := False;
  315.   if (h > -1) then
  316.   begin
  317.     b := IntToBox(shape[0].X, shape[0].Y, shape[0].X, shape[0].Y);
  318.     for i := 0 to h do
  319.     begin
  320.       if (shape[i].X < b.X1) then
  321.         b.X1 := shape[i].X
  322.       else
  323.         if (shape[i].X > b.X2) then
  324.           b.X2 := shape[i].X;
  325.       if (shape[i].Y < b.Y1) then
  326.         b.Y1 := shape[i].Y
  327.       else
  328.         if (shape[i].Y > b.Y2) then
  329.           b.Y2 := shape[i].Y;
  330.     end;
  331.     if ((pt.X >= b.X1) and (pt.Y >= b.Y1) and (pt.X <= b.X2) and (pt.Y <= b.Y2)) then
  332.     begin
  333.       SetLength(t, ((b.X2 - b.X1) + 1));
  334.       for i := 0 to (b.X2 - b.X1) do
  335.         SetLength(t[i], ((b.Y2 - b.Y1) + 1));
  336.       for i := 0 to h do
  337.       begin
  338.         v := (i + 1);
  339.         if (i = h) then
  340.           v := 0;
  341.         q := shape[i];
  342.         p := shape[v];
  343.         r := Length(o);
  344.         if ((q.X <> p.X) or (q.Y <> p.Y)) then
  345.         begin
  346.           l := Max(Round(Abs(q.X - p.X)), Round(Abs(q.Y - p.Y)));
  347.           SetLength(o, ((r + l) + 1));
  348.           for z := 0 to l do
  349.             o[(r + z)] := Point((q.X + Round((p.X - q.X) * (z / Extended(l)))), (q.Y + Round((p.Y - q.Y) * (z / Extended(l)))));
  350.         end else
  351.         begin
  352.           SetLength(o, (r + 1));
  353.           o[r] := q;
  354.         end;
  355.       end;
  356.       l := Length(o);
  357.       for i := 0 to (l - 1) do
  358.         if not t[(o[i].X - b.X1)][(o[i].Y - b.Y1)] then
  359.            t[(o[i].X - b.X1)][(o[i].Y - b.Y1)] := True;
  360.       for y := 0 to (b.Y2 - b.Y1) do
  361.       begin
  362.         for x := 0 to (b.X2 - b.X1) do
  363.         begin
  364.           f := t[x][y];
  365.           if not f then
  366.           begin
  367.             d := Point((x + b.X1), (y + b.Y1));
  368.             q := shape[0];
  369.             for i := 0 to (h + 1) do
  370.             begin
  371.               p := shape[(i mod (h + 1))];
  372.               if (d.Y > Min(q.Y, p.Y)) then
  373.                 if (d.Y <= Max(q.Y, p.Y)) then
  374.                   if (d.X <= Max(q.X, p.X)) then
  375.                   begin
  376.                     if (q.y <> p.y) then
  377.                       e := ((d.Y - q.Y) * (p.X - q.X) / Extended((p.Y - q.Y)) + q.X);
  378.                     if ((q.X = p.X) or (d.X < e)) then
  379.                       f := not f;
  380.                   end;
  381.               q := p;
  382.             end;
  383.           end;
  384.           if f then
  385.           begin
  386.             t[x][y] := True;
  387.             Result := t[(pt.X - b.X1)][(pt.Y - b.Y1)];
  388.           end;
  389.         end;
  390.         if Result then
  391.           Break;
  392.       end;
  393.       SetLength(t, 0);
  394.     end;
  395.   end;
  396. end;
  397.  
  398. {==============================================================================]
  399.   Explanation: Creates all the points needed to define a simple polygon
  400.   NOTE: Original algorithm by slacky (warpie)
  401. [==============================================================================}
  402. function TPAXagon(sides: Integer; C, S: TPoint): TPointArray;
  403. var
  404.   x, y, a, b, v: Integer;
  405.   n, m: Extended;
  406. begin
  407.   if (sides > 2) then
  408.   begin
  409.     SetLength(Result, sides);
  410.     x := S.x;
  411.     y := S.y;
  412.     n := Sin(Radians(360.0 / sides));
  413.     m := Cos(Radians(360.0 / sides));
  414.     for v := 0 to (sides - 1) do
  415.     begin
  416.       a := (x - C.x);
  417.       b := (y - C.y);
  418.       x := Round(((b * n) + (a * m) + C.x));
  419.       y := Round(((b * m) - (a * n) + C.y));
  420.       Result[v] := Point(x, y);
  421.     end;
  422.   end else
  423.     SetLength(Result, 0);
  424. end;
  425.  
  426. //******* DIRTY EXAMPLE BELLOW: *******//
  427. procedure SetPixels(bmp: Integer; TPA: TPointArray; color: Integer);
  428. var
  429.   a, z, w, h: Integer;
  430. begin
  431.   z := High(TPA);
  432.   if (z > -1) then
  433.   begin
  434.     GetBitmapSize(bmp, w, h);
  435.     for a := 0 to z do
  436.       if ((TPA[a].X >= 0) and (TPA[a].Y >= 0) and (TPA[a].X < w) and (TPA[a].Y < h)) then
  437.         FastSetPixel(bmp, TPA[a].X, TPA[a].Y, color);
  438.   end;
  439. end;
  440.  
  441. procedure SetPixelsMP(bmp: Integer; TPA: TPointArray; color: Integer);
  442. var
  443.   a, z, w, h: Integer;
  444. begin
  445.   z := High(TPA);
  446.   if (z > -1) then
  447.   begin
  448.     GetBitmapSize(bmp, w, h);
  449.     for a := 0 to z do
  450.       if ((TPA[a].X > 0) and (TPA[a].Y > 0) and (TPA[a].X < (w - 1)) and (TPA[a].Y < (h - 1))) then
  451.       begin
  452.         FastSetPixel(bmp, (TPA[a].X - 1), TPA[a].Y, color);
  453.         FastSetPixel(bmp, (TPA[a].X + 1), TPA[a].Y, color);
  454.         FastSetPixel(bmp, TPA[a].X, (TPA[a].Y + 1), color);
  455.         FastSetPixel(bmp, TPA[a].X, (TPA[a].Y - 1), color);
  456.       end;
  457.   end;
  458. end;
  459.  
  460. function GetPixels(bmp: Integer; TPA: TPointArray): TIntegerArray;
  461. var
  462.   w, h, i, l: Integer;
  463. begin
  464.   l := Length(TPA);
  465.   try
  466.     GetBitmapSize(bmp, w, h);
  467.   except
  468.   end;
  469.   SetLength(Result, l);
  470.   for i := 0 to (l - 1) do
  471.     if ((TPA[i].X > -1) and (TPA[i].Y > -1) and (TPA[i].X < w) and (TPA[i].Y < h)) then
  472.       Result[i] := FastGetPixel(bmp, TPA[i].X, TPA[i].Y)
  473.     else
  474.       Result[i] := -1;
  475. end;
  476.  
  477. function GetBitmapColorTPA(bmp: Integer; color: Integer): TPointArray;
  478. var
  479.   w, h, x, y, r: Integer;
  480. begin
  481.   try
  482.     GetBitmapSize(bmp, w, h);
  483.   except
  484.   end;
  485.   if ((w > 0) and (h > 0)) then
  486.   begin
  487.     SetLength(Result, (w * h));
  488.     for y := 0 to (h - 1) do
  489.       for x := 0 to (w - 1) do
  490.         if (FastGetPixel(bmp, x, y) = color) then
  491.         begin
  492.           Result[r] := Point(x, y);
  493.           Inc(r);
  494.         end;
  495.   end;
  496.   SetLength(Result, r);
  497. end;
  498.  
  499. {==============================================================================]
  500.   Explanation: Replaces TPA with all the edge-points from TPA.
  501.                Edge-points are points that are on the edge of the TPA, not completely surrounded by other points.
  502. [==============================================================================}
  503. procedure TPAEdge(var TPA: TPointArray);
  504. var
  505.   v, x, y, h, r: Integer;
  506.   B: array of TBoolArray;
  507.   bx: TBox;
  508. begin;
  509.   h := High(TPA);
  510.   if (h > 3) then
  511.   begin
  512.     bx := IntToBox(TPA[0].X, TPA[0].Y, TPA[0].X, TPA[0].Y);
  513.     for v := 1 to h do
  514.     begin
  515.       if (TPA[v].X < bx.X1) then
  516.         bx.X1 := TPA[v].X
  517.       else
  518.         if (TPA[v].X > bx.X2) then
  519.           bx.X2 := TPA[v].X;
  520.       if (TPA[v].Y < bx.Y1) then
  521.         bx.Y1 := TPA[v].Y
  522.       else
  523.         if (TPA[v].Y > bx.Y2) then
  524.           bx.Y2 := TPA[v].Y;
  525.     end;
  526.     bx := IntToBox((bx.X1 - 1), (bx.Y1 - 1), (bx.X2 + 1), (bx.Y2 + 1));
  527.     SetLength(B, ((bx.X2 - bx.X1) + 1));
  528.     for v := 0 to (bx.X2 - bx.X1) do
  529.       SetLength(B[v], ((bx.Y2 - bx.Y1) + 1));
  530.     for v := 0 to h do
  531.       if not B[(TPA[v].X - bx.X1)][(TPA[v].Y - bx.Y1)] then
  532.         B[(TPA[v].X - bx.X1)][(TPA[v].Y - bx.Y1)] := True;
  533.     for y := 1 to ((bx.Y2 - bx.Y1) - 1) do
  534.       for x := 1 to ((bx.X2 - bx.X1) - 1) do
  535.         if B[x][y] then
  536.           if not (B[(x - 1)][y] and B[x][(y - 1)] and B[(x + 1)][y] and B[x][(y + 1)]) then
  537.           begin
  538.             TPA[r].X := (x + bx.X1);
  539.             TPA[r].Y := (y + bx.Y1);
  540.             Inc(r);
  541.           end;
  542.     SetLength(TPA, r);
  543.     SetLength(B, 0);
  544.   end;
  545. end;
  546.  
  547. procedure Setup;
  548. var
  549.   shape, TPA: TPointArray;
  550.   bmp, t, o: Integer;
  551.   v: Boolean;
  552.   a: TBox;
  553. begin
  554.   //Dynamic shapes from Example 6 and down:
  555.   v := True;
  556.   case POLYGON_EXAMPLE of
  557.     // Microshape ------//
  558.     //           TOP           LEFT           BOTTOM          RIGHT
  559.     0: shape := [Point(20,20), Point(20,120), Point(120,120), Point(120,20)];
  560.     // Arrow like shape //
  561.     1: shape := [Point(70,90),Point(185,90),Point(185,116), Point(70,116), //Square +
  562.                  Point(70,140),Point(35,105),Point(70,70)];                //Triangle
  563.     // Triangle --------//
  564.     2: shape := [Point(50,50),Point(0,100),Point(100,150)];
  565.     // Raped pentagon --//
  566.     3: shape := [Point(10,25),Point(35,5),Point(82,22),Point(50,90),Point(4,60)];
  567.     // Octagon ---------//
  568.     4: shape := [Point(100,30), Point(155,50),  //Top-Right
  569.                  Point(180,110),Point(155,160), //Right-Bottom
  570.                  Point(100,180),Point(45,160),  //Bottom-Left
  571.                  Point(20,100), Point(45,50)];  //Left-Top
  572.     // S-shape ---------//
  573.     5: shape := [Point(135,50),Point(123,70),Point(103,58),Point(85,70),Point(85,85),
  574.                  Point(122,105),Point(132,125),Point(120,155),Point(78,164),Point(55,147),
  575.                  Point(64,128),Point(80,140),Point(100,140),Point(96,116),Point(62,98),
  576.                  Point(60,55),Point(111,35)];
  577.     // Xagon: 15 corners //
  578.     6: shape := TPAXagon(15, Point(100,100), Point(60,100));
  579.     // Xagon: 9 corners //
  580.     7: shape := TPAXagon(9, Point(100,100), Point(60,50));
  581.     // Xagon: 5 corners AKA Pentagon //
  582.     8: shape := TPAXagon(5, Point(100,100), Point(74,50));
  583.     // Xagon: 3 corners AKA Triangle //
  584.     9: shape := TPAXagon(3, Point(100,100), Point(48,48));
  585.   else
  586.     v := False;
  587.   end;
  588.   if v then
  589.   begin
  590.     if ((a.X1 > -1) and (a.Y1 > -1)) then
  591.     begin
  592.       if (OFFSET > 0) then
  593.         o := OFFSET;
  594.       t := GetSystemTime;
  595.       if (o > 0) then
  596.         OffsetTPA(shape, Point(o, o));
  597.       TPA := TPAFromPolygon(shape);
  598.       WriteLn('Polygon created in ' + IntToStr(GetSystemTime - t) + ' ms.');
  599.       a := GetTPABounds(TPA);
  600.       bmp := CreateBitmap((a.X2 + o), (a.Y2 + o));
  601.       TPAEdge(TPA);
  602.       t := GetSystemTime;
  603.       if FLOODFILL_8WAY then
  604.         TPAFloodFill(TPA, MiddleTPA(TPA), ff8Way)
  605.       else
  606.         TPAFloodFill(TPA, MiddleTPA(TPA), ff4Way);
  607.       WriteLn('Polygon area floodfilled in ' + IntToStr(GetSystemTime - t) + ' ms.');
  608.       SetPixels(bmp, TPA, FLOODFILL_COLOR);
  609.       if DISPLAY_MAINPOINTS then
  610.         SetPixelsMP(bmp, shape, 16777215);
  611.       DisplayDebugImgWindow((a.X2 + a.X1), (a.Y2 + a.Y1));
  612.       DrawBitmapDebugImg(bmp);
  613.       FreeBitmap(bmp);
  614.       SetLength(TPA, 0);
  615.     end else
  616.       WriteLn('Invalid TPA! Negative points found...');
  617.   end else
  618.     WriteLn('Invalid polygon ID!');
  619. end;
  620.  
  621. begin
  622.   Setup;
  623. end.
Advertisement
Add Comment
Please, Sign In to add comment