1 Attachment(s)
Coloring algorithm FloodFill
I write Coloring algorithm FloodFill and that ok's, it's work. I can description it: choose a new point X in your drawings, ex: g.drawrectangle(new pen(Color.Blue), 100,100,200,50) , Asolute, a point X can be: (120,120) or more, more, etc...In addition choose a color you want paint( i choose Violet) and Color of Rectangle'Line: Blue, after all, it will spreading 4 directions and top where's color of line(Blue) So, like:
Attachment 30201
and code:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace FloodFill
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Bitmap bm;
Graphics g;
private bool SameColor(Color c1, Color c2)
{
return ((c1.A == c2.A) && (c1.B == c2.B) && (c1.G == c2.G) && (c1.R == c2.R));
}
private void tobien1(Bitmap bm, Point p, Color Color, Color LineColor)
{
Stack<Point> S = new Stack<Point>();
S.Push(p);
while (S.Count != 0)
{
p = S.Pop();
Color CurrentColor = bm.GetPixel(p.X, p.Y);
if (!SameColor(CurrentColor, Color) && !SameColor(CurrentColor, LineColor))
{
bm.SetPixel(p.X, p.Y, Color);
S.Push(new Point(p.X - 1, p.Y));
S.Push(new Point(p.X + 1, p.Y));
S.Push(new Point(p.X, p.Y - 1));
S.Push(new Point(p.X, p.Y + 1));
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
g = this.CreateGraphics();
}
private void DrawRectangle(Bitmap bm, Point p, int width, int height, Color c)
{
Graphics g = Graphics.FromImage(bm);
g.DrawRectangle(new Pen(c), p.X, p.Y, width, height);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
bm = new Bitmap(ClientSize.Width, ClientSize.Height);
DrawRectangle(bm, new Point(100,100), 200, 50, Color.Blue);
g.DrawImage(bm, new Point(0, 0));
}
private void button1_Click(object sender, EventArgs e)
{
tobien1(bm, new Point(120,120), Color.Violet, Color.Blue);
g.DrawImage(bm, new Point(0, 0));
}
}
}
It's work, Ok? Now, i want: how can make it slowly, slowy process of spreading 4 directions, my mean: when you press F5 to build, and all what you see: it finished. So, can be make it slowly, slowly??? can be? I want to see spreading 4 directions slow and how it' work. Can you understand and help me? Thanks.
1 Attachment(s)
Re: Coloring algorithm FloodFill
Re: Coloring algorithm FloodFill
IMHO, that is precisely how a FloodFill should actually work. I've created something similar in VB.NET a long time ago :
Creating Your Own Drawing Application with Visual Basic .NET, Part 1
http://www.codeguru.com/csharp/.net/...le.php/c13205/
Creating Your Own Drawing Application with Visual Basic.NET, Part 2
http://www.codeguru.com/csharp/.net/...le.php/c13207/
Creating Your Own Drawing Application in Visual Basic.NET, Part 3
http://www.codeguru.com/vb/gen/vb_gr...le.php/c13611/
Creating Your Own Drawing Application in Visual Basic.NET, Part 4
http://www.codeguru.com/vb/gen/vb_gr...cle.php/c14007
I also do have a lot of experience in Graphic Design software, and all of them ( CorelDraw, Flash, PhotoShop, Fireworks etc. ) works the same way.
You can perhaps add a timer and do it from there, but I reaqlly do not see any need. Just my opinion... ;)
Re: Coloring algorithm FloodFill
Thanks for care, but my problem still not solved, :sick:
Re: Coloring algorithm FloodFill
It seems like you haven't read my previous post properly. Read again. FloodFilling an area means filling that area at once, hence its name. Look at its definition(s) :
http://en.wikipedia.org/wiki/Flood_fill
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
What you want to do, is not a FloodFill par se, it will end up being some sort of animation - which is totally unecessary IMHO, and it will waste a lot of resources unecessarily.
If you want to waste resources, time, and uneceaasry logic, fine, go ahead add a timer - bun't don't say I didn't warn you of the consequences....
1 Attachment(s)
Re: Coloring algorithm FloodFill
Quote:
Originally Posted by
HanneSThEGreaT
It seems like you haven't read my previous post properly. Read again. FloodFilling an area means filling that area at once, hence its name. Look at its definition(s) :
http://en.wikipedia.org/wiki/Flood_fill
http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx
What you want to do, is not a FloodFill par se, it will end up being some sort of animation - which is totally unecessary IMHO, and it will waste a lot of resources unecessarily.
If you want to waste resources, time, and uneceaasry logic, fine, go ahead add a timer - bun't don't say I didn't warn you of the consequences....
Yeah, that's right, i want it like same:
Attachment 30205
I want my rectangle is painted like this picture, add timer? Yes, i think it, and try, but not result well, maybe i code wrong, can you?
Re: Coloring algorithm FloodFill
Loosexll, if I understood you well, you just want to slow down the program so that you can actually watch the algorithm working in real time, slow enough for the human eye to follow, so that you can track it and visually understand how it works, and visually check for errors? Correct?
If so, you need to structure your program differently, and establish a render loop - but I'll wait for your answer before I give you any advice, because that would require to restructure your program.
Re: Coloring algorithm FloodFill
Quote:
Originally Posted by
TheGreatCthulhu
Loosexll, if I understood you well, you just want to slow down the program so that you can actually watch the algorithm working in real time, slow enough for the human eye to follow, so that you can track it and visually understand how it works, and visually check for errors? Correct?
If so, you need to structure your program differently, and establish a render loop - but I'll wait for your answer before I give you any advice, because that would require to restructure your program.
And now, i'm still stuck, >"<
Re: Coloring algorithm FloodFill
Oh, help....now, i haven't got it, >"<