Liberty BASIC Community Forum
Liberty BASIC Programming Discussions >> Liberty BASIC Code >> Flood filling....

Flood filling....
Post by tenochtitlanuk on Oct 2nd, 2015, 3:51pm

There've been some interesting programs on the JB Forum to produce attractive graphics, and the problems of filling awkward shapes came up.
In LB we can call the API and it is so much easier. This is my example of flood-filling from a stated point out to a stated boundary colour. Draws empty outlines then chooses random points/colours to fill.
User Image


WindowWidth  =500
WindowHeight =500

open "Fill-me" for graphics_nsb as #wg

#wg "trapclose [quit]"

hw =hwnd( #wg)

calldll #user32, "GetDC", hw as ulong, hdc as ulong

for i =1 to 50
    #wg "up ; goto "; -50 +600 *rnd( 1); " "; -50 +600 *rnd( 1); " ; down"
    #wg "circlefilled "; 100 *rnd( 1)
next i

#wg "flush"

notice "Hit <Return> to flood-fill the areas one at a time at 10/second."

for i =1 to 500
    r           =int( 256 *rnd( 1))
    g           =int( 256 *rnd( 1))
    b           =int( 256 *rnd( 1))
    fillCol$    =str$( r) +" " +str$( g); " " +str$( b)
    'longCol     =r +2^8 *g +2^16 *b
    #wg "color "; fillCol$; " ; up ; backcolor "; fillCol$

    xVar            =int( 500 *rnd( 1))
    yVar            =int( 500 *rnd( 1))
    targetcolor     =0  '   this is the colour of the outline to fill out to.

    calldll #gdi32, "ExtFloodFill",_
        hdc                as ulong,_
        xVar               as long,_
        yVar               as long,_
        targetcolor        as long,_
        _FLOODFILLBORDER   as long,_    '   '   ie fill out 'til this colour is met...
        result             as long
        calldll #kernel32, "Sleep", 100 as long, ret as void
next i

#wg "flush ; getbmp scr 0 0 500 500"
bmpsave "scr", "fillDemo.bmp"


    calldll #user32, "ReleaseDC", hw as ulong, hdc as ulong   'release the DC
    close #wg

Re: Flood filling....
Post by tenochtitlanuk on Oct 4th, 2015, 4:25pm

Recent variation- ( refresh to watch the animation again.)
User Image
Explanatory webpage is on line with zipped code and images.