Guest User

Untitled

a guest
Oct 17th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. public static void FloodFill(ref Color[] source, Point pt, int width, int height, Color targetColor, Color replacementColor)
  2. {
  3. Stack<Point> pixels = new Stack<Point>();
  4.  
  5. targetColor = source[P(pt.x, pt.y, width, height)];
  6. pixels.Push(pt);
  7.  
  8. while (pixels.Count > 0)
  9. {
  10. Point a = pixels.Pop();
  11.  
  12. if (source[P(a.x, a.y, width, height)] == targetColor)
  13. {
  14. source[P(a.x, a.y, width, height)] = replacementColor;
  15.  
  16. if (a.x > 0)
  17. pixels.Push(new Point(a.x - 1, a.y));
  18.  
  19. if (a.x < width)
  20. pixels.Push(new Point(a.x + 1, a.y));
  21.  
  22. if (a.y > 0)
  23. pixels.Push(new Point(a.x, a.y - 1));
  24.  
  25. if (a.y < height)
  26. pixels.Push(new Point(a.x, a.y + 1));
  27. }
  28. }
  29. }
  30.  
  31. private IEnumerator MainGenerationDebug(Color[] source, Color32[] target, int width, int height)
  32. {
  33. // (1)
  34. for (int i = 0; i < source.Length; Interlocked.Increment(ref i))
  35. {
  36. // (2)
  37. Color c = source[i];
  38.  
  39. // (3)
  40. int x = i % width,
  41. y = i / width;
  42.  
  43. // (4) & (5)
  44. yield return IntMapIteration(source, target, width, c, i, exceptions, (s, t) =>
  45. {
  46. source = s;
  47. target = t;
  48. });
  49.  
  50. // (6)
  51. if (c == Color.white)
  52. {
  53. F.FloodFill(ref source, new Point(x, y), width, height, Color.white, Color.red);
  54. }
  55. }
  56. }
Add Comment
Please, Sign In to add comment