|
|
Written in C# The EXE name should tip you off as to what it does: A
flood fill.
Use the left button to draw a container, use the right button to fill it.
Code... if you could ever be so interested :) Yes, I'm goofing off at
work. :P
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
bg = new Bitmap(400, 400);
Graphics g = Graphics.FromImage(bg);
g.Clear(Color.White);
}
Bitmap bg;
int px, py;
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
FloodFill(e.X, e.Y);
}
px = e.X; py = e.Y;
}
private void FloodFill(int x, int y)
{
Color c = Color.FromArgb(64, 128, 192);
int ox = x;
while(x > 0 && bg.GetPixel(x, y) ==
Color.FromArgb(255,255,255))
{
bg.SetPixel(x, y, c); x--;
}
x = ox+1;
while (x < 400 && bg.GetPixel(x, y) == Color.FromArgb(255,
255, 255))
{
bg.SetPixel(x, y, c); x++;
}
x = ox;
Refresh();
while (x > 0 && bg.GetPixel(x, y) == c)
{
if(y > 0 && bg.GetPixel(x,y-1) ==
Color.FromArgb(255,255,255))
{
FloodFill(x, y-1);
}
if (y < 399 && bg.GetPixel(x, y + 1) ==
Color.FromArgb(255, 255, 255))
{
FloodFill(x, y + 1);
}
x--;
}
x = ox;
while (x < 400 && bg.GetPixel(x, y) == c)
{
if (y > 0 && bg.GetPixel(x, y - 1) ==
Color.FromArgb(255, 255, 255))
{
FloodFill(x, y - 1);
}
if (y < 399 && bg.GetPixel(x, y + 1) ==
Color.FromArgb(255, 255, 255))
{
FloodFill(x, y + 1);
}
x++;
}
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Left)
{
if(px == -1 && py == -1)
{
bg.SetPixel(e.X, e.Y, Color.Black);
px = e.X; py = e.Y;
}
else
{
Graphics g = Graphics.FromImage(bg);
g.DrawLine(Pens.Black, px, py, e.X, e.Y);
px = e.X; py= e.Y;
}
Refresh();
}
}
protected override void OnPaintBackground(PaintEventArgs e)
{
e.Graphics.DrawImage(bg, 0, 0);
}
}
}
--
~Mike
Post a reply to this message
Attachments:
Download 'flood.exe.dat' (9 KB)
|
|