Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Paint bucket
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Dude_man_47




PostPosted: Fri Dec 01, 2006 6:34 pm   Post subject: 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

code:

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)
Sponsor
Sponsor
Sponsor
sponsor
uberwalla




PostPosted: Fri Dec 01, 2006 6:39 pm   Post subject: (No subject)

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




PostPosted: Fri Dec 01, 2006 7:14 pm   Post subject: (No subject)

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




PostPosted: Fri Dec 01, 2006 8:03 pm   Post subject: (No subject)

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.

code:
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




PostPosted: Wed Apr 25, 2007 10:30 am   Post subject: RE:Paint bucket

i dont like this.
rollerdude




PostPosted: Wed Apr 25, 2007 1:04 pm   Post subject: Re: Paint bucket

i cant really help, but for "those who have replied b4", this is the help forum...
ericfourfour




PostPosted: Wed Apr 25, 2007 7:45 pm   Post subject: Re: Paint bucket

rollerdude @ Wed Apr 25, 2007 1:04 pm wrote:
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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: