Recursive fill

new topic     » topic index » view thread      » older message » newer message

Here's a recursive fill routine I just came up with.
It's probably not the most efficiant way to do the
job, but I think it's kinda cute.

-- code begins ---

constant adj={{1,0},{0,1},{-1,0},{0,-1}}
        ,scrw = 320 -- Insert screen width here if != 320
        ,scrh = 200 -- Insert screen height here if != 200

procedure fill(sequence pos,object c)
    sequence new
    if atom(c) then
        c={get_pixel(pos),c}
    end if
    pixel(c[2],pos)
    for l=1 to 4 do
        new=pos+adj[l]
        if new[1]>0 and new[1]<scrw and new[2]>0 and new[2]<scrh then
            if get_pixel(new)=c[1] then
                fill(new,c)
            end if
        end if
    end for
end procedure

-- code ends --

Usage : fill(seed point,color)

i.e fill({130,77},5)


It can be sped up a bit by drawing a 1 pixel
wide box around the edge of the screen in an
unused color and removing the "on-screen"
check.

Graeme.

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu