Qbasicnews.com
July 02, 2020, 06:42:13 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Drawing Flames  (Read 18077 times)
Pyrokid
Wandering Guru
***
Posts: 355



WWW
« on: September 07, 2005, 08:50:31 PM »

Alright ive always thought it would be cool to write a program that drawed a fire that looked quite real and looked cool and i thought by seeing some peoples entries that i could figure somthing out.

Rules
Looks like a flame or fire
Can be still or moving
no external files
Lots of remarks
Logged

his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless  effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
rdc
Senior Member
**
Posts: 176



WWW
« Reply #1 on: September 07, 2005, 09:21:09 PM »

Realistic fire is very difficult to do, even with advanced graphics techniques.
Logged

Pyrokid
Wandering Guru
***
Posts: 355



WWW
« Reply #2 on: September 07, 2005, 09:24:32 PM »

Well not completely real but beliveable
Logged

his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless  effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Deleter
Na_th_an
*****
Posts: 1293



WWW
« Reply #3 on: September 07, 2005, 11:30:02 PM »

Pyro:
01010111 01100101 01101100 01101100 00101100 00100000 01101101 01100001 01111001 01100010 01100101 00100000 01101001 01100110 00100000 01111001 01101111 01110101 00100000 01110000 01110101 01110100 00100000 01101001 01110100 00100000 01101001 01101110 00100000 01101000 01100101 01111000 00101110 00101110

And here's my entry (not exactly the effect I was going for, but it will suffice until I feel like changing it Tongue) it runs very slow. on my comp its fine, but I'm sure on lower end systems it will look like cripe. :roll:

Code:
DECLARE SUB SpawnParticle()
DECLARE SUB HandleParticles()
DECLARE SUB DrawParticles()
DECLARE SUB BuildSprite(argColor AS INTEGER, address AS INTEGER PTR, size AS INTEGER)
DECLARE FUNCTION Neighbors(index AS INTEGER) AS INTEGER

TYPE ParticleType
    x AS DOUBLE
    y AS INTEGER
    xSpeed AS INTEGER
    ySpeed AS INTEGER
    heat AS INTEGER
    lastUpdate AS DOUBLE
END TYPE

CONST MaxParticles = 1000
CONST SpawnRate = 100
CONST DecayFactor = 750'1000

RANDOMIZE TIMER

SCREENRES 640,480,32,2

DIM SHARED      AS ParticleType     particle(MaxParticles)
DIM SHARED      AS INTEGER          sprite(9)

DIM     AS INTEGER          tempCount
DIM     AS DOUBLE           lastSpawn
DIM     AS INTEGER          curPage

FOR tempCount = 0 TO 99
    SpawnParticle()
NEXT

lastSpawn = TIMER

DO
    CLS
    HandleParticles()
    DrawParticles()
   
    SCREENSET curPage, -(curPage - 1)
    curPage = -(curPage - 1)
   
    IF (TIMER - lastSpawn) >= (1/SpawnRate) THEN
        FOR tempCount = 1 TO (TIMER - lastSpawn)*SpawnRate
            SpawnParticle()
        NEXT
    END IF
   
   
   
LOOP

SUB SpawnParticle()
    DIM AS INTEGER tempX, tempY, tempHeat, tempCount
   
    FOR tempCount = 0 TO MaxParticles -1
        IF particle(tempCount).heat <= 0 THEN
            particle(tempCount).x = 320 + INT(RND * 51) - 25'INT(RND * 11) - 5
            particle(tempCount).y = 479
            particle(tempCount).heat = INT(RND * 100)
            particle(tempCount).ySpeed = particle(tempCount).heat \ 2 + 25
            particle(tempCount).heat += 950
            particle(tempCount).xSpeed = INT(RND * 50) - 25
            particle(tempCount).lastUpdate = TIMER
            EXIT FOR
        END IF
    NEXT
   
END SUB

SUB HandleParticles()
    DIM AS INTEGER tempCount
    FOR tempCount = 0 TO MaxParticles -1
        IF particle(tempCount).heat > 0 THEN
            IF particle(tempCount).ySpeed * (TIMER - particle(tempCount).lastUpdate) >= 1 THEN
                particle(tempCount).lastUpdate = (TIMER - particle(tempCount).lastUpdate)
                particle(tempCount).y -= particle(tempCount).ySpeed * particle(tempCount).lastUpdate
                particle(tempCount).x += particle(tempCount).xSpeed * particle(tempCount).lastUpdate
                particle(tempCount).heat -= (DecayFactor / Neighbors(tempCount)) * particle(tempCount).lastUpdate
                particle(tempCount).lastUpdate = TIMER
            END IF
        END IF
    NEXT        
END SUB

SUB DrawParticles()
    DIM AS INTEGER tempCount, tempColor, tempSize, tempAlpha
    FOR tempCount = 0 TO MaxParticles -1
        IF particle(tempCount).heat > 0 THEN
            tempColor = INT(particle(tempCount).heat / 2.06)
            tempSize = 1
            IF tempColor > 255 THEN
                IF tempColor > 383 THEN tempSize = 3 ELSE tempSize = 2
                tempAlpha = (tempColor - 255)/1.33
                tempColor = RGB(tempColor, tempColor - 510,0)                
            ELSE
                tempAlpha = -tempColor
                tempColor = RGB(tempColor, 0,0)                
            END IF
            IF tempAlpha > 0 THEN
                BuildSprite(tempColor, @sprite(0), tempSize)
                PUT(particle(tempCount).x-1, particle(tempCount).y-1),@sprite(0),alpha,tempAlpha
                tempAlpha = 255
            ELSE
                tempAlpha = -(tempColor)
            END IF
            BuildSprite(tempColor, @sprite(0), 1)
            PUT (particle(tempCount).x, particle(tempCount).y),@sprite(0),pset'alpha,tempAlpha
        END IF        
    NEXT
END SUB

FUNCTION Neighbors(index AS INTEGER) AS INTEGER
    DIM AS INTEGER tempCount, tempNeighbors
   
    FOR tempCount = 0 TO MaxParticles - 1
        IF ABS(particle(tempCount).x - particle(index).x) < 2 THEN
            IF ABS(particle(tempCount).y - particle(index).y) < 2 THEN
                IF particle(tempCount).heat > 0 THEN tempNeighbors += 1
            END IF
        END IF
    NEXT tempCount
   
    RETURN (tempNeighbors - 1) 'SUBTRACT THE PARTICLE WE WERE CHECKING
END FUNCTION

SUB BuildSprite(argColor AS INTEGER, address AS INTEGER PTR, size AS INTEGER)
    'Y*65536+X*8+4
    address[0] = (size shl 16) + (size shl 3) + 4
    address[1] = argColor
    address[2] = argColor
    address[3] = argColor
    address[4] = argColor
    address[5] = argColor
    address[6] = argColor
    address[7] = argColor
    address[8] = argColor
    address[9] = argColor
END SUB
Logged

Pyrokid
Wandering Guru
***
Posts: 355



WWW
« Reply #4 on: September 07, 2005, 11:37:36 PM »

Deleter: 01001001 00100000 01101000 01100001 01110110 01101110 00100111 01110100 00100000 01101100 01100101 01100001 01110010 01101110 01100101 01100100 00100000 01101000 01100101 01111000 00100000 01101001 01101110 00100000 01101101 01111001 00100000 01100011 01101111 01101101 01110000 01110101 01110100 01100101 01110010 00100000 01101110 01100101 01110100 01110111 01101111 01110010 01101011 01101001 01101110 01100111 00100000 01100011 01101100 01100001 01110011 01110011 00100000 01111001 01100101 01110100 00100000 01101001 00100000 01110100 01101000 01101001 01101110 01101011 00100000 01110100 01101000 01100001 01110100 01110011 00100000 01110100 01101111 01101101 01101101 01101111 01110010 01101111 01110111

Hmm i cant get it to work i get a syntax error
Logged

his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless  effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Sterling Christensen
Na_th_an
*****
Posts: 1328


« Reply #5 on: September 08, 2005, 12:59:18 AM »

Here's my attempt:
Code:
' comment out to remove flamethrower
#define flamethrower
#define ft_width 9

' comment out to remove sparkle effect
#define sparkles 20

' comment out to fade smoothly
#define randomize_vertical

' simulates flickering from wind
#define randomize_horizontal

' Size of the screen
#define sw 320
#define sh 200

' Space on the right and left between fire and edge of screen
#define margin 40

screenres sw, sh, 8

' Now we set the palette

c = 0

' start with a 16 color light blue (200,200,255) -> white gradient
for x = 0 to 15
y = x * 55 \ 15
palette c, 200+y, 200+y, 255
c += 1
next x

' then an 84 color white to yellow gradient
for x = 0 to 83
palette c, 255, 255, 255 - x * 255 \ 83
c += 1
next x

' 20 color yellow -> dark red (215, 0, 0)
for x = 0 to 15+4
red = 255-(x shl 2)
palette c, red, 255 - x * 255 \ (15+4), 0
c += 1
next x

' 8 color dark red -> smokey gray (108, 108, 108)
for x = 0 to 7
palette c, red - x * (red-108) \ 7, x * 108 \ 7, x * 108 \ 7
c += 1
next x

' 128 color smokey gray -> black
for x = 0 to 127
y = 108 - (x * 108 \ 127)
palette c, y, y, y
c += 1
next x

' clear the screen to black
color , 255
cls

randomize timer

dim as ubyte ptr scrn, p0, p1, p2

n = 1
ftd = 1
do
#ifdef sparkles
' Draw some pixels at random locations
' the intensitiy increases downward (192 at the top, 0 at the bottom)
for c = 1 to sparkles
y = int(rnd * (sh - 1))
pset (int(rnd * (sw-2)) + 1, y), 192 - (y * 192 \ sh)
next c
#endif

screenlock
scrn = screenptr

' Randomize the bottom row of pixels
xs = margin  ' Where the fire starts
xe = sw-1-margin  ' Where the fire ends
p0 = scrn + sw * (sh - 1)  ' pointer to bottom row
for x = xs to xe
p0[x] = (p0[x] * 2 + int(rnd * 210)) \ 3
next x

#ifdef flamethrower
ftx += ftd  ' move the flamethrower

' make it bounce
if ftx < 1 or ftx >= sw-ft_width-1 then ftd = -ftd

' draw it
p0[ftx] = 160
for x = ftx+1 to ftx+ft_width-1
p0[x] = 0
next x
p0[x] = 160
#endif

p0 = scrn  ' pointer to the top row of pixels
p1 = p0 + sw  ' the next row
p2 = p1 + sw  ' and the row after that

' Loop over all but the last 2 rows
for y = 0 to sh-3

#ifdef randomize_vertical
n = int(rnd * 3)
#endif

#ifdef randomize_horizontal
d = int(rnd * 3) - 1
#endif

' Loop over all but the first and last column
for x = 1 to sw-2

xd = x + d
if xd < 1 or xd > sw-2 then xd = x

' Take the average of a 3x2 block of pixels at (xd, y)
' giving the top row twice as much weight
c = p1[xd-1] + p1[xd] + p1[xd+1]
c = c+c + p2[xd-1] + p2[xd] + p2[xd+1]
c = c \ 9

' Fade the pixel a little (blue->white->yellow->red->grey->black)
c += n
if c > 255 then c = 255

p0[x] = c
next x

' Advance the pointers to the next row
p0 += sw
p1 += sw
p2 += sw
next y

' Do the second to bottom row
p0 = scrn + (sh-2) * sw  ' pointer to row sh-2
p1 = p0 + sw  ' pointer to the row below p0 (the last row, sh-1)
for x = 1 to sw-2
' Take the average of a 3x1 block of pixels
c = (p1[x-1] + p1[x] + p1[x+1]) \ 3

' Fade the pixel a little (blue->white->yellow->red->grey->black)
c += 2
if c > 255 then c = 255

p0[x] = c
next x

screenunlock

' Wait 8 milliseconds
sleep 8

' Stop looping if the user has pressed a key
loop until len(inkey$)

end
Logged
rpgfan3233
Ancient Guru
****
Posts: 617



« Reply #6 on: September 08, 2005, 01:31:05 AM »

Quote from: "Pyrokid"
Deleter: 01001001 00100000 01101000 01100001 01110110 01101110 00100111 01110100 00100000 01101100 01100101 01100001 01110010 01101110 01100101 01100100 00100000 01101000 01100101 01111000 00100000 01101001 01101110 00100000 01101101 01111001 00100000 01100011 01101111 01101101 01110000 01110101 01110100 01100101 01110010 00100000 01101110 01100101 01110100 01110111 01101111 01110010 01101011 01101001 01101110 01100111 00100000 01100011 01101100 01100001 01110011 01110011 00100000 01111001 01100101 01110100 00100000 01101001 00100000 01110100 01101000 01101001 01101110 01101011 00100000 01110100 01101000 01100001 01110100 01110011 00100000 01110100 01101111 01101101 01101101 01101111 01110010 01101111 01110111

Hmm i cant get it to work i get a syntax error

[syntax="Binary"]01000011 01101000 01100101 01100011 01101011 00100000 01111001 01101111 01110101 01110010 00100000 01010000 01001101 01110011 00100000 01101001 01100110 00100000 01111001 01101111 01110101 00100000 01101000 01100001 01110110 01100101 01101110 00100111 01110100 00100000 01100001 01101100 01110010 01100101 01100001 01100100 01111001 00101110 00100000 01001001 00100000 01110011 01100101 01101110 01110100 00100000 01111001 01101111 01110101 00100000 01100001 00100000 01110000 01110010 01101111 01100111 01110010 01100001 01101101 00100000 01110100 01101000 01100001 01110100 00100000 01100011 01101111 01101110 01110110 01100101 01110010 01110100 01110011 00100000 01100110 01110010 01101111 01101101 00100000 01101000 01100101 01111000 00100000 01110100 01101111 00100000 01100001 01110011 01100011 01101001 01101001 00101100 00100000 01100010 01101001 01101110 01100001 01110010 01111001 00100000 01110100 01101111 00100000 01100001 01110011 01100011 01101001 01101001 00101100 00100000 01100001 01110011 01100011 01101001 01101001 00100000 01110100 01101111 00100000 01100010 01101001 01101110 01100001 01110010 01111001 00100000 01100001 01101110 01100100 00100000 01100001 01110011 01100011 01101001 01101001 00100000 01110100 01101111 00100000 01101000 01100101 01111000 00101110[/syntax]
Logged

974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Pyrokid
Wandering Guru
***
Posts: 355



WWW
« Reply #7 on: September 08, 2005, 08:17:31 AM »

01001100 01101111 01101100 00100000 01111001 01101111 01110101 01110010 00100000 01100010 01101001 01101110 01100001 01110010 01111001 00100000 01110011 01110100 01110010 01101001 01101110 01100111 00100000 01110111 01100001 01110011 00100000 01101111 01110110 01100101 01110010 00100000 00110001 00110011 00110000 00110000 00100000 01100011 01101000 01100001 01110010 00100000 01100001 01101110 01100100 00100000 01101001 00100000 01101000 01100001 01100100 00100000 01110100 01101111 00100000 01110011 01110000 01101100 01101001 01110100 00100000 01101001 01110100 00101110 00100000 01000001 01101110 01111001 01110111 01100001 01111001 01110011 00100000 01110100 01101000 01100001 01101110 01101011 01110011 00100000 01100010 01110101 01110100 00100000 01101001 00100000 01100100 01101111 01101110 01110100 00100000 01101110 01100101 01100101 01100100 00100000 01101001 01110100
Logged

his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless  effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
The walrus
Forum Regular
**
Posts: 137



WWW
« Reply #8 on: September 08, 2005, 12:29:30 PM »

I'm gonna have nightmares about 1's and 0's  :lol:
Logged
Dio
I hold this place together
*****
Posts: 874



« Reply #9 on: September 08, 2005, 04:42:40 PM »

lol, i guess you guys made a program to convert ASCII values in bi. i would do the same if i wern't so lazy.  Cheesy
Logged

quote="whitetiger0990"]whitetiger is.. WHITE POWER!!! [/quote]
Here
Neo
Na_th_an
*****
Posts: 2150



« Reply #10 on: September 08, 2005, 05:10:14 PM »

Stop posting in binary.

I wont even bother visiting this thread anymore if ppl speak in binary.
Logged
Pyrokid
Wandering Guru
***
Posts: 355



WWW
« Reply #11 on: September 08, 2005, 05:11:24 PM »

Dio:  01001100 01101111 01101100 00100000 01110100 01101000 01100101 00100000 01110000 01110010 01101111 01100111 01110010 01100001 01101101 00100000 01101001 00100000 01110111 01110010 01101111 01110100 01100101 00100000 01110100 01101111 01101111 01101011 00100000 01101101 01100101 00100000 01101100 01101001 01101011 01100101 00100000 00110001 00110000 00100000 01101101 01101001 01101110 01110011 00100000 01110100 01101111 00100000 01101101 01100001 01101011 01100101 00100000 01110000 01110010 01101001 01110100 01110100 01111001 00100000 01100101 01100001 01110011 01111001

Very nice Sterling
However i didnt quite get some of the math you were doing so i edited the rules so that you need remarks

Sry neo ill stop
Logged

his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless  effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
rpgfan3233
Ancient Guru
****
Posts: 617



« Reply #12 on: September 08, 2005, 06:57:10 PM »

Neo: U29ycnksIE5lby4gSGV4IG9yIGJhc2UgNjQgd2lsbCBiZSB1c2VkIGlmIEkgcG9zdCBhbnl0aGluZyBlbmNvZGVkIChvdGhlciB0aGFuIHRoaXMpLCB1bmxlc3MgYmluYXJ5IGlzIHJlcXVlc3RlZC4=

Created my own proggy for base 64. That should tell you how bored I get sometimes. :-)
Logged

974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
Dio
I hold this place together
*****
Posts: 874



« Reply #13 on: September 08, 2005, 08:21:08 PM »

Quote from: "Pyrokid"
Dio:  01001100 01101111 01101100 00100000 01110100 01101000 01100101 00100000 01110000 01110010 01101111 01100111 01110010 01100001 01101101 00100000 01101001 00100000 01110111 01110010 01101111 01110100 01100101 00100000 01110100 01101111 01101111 01101011 00100000 01101101 01100101 00100000 01101100 01101001 01101011 01100101 00100000 00110001 00110000 00100000 01101101 01101001 01101110 01110011 00100000 01110100 01101111 00100000 01101101 01100001 01101011 01100101 00100000 01110000 01110010 01101001 01110100 01110100 01111001 00100000 01100101 01100001 01110011 01111001


thanks, i had to manually translate that. and btw, my sig is for you and it is ASCII translated to the octal number system. [inset evil laugh here]  :wink:
Logged

quote="whitetiger0990"]whitetiger is.. WHITE POWER!!! [/quote]
Here
Pyrokid
Wandering Guru
***
Posts: 355



WWW
« Reply #14 on: September 08, 2005, 08:26:02 PM »

You are kidding me you converted that to decimal then to ascii with a pen and paper.
Logged

his world has been connected...
Tied to the darkness.
Soon to be completely eclipsed.
There is so very much to learn...
You understand so little.
A meaningless  effort.
One who knows nothing can understand nothing.
-Ansem Bringer of darkness and creator of the heartless
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!