Author Topic: Simple Fireball Effect  (Read 4870 times)

0 Members and 1 Guest are viewing this topic.

Offline ferris

  • Pentium
  • *****
  • Posts: 841
  • Karma: 84
    • View Profile
    • Youth Uprising Home
Simple Fireball Effect
« on: June 11, 2006 »
Basically I got bored one night.

This is a 128x128 fire effect mapped and scaled radially from an animated center point.

I'm posting this because I really have no use for it.

Code: [Select]
' Fireball

defint a - z

#include "tinyptc.bi"

const scrw = 320
const scrh = 240

if ptc_open("Fireball",scrw,scrh) = 0 then end

declare sub setupfireball
declare sub fireball

dim shared buffer(scrw * scrh)

dim shared pal(256)
dim shared tex(128,128)
dim shared cmap(128,128)
dim shared dmap(scrw shl 1,scrh shl 1) as double
dim shared amap(scrw shl 1,scrh shl 1) as double

dim shared fbox = scrw shr 1
dim shared fboy = scrh shr 1
dim shared cmapy

setupfireball

do
    fireball
    ptc_update @buffer(0)
loop until inkey$ = chr$(27)
end

sub setupfireball
dim r,g,b'dim r = 255,g = 255,b = 255
dim u,d,l
dim xd as double,yd as double
for i = 0 to 255
    if i <= 85 then
        r = i * 3
        g = i * 1.5
    elseif i <= 170 then
        i2 = i - 85
        g = 127 + (i2 * 1.5)
        b = i2 * 1.5
    else
        i2 = i - 170
        b = 127 + (i2 * 1.5)
    end if
'    if i <= 72 then
'        r = r - 3
'        g = r
'        b = r
'    else
'        r = r + 4
'        g = g + 2
'        b = b + 1
'    end if
'    if r < 0 then r = 0
'    if g < 0 then g = 0
'    if b < 0 then b = 0
'    if r > 255 then r = 255
'    if g > 255 then g = 255
'    if b > 255 then b = 255
    pal(i) = (r shl 16) + (g shl 8) + b
next i
for y = 0 to 126
    for x = 0 to 127
        cmap(x,y) = rnd * 5.0
    next x
next y
'for i = 0 to 1
    for y = 0 to 126
        u = (y - 1) and 127
        d = (y + 1) and 127
        for x = 0 to 127
            l = (x - 1) and 127
            r = (x + 1) and 127
            cmap(x,y) = (cmap(l,y) + cmap(r,y) + cmap(x,u) + cmap(x,d)) shr 2
        next x
    next y
'next i
for y = 0 to (scrh shl 1) - 1
    yd = cdbl(y - scrh)
    for x = 0 to (scrw shl 1) - 1
        xd = cdbl(x - scrw)
        dmap(x,y) = sqr(xd * xd + yd * yd)
        amap(x,y) = atan2(yd,xd)
    next x
next y
end sub

sub fireball
dim ox,oy,cmy,u,d,l,r,c
dim an as double,s as double,dis as double
an = cdbl(cmapy) / 128.0 * 6.28 * .2
s = 1.25 + cos(an * .43)
fbox = (scrw shr 1) + (sin(an) * (scrw * .3))
fboy = (scrh shr 1) + (sin(an * .67) * (scrh * .28))
ox = scrw - fbox
oy = scrh - fboy
for i = 0 to 127
    tex(i,127) = 255'rnd * 255
next i
for y = 1 to 126
    u = (y - 1) and 127
    d = (y + 1) and 127
    cmy = (cmapy + y) and 127
    for x = 0 to 127
        l = (x - 1) and 127
        r = (x + 1) and 127
        c = ((tex(l,y) + tex(r,y) + tex(x,u) + tex(x,d)) shr 2) - cmap(x,cmy)
        if c < 0 then c = 0
        tex(x,y) = c
        tex(x,y - 1) = c
    next x
next y
for y = 0 to scrh - 1
    yi = y * scrw
    for x = 0 to scrw - 1
        dis = dmap(ox + x,oy + y) * s
        if dis < 0 or dis > 127.0 then
            buffer(yi + x) = pal(0)
        else
            buffer(yi + x) = pal(tex(((amap(ox + x,oy + y) + an) * 81.52) and 127,127 - cint(dis)))
        end if
    next x
next y
cmapy = cmapy + 1
end sub

Have fun, dudes.
http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: Simple Fireball Effect
« Reply #1 on: June 11, 2006 »
Cool looking effect, well done.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Simple Fireball Effect
« Reply #2 on: June 11, 2006 »
That's really nice Jake, fast too.
It looks a little bit like the one in the Sparks demo by Mandrixx. I like yours better tho because it's faster.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Optimus

  • DBF Aficionado
  • ******
  • Posts: 2456
  • Karma: 128
    • View Profile
    • Optimouse Demo Site
Re: Simple Fireball Effect
« Reply #3 on: June 11, 2006 »
Wow! That rockz!!! I always wanted to do this effect..
It actually reminds me one of the effects in this great software demo -> (http://www.pouet.net/prod.php?which=9128)

Greats!!!  :D
Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Simple Fireball Effect
« Reply #4 on: June 11, 2006 »
That's the Sparks demo :)
You should check out the Java version too.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: Simple Fireball Effect
« Reply #5 on: June 11, 2006 »
Woah, cool, what a great effect, good going   8)
Challenge Trophies Won:

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Simple Fireball Effect
« Reply #6 on: June 11, 2006 »
Very good and fast !
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Simple Fireball Effect
« Reply #7 on: June 12, 2006 »
Excellent - looks very realistic and smooth ! Keep it up !!!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Simple Fireball Effect
« Reply #8 on: October 14, 2007 »
Very nice indeed  8)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won: