paint bucket... desparate help
Author |
Message |
moomoocow
|
Posted: Fri Mar 04, 2005 9:58 pm Post subject: paint bucket... desparate help |
|
|
code: | procedure bucket
loop
Mouse.Where (x, y, draw)
if tool = "bucket" and draw = 1 and x > 120 and x < 605 and
y > 30 and y < 385
then
drawfill (x, y, 8, clur)
end if
exit when draw=0
end loop
end bucket |
how do I get the flood fill to change colour? right now it only works as grey and also if there's nothing on the screen, it covers the complete screen. help plz, thx a lot. btw, the topic below mine also about the bucket, is kinda different and the code's rilly confusing so that's why i made a new topic. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
zylum
|
|
|
|
|
moomoocow
|
Posted: Sat Mar 05, 2005 12:17 pm Post subject: (No subject) |
|
|
thx, but i saw that thread already. it's different from my problem... |
|
|
|
|
|
Andy
|
Posted: Sat Mar 05, 2005 12:42 pm Post subject: (No subject) |
|
|
no it isnt.. do you even know what drawfill does? |
|
|
|
|
|
moomoocow
|
Posted: Sat Mar 05, 2005 1:47 pm Post subject: (No subject) |
|
|
yeah, i tried your spray and bucket, they don't work with mine. |
|
|
|
|
|
McKenzie
|
Posted: Sat Mar 05, 2005 3:06 pm Post subject: (No subject) |
|
|
OK so as you know drawfill looks like:
code: | drawfill (x, y : int, fillColor, borderColor : int) |
so you have to accept that if you are going to use drawfill to do your paint bucket that it MUST be outlined all in the same colour (borderColor.) By your code it looks like you have them backwards. It looks like you want to fill in colour "clur". So put that as your fillColor. From here you need to figure out what your fill colour is. I would suggest that you use whatdotcolour to check the colour of the pixel where you want to start doing the fill then run a loop to check each pixel to the left (right,up, down, doesn't matter) until you find a pixel of a different colour. That different colour is your fillColour.
Andy is right, the flood fill allows you to fill an area that is bounded by different colours, but I like the solution I outlined because its easier to get your head around it without needing a solid understanding of recursion. |
|
|
|
|
|
moomoocow
|
Posted: Sat Mar 05, 2005 6:09 pm Post subject: (No subject) |
|
|
ok i fixed the first part, like when it was all grey. thx a lot, but i really don't get how to do the whatdotcolor part...
code: | procedure bucket
loop
Mouse.Where (x3, y3, bawket)
if tool = "bucket" and bawket = 1 and x3 > 120 and x3 < 605 and
y3 > 30 and y3 < 385
then
loop
if whatdotcolor (x3, y3) = clur
then
drawfill (89, 14, clur, clur)
end if
end loop
end if
exit when bawket = 0
end loop
end bucket |
|
|
|
|
|
|
McKenzie
|
Posted: Sat Mar 05, 2005 6:43 pm Post subject: (No subject) |
|
|
When you click on the spot that you want to fill you need to
code: |
- remember the colour where you clicked
- check each pixel one at a time in one direction until you find one of a different colour. (you'll need a loop and a new variable to keep track of the new x positions that you are looking at)
- do your fill |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
moomoocow
|
|
|
|
|
McKenzie
|
Posted: Sun Mar 06, 2005 5:39 pm Post subject: (No subject) |
|
|
Don't give up, you'll get it. Lets focus on the heart of the problem:
code: | if tool = "bucket" and bawket = 1 and x3 > 120 and x3 < 605 and
y3 > 30 and y3 < 385 then
loop
what := whatdotcolor (x3 + 1, y3 - 1)
drawfill (89, 14, clur, what)
exit when bawket = 0
end loop
end if |
Your if checks if the bucket is selected and you are in clicking inside your drawing canvas. In pseudocode here is what you need to find the bounding colour:
code: |
startColour <- whatdotcolour(x,y)
dx <- 1
loop
checkColour <- whatdotcolour(x + dx,y)
exit when checkColour not= startColour
dx <- dx+1
end loop |
|
|
|
|
|
|
|
|