Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void FloodFill(ref Color[] source, Point pt, int width, int height, Color targetColor, Color replacementColor)
- {
- Stack<Point> pixels = new Stack<Point>();
- targetColor = source[P(pt.x, pt.y, width, height)];
- pixels.Push(pt);
- while (pixels.Count > 0)
- {
- Point a = pixels.Pop();
- if (source[P(a.x, a.y, width, height)] == targetColor)
- {
- source[P(a.x, a.y, width, height)] = replacementColor;
- if (a.x > 0)
- pixels.Push(new Point(a.x - 1, a.y));
- if (a.x < width)
- pixels.Push(new Point(a.x + 1, a.y));
- if (a.y > 0)
- pixels.Push(new Point(a.x, a.y - 1));
- if (a.y < height)
- pixels.Push(new Point(a.x, a.y + 1));
- }
- }
- }
- private IEnumerator MainGenerationDebug(Color[] source, Color32[] target, int width, int height)
- {
- // (1)
- for (int i = 0; i < source.Length; Interlocked.Increment(ref i))
- {
- // (2)
- Color c = source[i];
- // (3)
- int x = i % width,
- y = i / width;
- // (4) & (5)
- yield return IntMapIteration(source, target, width, c, i, exceptions, (s, t) =>
- {
- source = s;
- target = t;
- });
- // (6)
- if (c == Color.white)
- {
- F.FloodFill(ref source, new Point(x, y), width, height, Color.white, Color.red);
- }
- }
- }
Add Comment
Please, Sign In to add comment