/// <summary> /// Perform a floodfill click at the specified (x,y) pixel coords /// </summary> /// <param name="pxSpriteX">Click x-position (in pixels)</param> /// <param name="pxSpriteY">Click y-position (in pixels)</param> /// <returns>True if the sprite changes as a result of this click, false otherwise.</returns> public bool FloodFillClick(int pxSpriteX, int pxSpriteY) { int colorOld = GetPixel(pxSpriteX, pxSpriteY); int colorNew = Subpalette.CurrentColor; if (colorOld == colorNew) { return(false); } // Stack of pixels to process. Stack <PixelCoord> stackPixels = new Stack <PixelCoord>(); PixelCoord p = new PixelCoord(pxSpriteX, pxSpriteY); stackPixels.Push(p); while (stackPixels.Count != 0) { p = stackPixels.Pop(); SetPixel(p.X, p.Y, colorNew); FloodFill_CheckPixel(p.X - 1, p.Y, colorOld, ref stackPixels); FloodFill_CheckPixel(p.X + 1, p.Y, colorOld, ref stackPixels); FloodFill_CheckPixel(p.X, p.Y - 1, colorOld, ref stackPixels); FloodFill_CheckPixel(p.X, p.Y + 1, colorOld, ref stackPixels); } FlushBitmaps(); return(true); }
/// <summary> /// Convert from maths coordinates to pixel coordinates. /// </summary> /// <param name="cmplxPoint">Complex number (mathematical coordiantes)</param> /// <returns>Pixel coordinate, also a complex number but represented /// as an X,Y screen coordinate</returns> public PixelCoord GetPixelCoord(ComplexPoint cmplxPoint) { PixelCoord result = new PixelCoord(); result.xPixel = (int)(convConstX1 * cmplxPoint.x - convConstX2); result.yPixel = (int)(convConstY1 - convConstY2 * cmplxPoint.y); return(result); }
/// <summary> /// Perform a floodfill click at the specified (x,y) pixel coords /// </summary> /// <param name="pxSpriteX">Click x-position (in pixels)</param> /// <param name="pxSpriteY">Click y-position (in pixels)</param> /// <returns>True if the sprite changes as a result of this click, false otherwise.</returns> public bool FloodFillClick(int pxSpriteX, int pxSpriteY) { int colorOld = GetPixel(pxSpriteX, pxSpriteY); int colorNew = Subpalette.CurrentColor; if (colorOld == colorNew) return false; // Stack of pixels to process. Stack<PixelCoord> stackPixels = new Stack<PixelCoord>(); PixelCoord p = new PixelCoord(pxSpriteX, pxSpriteY); stackPixels.Push(p); while (stackPixels.Count != 0) { p = stackPixels.Pop(); SetPixel(p.X, p.Y, colorNew); FloodFill_CheckPixel(p.X - 1, p.Y, colorOld, ref stackPixels); FloodFill_CheckPixel(p.X + 1, p.Y, colorOld, ref stackPixels); FloodFill_CheckPixel(p.X, p.Y - 1, colorOld, ref stackPixels); FloodFill_CheckPixel(p.X, p.Y + 1, colorOld, ref stackPixels); } FlushBitmaps(); return true; }