
-----------------------------------
Unreal_Origin
Tue Nov 02, 2004 4:02 pm

just recustion
-----------------------------------
the is recusion it is in my paint program 


var mx, my, mb : int
var originalcolour : int
var thecolour : int := 4

proc fillingin (x, y, originalcolour, thecolour : int)


    drawdot (x, y, thecolour)
    if whatdotcolor (x + 1, y) = originalcolour then
        fillingin (x + 1, y, originalcolour, thecolour)
    end if
    if whatdotcolor (x, y + 1) = originalcolour then
        fillingin (x, y + 1, originalcolour, thecolour)
    end if
        if whatdotcolor (x, y - 1) = originalcolour then
        fillingin (x, y - 1, originalcolour, thecolour)
    end if
        if whatdotcolor (x-1, y ) = originalcolour then
        fillingin (x-1, y  , originalcolour, thecolour)
    end if
end fillingin

drawoval (255, 255,100, 100,  7)
drawbox (0,0,maxx,maxy,7)

loop
    mousewhere (mx, my, mb)
    if mb = 1 then
        originalcolour := whatdotcolor (mx, my)
        fillingin (mx, my, originalcolour, thecolour)
    end if
end loop




here is the problem i think it is with turing though, it is that it "stake overflow" but w/e (note this happens when you click to fast before it is done)

-----------------------------------
wtd
Tue Nov 02, 2004 6:55 pm


-----------------------------------
The key to recursion is providing a way for your function/procedure to escape the recursion.  At least one branch of that if...elsif...else statement has to do something other than call the function/procedure.

-----------------------------------
Andy
Wed Nov 03, 2004 5:07 pm


-----------------------------------
nah wtd.. it works.. when it finishes drawing, it'll stop cuz every where it checks will return the right color

-----------------------------------
wtd
Wed Nov 03, 2004 7:58 pm


-----------------------------------
No, it really doesn't.  It just keeps running and running, until it overflows the stack.  Try inserting some code after the code originally posted.  The circle will get drawn, and then nothing else will happen, because that procedure is still running.

Every recursive function or procedure has to have a way out.

Consider a basic (very quickly written) factorial function:

function factorial (n : int) : int
    if n 