Board Logo
« Fire? »

Welcome Guest. Please Login or Register.
Aug 17th, 2017, 06:26am


Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

Please use the forums Search feature before asking.
Please post code using the code box described in Format Your Messages.
This will keep indentation, separate it better form the message and prevent gibberish.
If the code is too long for one post or additional files are needed, upload a ZIP archive to the Just BASIC Files Archive Site.

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 hotthread  Author  Topic: Fire?  (Read 743 times)
tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3545
xx Fire?
« Thread started on: May 11th, 2017, 05:08am »

So I spent some time looking for "fire" or "burn" and found only this one
how many sprites can run simultanously?

So have to devise something of my own it seems...
User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 245
xx Re: Fire?
« Reply #1 on: May 11th, 2017, 05:27am »

hi ,
here is my first experiment with fire/flame(very primitive)
Code:
        open"flame"for graphics as#1
        r=100:x0=200:y0=200
        dc=atn(1)/45
        #1 "fill black;down;color white;line 50 200 ";x0-20;" ";y0+20*sin(90*dc)
        #1 "place ";x0;" ";y0
        min=10:max=20
      for j=1 to 3
            if min=5 then min=10 else min=5
            if max=35 then max=25
            if max=25 then max=20
            if max=20 then max=35
          for rd=min to max
                #1 "discard;down"
              for i=90+rd to 270-rd
                    x=x0+rd*cos(i*dc)
                    y=y0+rd*sin(i*dc)
                    if k=0 then k=1 else k=0
                    if k=1 then clr$="255 100 0" else clr$="200 180 0"
                    #1 "color ";clr$
                    #1 "goto ";x;" ";y
              next
          next
      next
        wait


 
User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1132
xx Re: Fire?
« Reply #2 on: May 11th, 2017, 08:55am »

Hi tsh, I look forward to a sprite thing! That would be the trick for the speed but do sprites blend in semi transparency?

Hi zzz,

Cute! I recognize a freshly lit match. Maybe we could alternate color lines, employ random height of flame and color line...

Since this is 2nd time I see that you open a window but don't set a trapclose, I remind:

#gr "trapclose quit" 'this is for window opened as #gr and calls sub routine called quit

OR this

#H$ "trapclose [quit] 'this is for window whose handle is H$ and GOSUB located at label [quit]

If I know you zzz, you would choose the [quit] label.

You set the trapclose so you can close a window without error. It works with WAIT to catch signal to end window.

How I write code:
when I code with FOR loop I put NEXT right under then fill in between

when I code IF... I put END IF next line under and then fill in between (if using an IF block)

when I code OPEN .... H$.... I put H$ "TRAPCLOSE [quit]" under it and then fill in between

Code:
        open"flame"for graphics as#1
        #1 "trapclose [quit]"  '<<<<<<<<<< set trap for exit without error
        r=100:x0=200:y0=200
        dc=atn(1)/45
        #1 "fill black;down;color white;line 50 200 ";x0-20;" ";y0+20*sin(90*dc)
        #1 "place ";x0;" ";y0
        min=10:max=20
      for j=1 to 3
            if min=5 then min=10 else min=5
            if max=35 then max=25
            if max=25 then max=20
            if max=20 then max=35
          for rd=min to max
                #1 "discard;down"
              for i=90+rd to 270-rd
                    x=x0+rd*cos(i*dc)
                    y=y0+rd*sin(i*dc)
                    if k=0 then k=1 else k=0
                    if k=1 then clr$="255 100 0" else clr$="200 180 0"
                    #1 "color ";clr$
                    #1 "goto ";x;" ";y
              next
          next
      next
        wait

[quit]  '<<<<<<<<<<<<<<<<<<<<< GOSUB executed when click close button
    close #1
    end
 


People (me at least) will love you if you put this in the code you display here. And thank you for indented code. ;-))
« Last Edit: May 11th, 2017, 09:00am by bplus » User IP Logged

B+
zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 245
xx Re: Fire?
« Reply #3 on: May 11th, 2017, 12:49pm »

taming flame is not that much easy as it seems.
eating too much memory and not fitting into a sub or function.
any idea or suggestion ?

B+
Quote:
do sprites blend in semi transparency?

there are soft wares like MTpaint,Windows paint which allow user do such things.Sprites also images so there should be a way to blend (semi)transparency.
User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1132
xx Re: Fire?
« Reply #4 on: May 11th, 2017, 4:28pm »

"any idea or suggestions"

no code?

OK first, should not have any memory problems drawing lines over lines in loops try DISCARD if you are getting them before cycle back in loop.

I would try a general oval area where I want my flame (we would test stationary flames first) and draw random line lengths in that area with all shades from bright red through orange through yellow.

Black out only random length at tips or flame. Have an occasional spark fly up.

The eternal flame can be realized in computer programming as long as the computer is plugged in and the power on and a clever programmer is at the keyboard. ;-))

User IP Logged

B+
zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 245
xx Re: Fire?
« Reply #5 on: May 12th, 2017, 02:12am »

B+,
Quote:
no code?

consider the code from Reply#1 or #2
User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1132
xx Re: Fire?
« Reply #6 on: May 12th, 2017, 1:38pm »

on May 12th, 2017, 02:12am, zzz000abc wrote:
B+,

consider the code from Reply#1 or #2


Hi zzz,


I mean from me you only want suggestions or ideas, but no code. Correct?

You don't want me to offer some code, with reply #1, #2 code also considered.

For example you want to figure it out all on your own before I show you "the right way" to do it. (I am joking that I am so skilled as to give you THE ultimately correct way to code this. I hope you get it.)
User IP Logged

B+
zzz000abc
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 245
xx Re: Fire?
« Reply #7 on: May 13th, 2017, 01:22am »

Quote:
I mean from me you only want suggestions or ideas, but no code. Correct?

hi , B+
I mean code/suggestions in the form of words as well as code.

If you or tsh want to use sprites in this forum only you can find live examples.
1.a burning folder found here just below the heading 'pages:1 2' http://justbasic.conforums.com/index.cgi?action=display&board=code&num=1494363847&start=0#1494486408
2. the LB logo it self. these form better prototypes I think if tsh/you have no other ideas as where to start.

BTW I started working on GTK+ color picker.
https://en.wikipedia.org/wiki/Color_picker
User IP Logged

bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1132
xx Re: Fire?
« Reply #8 on: May 13th, 2017, 10:05am »

on May 13th, 2017, 01:22am, zzz000abc wrote:
hi , B+
I mean code/suggestions in the form of words as well as code.

If you or tsh want to use sprites in this forum only you can find live examples.
1.a burning folder found here just below the heading 'pages:1 2' http://justbasic.conforums.com/index.cgi?action=display&board=code&num=1494363847&start=0#1494486408
2. the LB logo it self. these form better prototypes I think if tsh/you have no other ideas as where to start.

BTW I started working on GTK+ color picker.
https://en.wikipedia.org/wiki/Color_picker


Quote:
I mean code/suggestions in the form of words as well as code.

OK I have code that might be interesting for starters, fire starters, hmm... it is not translated to JB yet, it is not much better than yours but it might lead to more ideas. I will translate to JB. This uses no sprites.

Dang, I already forgot what #1 pointed to, the color wheel thread?

LB has a logo with fire? ha, I never noticed. I will have to give it another look/see! (Append: wait... it's the cartoon of Statue of Liberty's Torch, I think, nice logo idea BTW.)

A color picker is an excellent project! But I hope you don't forget about fire because you have me thinking about it and doing things. smiley
« Last Edit: May 13th, 2017, 10:10am by bplus » User IP Logged

B+
bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1132
xx Re: Fire?
« Reply #9 on: May 13th, 2017, 8:19pm »

Actually a little flicker helps the effect in this case:

Code:
'fire by bplus.txt for JB[B+=MGA] 2017-05-13

global H$, XMAX, YMAX, PI, DEG, RAD
H$ = "gr"
XMAX = 500 : YMAX = 500 : PI = acs(-1) : RAD = PI / 180

nomainwin

WindowWidth = XMAX + 8
WindowHeight = YMAX + 32
UpperLeftX = (1200 - XMAX) / 2
UpperLeftY = (700 - YMAX) / 2

open "Fire by bplus" for graphics_nsb_nf as #gr
#gr "trapclose quit"
#gr "down"
'============================== main code
#gr "size 8"
dim f(359, 1)
x = XMAX/2 + 80 : y = YMAX/2 + 40 : w = 100 : h = 110
while 1
    scan
    #gr "fill black"
    w = rand(45, 65)
    for i = 0 to 359
        scan
        f(i, 0) = x + w * cos(RAD * (i+90))
        f(i, 1) = y + h * sin(RAD * (i+90))
    next
    call hue 200, 180, 160
    call aline 80, 250, f(0, 0), f (0, 1)
    for i = 1 to 170
        scan
        call midInk 168, 205, 0, 255, 255, 0, rand(25, 50)/50
        ri = rand(1, 359)
        rf = rnd(0)
        midx = ( f(ri, 0) - f(0, 0) )/2 * rf + f(0, 0)
        midy = ( f(ri, 1) - f(0, 1) )/2 * rf + f(0, 1)
        if rnd(0) < .9 then
            call aline f(0, 0), f(0, 1), midx, midy
        else
            call pset midx, midy
        end if
    next
    #gr "discard"
wend
wait

function rand(lo, hi)
    rand = int((hi - lo + 1) * rnd(0)) + lo
end function

sub hue r, g, b 'fore and back
    #gr "color ";r;" ";g;" ";b
    #gr "backcolor ";r;" ";g;" ";b
end sub

sub pset x, y
    #gr "set ";x;" ";y
end sub

sub aline x0, y0, x1, y1
    #gr "line ";x0;" ";y0;" ";x1+1;" ";y1+1  'add 1 to end point
end sub

sub midInk r1, g1, b1, r2, g2, b2, frac
    dr = (r2 - r1) * frac : dg = (g2 - g1) * frac : db = (b2 - b1) * frac
    #gr "color ";r1 + dr;" ";g1 + dg;" ";b1 + db
    #gr "backcolor ";r1 + dr;" ";g1 + dg;" ";b1 + db
end sub

sub quit H$
    close #H$
    end
end sub

 
User IP Logged

B+
bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1132
xx Re: Fire?
« Reply #10 on: May 14th, 2017, 12:13pm »

Ha! I am looking all over the place trying to find Liberty torch icon, I remember seeing it somewherehuh

All I had to do was look up to see the light!
User IP Logged

B+
tsh73
JB-Supporter


member is offline

Avatar




PM

Gender: Male
Posts: 3545
xx Re: Fire?
« Reply #11 on: May 14th, 2017, 4:02pm »

I have another idea but I have not enough will-power to code it :(

But I found my old QBasic code from 2007
Here how it looks in JB
(really it was slow even in QB)
The colors are "Winamp fire" (from winAmp spectrum analizer)
Code:
'fire line
'tsh73 - conversion of QB code from 03 2007
'01 - initial
'02 - try to speed up by SIZE 2

'DECLARE FUNCTION modify! (h!, dh!, hmax!)
'DECLARE SUB fireLine (x!, y!, h!, hh!)
'fire project.
'some new things to be used...
'1) use aLine func
'2) try to fire along time?
'3) along time AND from 0 with 5 heght speed
'4) ok, how about the same along pentagram? That would be nifty!
'5) Now change colors to real firey stuff (change fireLine())
'--==** It's all DONE!!! **==--
'COMMON c() AS INTEGER
nomainwin

gosub [initQBcolors]
'colors are::
DIM c$(3)'from 0
c$(3) = qb$(4)
c$(2) = qb$(6)
c$(1) = qb$(14)
c$(0) = qb$(10)

'SCREEN 12
WindowWidth = 640:    WindowHeight = 480
gosub [ajustWindow]

x0 = 200
wmax = 200
bottom = 250
h = 30
h = 50
h = 100
dh = h / 10
'LINE (x0, bottom)-STEP(w, -h), , B
'PRINT "do it along HORIZ line..."
'a$ = INPUT$(1)
notice "do it along HORIZ line..."
w = 0
dw = .05        'to be set by trial / error
'actually have an idea for timer but it's a separate task
DIM hh(wmax)

#gr "when characterInput [char1]"
gotKey = 0
while gotKey=0
    scan
   i = int(RND(0) * w/2)*2
   x = x0 + i
   hh(i) = modify(hh(i), dh, h)
   CALL fireLine x, bottom, h, hh(i)
   w = w + dw
   IF w > wmax THEN w = wmax
   #gr "discard"
wend

[part2]
'PRINT "now, do it along general line..."
'a$ = INPUT$(1)
notice "now, do it along general line..."
#gr "discard; fill black"
REDIM hh(wmax)  'set all to 0
'now, do it along the line...
'x0
x1 = x0 + w
y0 = bottom
y1 = bottom - h
w = 0
#gr "when characterInput [char2]"
gotKey = 0
while gotKey=0
    scan
   i = int(RND(0) * w/2)*2
   x = x0 + i
   y = y0 + (y1 - y0) * (x - x0) / (x1 - x0)
   hh(i) = modify(hh(i), dh, h)
   CALL fireLine x, y, h, hh(i)
   w = w + dw
   IF w > wmax THEN w = wmax
   #gr "discard"
wend

[part3]
'PRINT "draw pentagram..."
'troubles with order.
'a$ = INPUT$(1)
'CLS
'notice "draw pentagram..."
#gr "discard; fill black"
'get the points
pi = 355 / 113
DIM xp(5), yp(5), l(5)  'lengths!
phi = 0
FOR i = 0 TO 4
   phi = 2 * pi / 5 * i * 2
   xp(i) = 320 + 300 * SIN(phi)
   yp(i) = 240 + 20 + 160 * COS(phi)
NEXT

''drawing pentagram: just for tests - commented out
i = 0
wmax = 0
FOR j = 0 TO 4
   ii = (i + 1) MOD 5
   'LINE (xp(ii), yp(ii))-(xp(I), yp(I))
   'CIRCLE (xp(i), yp(i)), 10
   'CIRCLE (xp(ii), yp(ii)), 8
   'a$ = INPUT$(1)
   l(i) = (xp(ii) - xp(i))
   'PRINT l(i)
   wmax = wmax + ABS(l(i))    'ABS!!! 'cause the sum is 0 - closed line
   i = ii
NEXT
notice "one more thing: fire pentagram..."
'PRINT "one more thing: fire pentagram..."
'a$ = INPUT$(1)
w = 0
dw = .05        'to be set by trial / eror
DIM hhp(640, 4)
'DO UNTIL INKEY$ <> ""
#gr "when characterInput [quit]"
while 1
SCAN
'change: instead of
   'RANDOMLY GET A LINE
   'and randomly get a point on a line
   'we 'll do randomly get a point on a length
   'then transfer it to line, point on a line.
   rl = int(RND(0) * w/2)*2
   i = 0
   DO WHILE rl - ABS(l(i)) > 0 'get a line
      rl = rl - ABS(l(i))
      i = i + 1
   LOOP
   'ddx = rl * SGN(l(i))       'get pos on that line. Use the sign!
   ddx = rl * ((l(i)>0)-(l(i)<0))
   ii = (i + 1) MOD 5
   'and randomly get a point on a line
   dx = l(i)
   dy = (yp(ii) - yp(i))
   x = xp(i) + ddx
   y = yp(i) + dy * (x - xp(i)) / dx
   hhp(rl, i) = modify(hhp(rl, i), dh, h)
   CALL fireLine x, y, h, hhp(rl, i)
   w = w + dw
   IF w > wmax THEN w = wmax
   #gr "discard"
wend
'not very fast, is it???
'and have some problems with overlapping.
'Probably if I have old val and clear just difference between them...
'Ok it all works but speed definitely the issue.

SUB fireLine x, y, h, hh
'SHARED c() AS INTEGER
'colors are in c()
   'clear line first
   'LINE (x, y)-STEP(0, -h), 0
    #gr "color black"
    #gr "line ";int(x);" ";int(y);" ";int(x);" ";int(y-h)
   h4 = hh / 4
   FOR j = 3 TO 0 STEP -1
      'LINE (x, y - j * h4)-STEP(0, -h4), c(j)
        #gr "color ";c$(j)
        #gr "line ";int(x);" ";int(y - j * h4);" ";int(x);" ";int(y - j * h4-h4)
   NEXT
END SUB

SUB fireLine2 x, y, h, hh
'old one - just random colors
   c = RND(0) * 14 + 1
   'LINE (x, y - h)-STEP(0, h), 0
    #gr "color black"
    #gr "line ";x;" ";y-h;" ";x;" ";y
   'LINE (x, y)-STEP(0, -hh), c
    #gr "color ";qb$(c)
    #gr "line ";x;" ";y;" ";x;" ";y-hh
END SUB

FUNCTION modify (h, dh, hmax)
   hh = h + (RND(0) - .5) * dh
   IF hh > hmax THEN hh = hmax
   IF hh < 0 THEN hh = 0
   modify = hh
END FUNCTION

'=================
[ajustWindow]
    desiredWidth = WindowWidth
    desiredHeight = WindowHeight
    UpperLeftX = 1
    UpperLeftY = 1
    WindowWidth = 200
    WindowHeight = 100
    open "Ajusting..." for graphics_nsb_nf as #gr
    #gr, "home ; down ; posxy x y"
    'x, y give us width, height
    width = 2*x : height = 2*y
    close #gr

    slackX = 200-width
    slackY = 100-height

    WindowWidth = desiredWidth + slackX
    WindowHeight = desiredHeight + slackY
    open "Space advances to next thing" for graphics_nsb_nf as #gr
    #gr, "trapclose [quit]"
    #gr, "down; fill black; flush"
	#gr, "size 2"
	#gr, "setfocus"
return

[initQBcolors]
dim qb$(15) 'thanks Andy Amaya
qb$( 0) = "  0   0   0" 'black
qb$( 1) = "  0   0 128" 'blue
qb$( 2) = "  8 128   8" 'green
qb$( 3) = "  0 128 128" 'cyan
qb$( 4) = "128   0   0" 'red
qb$( 5) = "128   0 128" 'magenta
qb$( 6) = "128  64  32" 'brown
qb$( 7) = "168 168 168" 'white
qb$( 8) = "128 128 128" 'grey
qb$( 9) = " 84  84 252" 'light blue
qb$(10) = " 42 252  42" 'light green
qb$(11) = "  0 220 220" 'light cyan
qb$(12) = "255   0   0" 'light red
qb$(13) = "255  84 255" 'light magenta
qb$(14) = "255 255   0" 'yellow
qb$(15) = "255 255 255" 'bright white
return

[quit]
    close #gr
    end
return

[char1]
    #gr "when characterInput"
    gotKey = 1
'wait
goto [part2]

[char2]
    #gr "when characterInput"
    gotKey = 1
'wait
goto [part3]
 
User IP Logged

Q: "And if I took your codes and compile them, and sell them for a profit"?
A: Go ahead. I had my share of good then I coded it for fun, if you can make better use of it - please do.
(enjoying JB 1.01 on WinXP, netbook and desktop)
bplus
Senior Member
ImageImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 1132
xx Re: Fire?
« Reply #12 on: May 14th, 2017, 5:56pm »

Hey tsh73,

Not bad! not bad speed wise, I have an idea for random triangles now, then we will see speed problems, I bet!

But with sprites? Maybe what you were thinking?

Maybe from bounce, I learned something, but it is a will power effort ;-))

I wonder how zzz's will power is holding up? cheesy
User IP Logged

B+
Rod
Administrator
ImageImageImageImageImage


member is offline

Avatar

Graphics = Goosebumps!


PM

Gender: Male
Posts: 3070
xx Re: Fire?
« Reply #13 on: May 15th, 2017, 03:22am »

Very roughly drawn demo of sprite based fire.


http://gamebin.webs.com/Fire.zip
User IP Logged

tenochtitlanuk ( John F)
Full Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 417
xx Re: Fire?
« Reply #14 on: May 15th, 2017, 11:05am »

I'm always keen for people to see advantages in moving to 'big brother' Liberty BASIC.
In it you can do floodfills, producing results llke this ..
User Image
The code will be on the LB conforum. It's interesting how many different ways you can tackle this kind of thing!
« Last Edit: May 15th, 2017, 11:20am by tenochtitlanuk ( John F) » User IP Logged

Visit my LB/JB pages at http://www.diga.me.uk/index.html
I use XP and Ubuntu Linux on old machines!
Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

Conforums Terms of Service | Membership Rules | Home | Search | Recent Posts | Notification | Format Your Message | Installation FAQ

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