Sujet : Re: filling area by color atack safety
De : phaywood (at) *nospam* alphalink.com.au (Peter 'Shaggy' Haywood)
Groupes : comp.lang.cDate : 17. Mar 2024, 08:03:57
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <t7hick-t14.ln1@hendrix.foo>
References : 1
User-Agent : KNode/0.10.9
Groovy hepcat fir was jivin' in comp.lang.c on Sat, 16 Mar 2024 03:11
pm. It's a cool scene! Dig it.
i was writing simple editor (something like paint but more custom for
my eventual needs) for big pixel (low resolution) drawing
it showed in a minute i need a click for changing given drawed area of
of one color into another color (becouse if no someone would need to
do
it by hand pixel by pixel and the need to change color of given
element is very common)
Not really a C question, but I'll forgive that for now.
What you're looking for (and can easily find on Google, Duck Duck Go
or any other search engine, if you but utilise any of those services)
is called a "flood fill" algorithm.
But a word of advice: recursion can be tricky if you don't understand
the effect. Your method creates a very large recursive chain. This is
best avoided. Try it out "by hand". Get a piece of graph paper and draw
some shapes on it, including some complex ones. Now choose one of these
shapes and choose a starting pixel within this area and try applying
your algorithm. With a coloured pencil, colour in each square as you
go, just as the algorithm would. Also make note of the level of
recursion as you go. I think you'll be amazed. Repeat for all the
shapes on your graph paper.
-- ----- Dig the NEW and IMPROVED news sig!! ------------------- Shaggy was here! ---------------
Ain't I'm a dawg!!