Colour Flood Filling- Xmas Tree

I fancied doing an animated graphic Christmas tree. It's easy to draw circles and rectangles filled with colour, but I wanted to fill irregular shapes. The baubles here are therefore a bad example- a better one would use say candle-shaped lights.

To run the code you need this bmp saved in the same directory as the LB code. If you draw your own black-outline drawing of enclosed shapes, you'll need to find the x,y coordinates of the centre from which to fill them.

The result should be a display of animated lights. Try other colour sequences, timings, etc.


Code

    global wg, hdc

    dim b( 30, 2), c$( 13)

    b(  1, 1)   = 86: b(  1, 2)  =437
    b(  2, 1)   =138: b(  2, 2)  =380
    b(  3, 1)   =200: b(  3, 2)  =394
    b(  4, 1)   =307: b(  4, 2)  =425
    b(  5, 1)   =303: b(  5, 2)  =369
    b(  6, 1)   =275: b(  6, 2)  =318
    b(  7, 1)   =202: b(  7, 2)  =306
    b(  8, 1)   =147: b(  8, 2)  =289
    b(  9, 1)   =256: b(  9, 2)  =243
    b( 10, 1)   =187: b( 10, 2)  =179
    b( 11, 1)   =238: b( 11, 2)  =137
    b( 12, 1)   =224: b( 12, 2)  = 92
    b( 13, 1)   =232: b( 13, 2)  = 38

    c$(  1) ="255  72   0"
    c$(  2) ="255 156   0"
    c$(  3) ="255 255   0"
    c$(  4) =" 72 255   0"
    c$(  5) ="  0 255 234"
    c$(  6) ="  0 250 255"
    c$(  7) ="  0  42 255"
    c$(  8) ="222   0 255"
    c$(  9) ="230 211 237"
    c$( 10) ="242 253 120"
    c$( 11) ="250 251 160"
    c$( 12) ="252 253 200"
    c$( 13) ="255 255 255"


    WindowWidth  =455
    WindowHeight =600

    nomainwin

    open "Xmas Tree" for graphics_nsb as #wg

    hw      =hwnd( #wg)
    calldll #user32, "GetDC", hw as ulong, hdc as ulong

    #wg "trapclose quit"

    loadbmp "scr", "xmasTreeColoured.bmp"

    #wg "down ; drawbmp scr 1 1 ; flush ; size 12"

    n =0

    for k =1 to 200
        for j =1 to 13
            call bauble b(  j, 1), b(  j, 2), c$( 1 +( n +j) mod 12)
            n =n +1
        next j
    next k

    wait

    sub bauble x, y, col$
        #wg "backcolor "; col$             '   this  is colour to fill WITH
        #wg "color ";     col$

        targetcolor   =0 +0 *2^8 +0 *2^16  '   black is colour to fill out TO

        calldll #gdi32, "ExtFloodFill", hdc as ulong,_
            x                  as  long,  y as  long,_
            targetcolor        as  long,_
            _FLOODFILLBORDER   as  long, result as  long    '   ie fill out 'til this colour is met..

        call delay 10
    end sub

    sub delay sleeptime
        calldll #kernel32, "Sleep", sleeptime as long, ret as void
        scan
    end sub

    sub quit h$
        calldll #user32, "ReleaseDC", hw as ulong, hdc as ulong, ret as void   'release the DCclose #h$
        close #h$
        end
    end sub