POV-Ray : Newsgroups : povray.off-topic : Terminal Boredom ... Server Time
31 Oct 2024 23:15:16 EDT (-0400)
  Terminal Boredom ... (Message 1 to 3 of 3)  
From: Mike Raiford
Subject: Terminal Boredom ...
Date: 13 Feb 2009 16:37:48
Message: <4995e82c@news.povray.org>


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)

From: scott
Subject: Re: Terminal Boredom ...
Date: 16 Feb 2009 02:53:08
Message: <49991b64@news.povray.org>

>
> 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.

It crashes if you draw a shape that is too complicated :-)


Post a reply to this message

From: Mike Raiford
Subject: Re: Terminal Boredom ...
Date: 16 Feb 2009 08:16:12
Message: <4999671c$1@news.povray.org>
scott wrote:

> 
> It crashes if you draw a shape that is too complicated :-)
> 

Hmm, let me guess ... Stack overflow? :)Yeah, it'll do that...



-- 
~Mike


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.