
-----------------------------------
Dude_man_47
Fri Dec 01, 2006 6:34 pm

Paint bucket
-----------------------------------
Hey,

I was wondering if anyone could help me. I have a paint bucket function (fill) 
for my paint project. It seems to get the job done, but it also laggs (maybe it's just my comp) but it almost looks like there is a delay on it.
 I was wondering if there was a more affeicient way of doing it so that it would run a little faster. I'd apreciate any help,

Dude_man_47 


proc fill (x, y, s, f : int)
    Draw.Dot (x, y, f)
    if whatdotcolor (x + 1, y) = s then
        fill (x + 1, y, s, f)
    end if
    if whatdotcolor (x, y + 1) = s then
        fill (x, y + 1, s, f)
    end if
    if whatdotcolor (x, y - 1) = s then
        fill (x, y - 1, s, f)
    end if
    if whatdotcolor (x - 1, y) = s then
        fill (x - 1, y, s, f)
    end if
end fill


Draw.Box (100, 100, 200, 200, black)
fill (150, 150, white, black)


-----------------------------------
uberwalla
Fri Dec 01, 2006 6:39 pm


-----------------------------------
i think if u are asking for help you should go and post in the turing help forum. anyways i do not know whatdotcolor all that well but as i look at it it looks efficient. works smoothly too. good job.

-----------------------------------
Dude_man_47
Fri Dec 01, 2006 7:14 pm


-----------------------------------
Sorry about posting in the wrong section I should've posted in Help so, "my bad", I wasnt looking. 

Neways, it should run smoothly but sometimes I find you get stack overflows 
if you click in certain places while trying to fill the screen. Yet again and replies would be greatly apreciated.

~Dude_Man_47

-----------------------------------
zylum
Fri Dec 01, 2006 8:03 pm


-----------------------------------
stack overflow occures on larger fills because you run out of memory. everytime you call the function recursively, it has to remember the state of the current function call so that when the new function call returns, the program can continue where it left off. 

the type of recursion you are using is depthe first search or DFS which (as the name implies) goes as deep as it can in its recursion. to overcome this you can try using breadth first search or DFS. i think its covered in my recursion tutorial.

also you can shorten your code a bit.

proc fill (x, y, s, f, d : int)
    if (whatdotcolor (x, y) ~= s or x < 1 or x > maxx or y < 1 or y > maxy) then
        return
    end if

    Draw.Dot (x, y, f)
    fill (x + 1, y, s, f, d + 1)
    fill (x, y + 1, s, f, d + 1)
    fill (x, y - 1, s, f, d + 1)
    fill (x - 1, y, s, f, d + 1)
end fill

your code also lacked the condition that the drawing must remain on  the screen.

-----------------------------------
lilmizeminem
Wed Apr 25, 2007 10:30 am

RE:Paint bucket
-----------------------------------
i dont like this.

-----------------------------------
rollerdude
Wed Apr 25, 2007 1:04 pm

Re: Paint bucket
-----------------------------------
i cant really help, but for "those who have replied b4", this is the help forum...

-----------------------------------
ericfourfour
Wed Apr 25, 2007 7:45 pm

Re: Paint bucket
-----------------------------------
i cant really help, but for "those who have replied b4", this is the help forum...

"i cant really help" either

The moderators of this forum have the ability to move topics. Most likely, this topic was in another thread and was moved. That is why this is in the help forum.
