
-----------------------------------
moomoocow
Fri Mar 04, 2005 9:58 pm

paint bucket... desparate help
-----------------------------------
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.

-----------------------------------
zylum
Fri Mar 04, 2005 11:11 pm


-----------------------------------
http://www.compsci.ca/v2/viewtopic.php?t=7959

-----------------------------------
moomoocow
Sat Mar 05, 2005 12:17 pm


-----------------------------------
thx, but i saw that thread already. it's different from my problem...

-----------------------------------
Andy
Sat Mar 05, 2005 12:42 pm


-----------------------------------
no it isnt.. do you even know what drawfill does?

-----------------------------------
moomoocow
Sat Mar 05, 2005 1:47 pm


-----------------------------------
yeah, i tried your spray and bucket, they don't work with mine.

-----------------------------------
McKenzie
Sat Mar 05, 2005 3:06 pm


-----------------------------------
OK so as you know drawfill looks like:
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
Sat Mar 05, 2005 6:09 pm


-----------------------------------
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...

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
Sat Mar 05, 2005 6:43 pm


-----------------------------------
When you click on the spot that you want to fill you need to

- 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

-----------------------------------
moomoocow
Sun Mar 06, 2005 11:23 am


-----------------------------------
:(  :(  i'm about to give up. it's too hard, sir, but this is better than last time.
procedure bucket
    var what : int
    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
  what:=  whatdotcolor (x3 + 1, y3 - 1) 
       
                drawfill (89, 14, clur, what)
            exit when bawket=0
        end loop
    end if
end bucket

-----------------------------------
McKenzie
Sun Mar 06, 2005 5:39 pm


-----------------------------------
Don't give up, you'll get it.  Lets focus on the heart of the problem:

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:

startColour 