Smoke engine
Author |
Message |
Insectoid

|
Posted: Thu Jan 22, 2009 6:48 pm Post subject: Smoke engine |
|
|
So, I wrote this little smoke simulation. It's based on (SNIPERDUDE?)'s particle engine tutorial. For the first 15 or so seconds it looks rather bad, but after that it looks the way it is supposed to. You'll notice when the chaff is gone and it's going right. I know why it does that, but I was too lazy to fix it. I also tried to add in fire, but got bored and left it with smoke. I also tried to do wind, but once again, I got bored. Really, it was done with the smoke. I tried a little to make it adaptable to other programs, with an 'animate' procedure that could be called and whatnot, but got stuck in a very long loop (nested for loops can take forever to execute).
Turing: |
View.Set ("offscreenonly")
%colorback (blue)
const MaxParticles := 10000
const smokelength := 1000
const MaxFire := 500
var smokeX := 200
const smokeWidth := 1
const FireX := 200
var smokeVel := 1
const MaxHeight := 350
const FireHeight := 50
const ListX := . 01
var doWind := false
type Particle_Type : %declare type
record
x, y, speed : int
col : int
list : real
maxY : int
end record
var Particles : array 1 .. MaxParticles of Particle_Type %declare array of type that you've made
var fireParticles : array 1 .. MaxFire of Particle_Type
for i : 1 .. MaxParticles % give particles their initial x,y value
Particles (i ).x := Rand.Int (smokeX, smokeX + smokeWidth ) %randmize the x position
Particles (i ).y := Rand.Int (0 - MaxHeight, 0) %randmize the y position
Particles (i ).speed := Rand.Int (1, 3) %randmize the y position
Particles (i ).col := Rand.Int (15, 31)
Particles (i ).list := 0
Particles (i ).maxY := Rand.Int (1, MaxHeight )
end for
for i : 1 .. MaxFire
fireParticles (i ).x := Rand.Int (FireX - 20, FireX + 20)
fireParticles (i ).y := Rand.Int (0, FireHeight )
fireParticles (i ).speed := Rand.Int (1, 3)
fireParticles (i ).col := Rand.Int (38, 43)
fireParticles (i ).maxY := Rand.Int (1, FireHeight )
end for
/*
proc Wind (windX, windY : int)
for i : 1 .. MaxParticles
if Particles (i).y > windY - 50 and Particles (i).y < windY + 50 and doWind = true then
Particles (i).x += windX * Rand.Int (abs (windY - Particles (i).y) div 5, (abs (windY - Particles (i).y) +10) div 5)
Particles (i).y += Rand.Int (-5, 5)
end if
end for
end Wind
*/
proc Animate
for x : 1 .. MaxParticles
smokeX + = smokeVel
cls %clear the screen
/*if Rand.Int (1, 100) = 100 and doWind = false then
doWind := true
end if
if Rand.Int (1, 20) = 20 and doWind = false then
doWind := false
end if*/
for i : 1 .. MaxParticles %inside this loop we go through all the particles 1 by 1
Particles (i ).y + = Particles (i ).speed %move down the drop of rain
if Particles (i ).y >= Particles (i ).maxY then %if drop of rain has fallen to the ground, reset it's values
Particles (i ).y := 0 %set it's y location back to the top again
Particles (i ).x := Rand.Int (smokeX, smokeX + smokeWidth ) %randmize the x position of rain droplets from 0 to maxx
Particles (i ).speed := Rand.Int (1, 3) %randmize the speed of drops rain
Particles (i ).col := Rand.Int (15, 31)
Particles (i ).list := 0
end if
Particles (i ).x + = Rand.Int (- 1, 1)
Draw.Dot (round (Particles (i ).x ), Particles (i ).y, Particles (i ).col ) %draw the drop of rain
Particles (i ).list + = ListX
end for
/* for i : 1 .. MaxFire
fireParticles (i).y += fireParticles (i).speed
fireParticles (i).x += Rand.Int (Particles (i).x - FireX mod 2, parti)
if fireParticles (i).y >= FireHeight then
fireParticles (i).y := 0
fireParticles (i).x := Rand.Int (FireX - 20, FireX + 20)
fireParticles (i).speed := Rand.Int (1, 3)
fireParticles (i).col := Rand.Int (38, 43)
end if
Draw.Dot (fireParticles (i).x, fireParticles (i).y, fireParticles (i).col)
end for*/
View.Update
if smokeX > smokeWidth or smokeX < 50 then
smokeVel * = - 1
end if
%Wind (300, 1)
%delay (100)
%View.Update
end for
end Animate
loop
Animate
end loop
|
Tell me what you think! I know, a lot of stuff has been left there that isn't used, but this was a spare time/'that would be cool' project. I'm currently working on a program that has a flexible line that bounces off walls. Sure, it's not a spring simulation, but it should look cool. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
saltpro15

|
Posted: Thu Jan 22, 2009 6:56 pm Post subject: RE:Smoke engine |
|
|
cool, I made one of these once, they turn out better if the background color is black, just a thought, yours is cool though  |
|
|
|
|
 |
Insectoid

|
Posted: Thu Jan 22, 2009 7:22 pm Post subject: RE:Smoke engine |
|
|
Black smoke on a black background? I guess it could hide the blemishes better... |
|
|
|
|
 |
saltpro15

|
Posted: Thu Jan 22, 2009 8:33 pm Post subject: RE:Smoke engine |
|
|
i had grey smoke, my bad  |
|
|
|
|
 |
A.J

|
Posted: Thu Jan 22, 2009 8:58 pm Post subject: Re: Smoke engine |
|
|
very well don insectoid....although there is one thing that could make your smoke a bit more realistic : make the particles close into each other.
I think that this will make it look a bit more realistic, but that's just me
very good job though, I really like your coding convention  |
|
|
|
|
 |
bigone150
|
Posted: Thu Apr 23, 2009 7:31 am Post subject: RE:Smoke engine |
|
|
Hey Insectoid amazing smoke there, i wanted to know if you could help me for a code for my rocket? If you would like to see the coding of the rocket and how wide it is go to http://compsci.ca/v3/viewtopic.php?p=184061&no=1#184061 |
|
|
|
|
 |
DanTheMan
|
Posted: Fri May 15, 2009 9:01 am Post subject: RE:Smoke engine |
|
|
This is kind of nice, but is there a way to make the fire red at the base, and turning into black smoke at the top? |
|
|
|
|
 |
|
|