Liberty BASIC Community Forum
« Flood filling.... »

Welcome Guest. Please Login or Register.
Jun 25th, 2017, 05:25am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Flood filling....  (Read 365 times)
tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1154
xx Flood filling....
« Thread started 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
Code:

nomainwin

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)
    scan
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
        scan
next i

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

wait

[quit]
    calldll #user32, "ReleaseDC", hw as ulong, hdc as ulong   'release the DC
    close #wg
    end
 
User IP Logged

tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1154
xx Re: Flood filling....
« Reply #1 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls