Liberty BASIC Community Forum
« Flame-effects »

Welcome Guest. Please Login or Register.
May 29th, 2017, 08:15am


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


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Flame-effects  (Read 63 times)
tenochtitlanuk
Moderator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1151
xx Flame-effects
« Thread started on: May 15th, 2017, 11:13am »

User Image
Over on the JB conforum there has been some fun making animated flame effects.
It's a natural for LB and flood-filling...

Code:
nomainwin

WindowWidth  = 400
WindowHeight = 400
UpperLeftX   = 200
UpperLeftY   =  50

open "Flame" for graphics_nsb_nf as #wg

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

#wg "trapclose quit"
#wg "down"

loadbmp "scr", "candle.bmp"
'   this is a colour bmp. Background colour ="1 1 1" and outline colour "120 120 120" and must not be used....
#wg "drawbmp scr 0 0"

loadbmp "scr2", "colors.bmp"
'   this is a colour bmp with 100 suitable colours..
#wg "drawbmp scr2 1 1"

dim col$( 100)
y           =3

for i =1 to 100
    calldll #gdi32, "GetPixel", hdc as ulong, i as long, y as long, pixcol as ulong
        bl      = int(  pixcol /( 256*256))
        gr      = int( (pixcol -bl *256*256) / 256)
        re      = int(  pixcol -bl *256*256 -gr *256)
        col$( i) =str$( re) +" " +str$( gr) +" " +str$( bl)
next i

targetcolor     =120 *2^16 +120 *2^8 +120  '   this is the colour "120 120 120" of the outline to fill out to.

for i =1 to 10000    '   1000 flickers....

    x            =int( 100 +300 *rnd( 1))   '   choose point to flood fill out from.... out to "120 120 120" outlines.
    y            =int(      400 *rnd( 1))

    fillCol$    =col$( 1 +int( 100 *rnd( 1)))

    calldll #gdi32, "GetPixel", hdc as ulong, x as long, y as long, pixcol as ulong
        bl      = int(  pixcol /( 256*256))
        gr      = int( (pixcol -bl *256*256) / 256)
        re      = int(  pixcol -bl *256*256 -gr *256)

'   check we've not chosen outline or background color for fill, and that area is available, ie not the "black" background
'       "black" (1 1 1) and reserved colours like "220 20 20" must remain untouched.
if ( ( str$( re) +" " +str$( gr) +" " +str$( bl) ="1 1 1") or ( str$( re) +" " +str$( gr) +" " +str$( bl) ="220 20 20")) then [past]

    if ( ( fillCol$ <>"1 1 1") and ( fillCol$ <>"120 120 120")) then       '   must not fill with outline (120 120 120) border or "black" background.
        #wg "color "; fillCol$; " ; up ; backcolor "; fillCol$

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

        'calldll #kernel32, "Sleep", 100 as long, ret as void   '   un=rem for optional delay
        scan
    end if
  [past]

'if i /100 =int( i /100) then   '   un-rem to save some images to make an animated gif if required...
'    #wg "flush ; getbmp scr 110 0 200 390"
'    bmpsave "scr", "flame"; right$( "000" +str$( i), 3); ".bmp"
'end if

next i

wait

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

You need two BMP files- the one with the outlines to fill out to, and a strip of suitable graduated colours to use..

User Image


User Image

PS I chose the outline colour rather unsuitably- it woulkd be better to use a colour mid-range for the flame, rather than a mid-grey. Easily altered...
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