Author Topic: Automatic Lava  (Read 3362 times)

0 Members and 1 Guest are viewing this topic.

docgen

  • Guest
Automatic Lava
« on: March 28, 2007 »

Hi!

Just another testcode to become more familiar with FB!

It's a "lavapainter" :)

Code needs FB 0.17 !
or download exe

use LMB; RMB; MMB or spacekey


Code: [Select]
' Automatic Lava
' by stef
   
    OPTION STATIC
    OPTION EXPLICIT

    CONST MAXPARTICLES=1000
   
    CONST SCREENW=800
    CONST SCREENH=600
   
 
declare sub initparticles()
declare sub deleteparticles()
declare sub calcparticles()
declare sub drawparticles()
declare sub createcolours()
 
dim shared grav as single =0.001
dim shared posx as integer
dim shared posy as integer
dim shared buttons as integer

dim shared col as integer
dim shared col_red as integer =255
dim shared col_green as integer
dim shared col_blue as integer=0
dim shared colfactor as integer =5 ' only: 1; 5; 15
     
dim shared counter as integer


dim shared cd as integer=MAXPARTICLES
dim shared size as integer =50 '*2
dim shared a as integer
   
type tparticles
    exist as integer
    x as single 
    y as single
    dx as single 
    dy as single
    angle as single
    speed as single
end type

dim shared particle(MAXPARTICLES) as tparticles
   
    SCREEN 19, 16, 2, 1
   
    SCREENSET 1, 0

    RANDOMIZE TIMER

 Dim shared screenim As Byte Ptr
    screenim = Imagecreate(Screenw,screenh,rgb(0,0,0))
   
  Dim shared maskim As Byte Ptr
    maskim = Imagecreate(Screenw,screenh,rgb(0,0,0)) 

   
   Dim shared phim As Byte Ptr
    phim = Imagecreate(size*2,size*2)
   
    for a = size-1 to 10 step-1
       Circle phim,(size,size),a,RGB((255-5*a),(255-5*a),(255-5*a)),,,,F       
    next
 
DO
 
    GETMOUSE posx, posy,, buttons
   
 
        IF Bit(buttons, 0) THEN
            initparticles()
           
        endif
         IF Bit(buttons, 1) THEN
            deleteparticles()
           
        endif
         IF Bit(buttons, 2) or multikey(&h39) THEN
            createcolours()
           
        endif
 
    calcparticles()
         
    drawparticles()
   
   put (0,0),screenim,pset
   
       
    locate 1,1,0
    print " press LMB= more lava; press RMB= less lava; press MMB or SPACE= change colours"
   
   
    SCREENCOPY
 
LOOP UNTIL INKEY$=CHR$(27)

imagedestroy screenim
imagedestroy maskim
imagedestroy phim

end


sub initparticles()

     if particle(counter).exist=0 then
        particle(counter).exist=1
   
        particle(counter).x=posx
        particle(counter).y=posy
        particle(counter).angle=(Rnd*360)*0.017453293
        particle(counter).speed=Rnd*3+0.1
        particle(counter).dx=sin(particle(counter).angle)*particle(counter).speed
        particle(counter).dy=cos(particle(counter).angle)*particle(counter).speed
       
      endif     
        counter=counter+1
        if counter> MAXPARTICLES then counter=0
   
end sub

sub deleteparticles()
  static cd as integer
   
       if particle(counter).exist=1 then
        particle(counter).exist=0
       endif     
    counter=counter-1
   
    if counter<0  then counter=0
 
end sub

sub calcparticles()
   
    dim x as integer
   
   
    for x= 0 to MAXPARTICLES
       
        if particle(x).exist=1 then
            particle(x).x=particle(x).x+particle(x).dx
            particle(x).y=particle(x).y+particle(x).dy
            particle(x).dy=particle(x).dy+grav
           
            if particle(x).x< 0 then particle(x).dx=-particle(x).dx
            if particle(x).x> SCREENW then particle(x).dx=-particle(x).dx
            if particle(x).y< 0 then particle(x).dy=-particle(x).dy
            if particle(x).y> SCREENH+size then particle(x).dy=-particle(x).dy
         endif
    next

end sub

sub drawparticles()
    dim x as integer
   
    line screenim,(0,0)-(800,600),rgb(0,0,0),BF
    line maskim,(0,0)-(800,600),rgb(col_red,col_green,col_blue),BF
   
    for x= 0 to MAXPARTICLES
       
        if particle(x).exist=1 then
             put screenim,(particle(x).x-size,particle(x).y-size),phim,add,150
        endif
    next
   
    put screenim,(0,0),maskim,and
 
end sub

sub createcolours()
    If col_red<255 And col_green =0 And col_blue =255 Then col_red=col_red+colfactor
    If col_red=255 And col_green=0 And col_blue >0 Then col_blue=col_blue-colfactor
    If col_red=255 And col_green < 255 And col_blue =0 Then col_green=col_green+colfactor
    If col_red>0 And col_green = 255 And col_blue =0 Then col_red=col_red-colfactor
    If col_red=0 And col_green = 255 And col_blue <255 Then col_blue=col_blue+colfactor
    If col_red=0 And col_green >0 And col_blue =255 Then col_green=col_green-colfactor
end sub







Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Automatic Lava
« Reply #1 on: March 28, 2007 »
Excellent version of the classic metaballs effect Stef :)

Have some Karma!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Automatic Lava
« Reply #2 on: March 28, 2007 »
Very good, Stef!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline rdc

  • Pentium
  • *****
  • Posts: 1495
  • Karma: 140
  • Yes, it is me.
    • View Profile
    • Clark Productions
Re: Automatic Lava
« Reply #3 on: March 29, 2007 »
Nice.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Automatic Lava
« Reply #4 on: March 29, 2007 »
Does what it says on the tin!  Nice!

Jim
Challenge Trophies Won:

Offline ferris

  • Pentium
  • *****
  • Posts: 841
  • Karma: 84
    • View Profile
    • Youth Uprising Home
Re: Automatic Lava
« Reply #5 on: March 29, 2007 »
Hey, that's cool!

Good job.
http://iamferris.com/
http://youth-uprising.com/

Where the fun's at.
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Automatic Lava
« Reply #6 on: March 29, 2007 »
Good one :D
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Tetra

  • DBF Aficionado
  • ******
  • Posts: 2532
  • Karma: 83
  • Pirate Monkey!
    • View Profile
Re: Automatic Lava
« Reply #7 on: March 29, 2007 »
I like that, its quite mezmorising  :goodpost:
Challenge Trophies Won: