New 2.0.2 smoke

About advanced scenes, and the Thyme scripting language used in Algodoo.

New 2.0.2 smoke

Postby Kilinich » Fri Nov 30, 2012 1:11 am

Rating: rated 6.6
Filesize: 190.64 kB
Comments: 4
Ratings: 5
download


Code: Select all
scene.my.addSmoke = (sPos,sVel,fromSize,toSize,sColor,fadeTime) => {geval("scene.addCircle({pos := "+sPos+"; vel := "+sVel+"; radius := {"+0.5*fromSize+" + ("+0.5*(toSize - fromSize)/fadeTime+" * (sim.time - "+sim.time+"))}; color := {["+sColor(0)+","+sColor(1)+","+sColor(2)+", "+sColor(3)+"*(1 - (sim.time - "+sim.time+") / "+fadeTime+")]}; drawBorder := false; drawCake := false; density := {sim.time > "+(sim.time + fadeTime)+" ? 0 : 0.01}; collideSet := 0; collideWater := false; airFrictionMult = 0; edgeBlur := {entity.radius/4}})")}
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: New 2.0.2 smoke

Postby tatt61880 » Fri Nov 30, 2012 3:58 pm

Cool. :thumbup:
For high quality, toggling anti-aliasing ON in option menu is required. ;)
NOTE: I'm not an Algoryx member.
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
User avatar
tatt61880
[Most Helpful Person 2010]
 
Posts: 1150
Joined: Mon Aug 31, 2009 5:45 pm
Location: Tokyo, Japan

Re: New 2.0.2 smoke

Postby Kilinich » Thu Feb 21, 2013 9:30 am

For 2.1+ it's even simpler (no geval, using timeToLive):

Code: Select all
scene.my.addSmoke = (sPos, sVel, fromSize, toSize, sColor, fadeTime) => {
  scene.addCircle({
    _fadeTime := fadeTime; timeToLive := fadeTime;
    _fromSize := fromSize; _toSize := toSize;
    _color := sColor; color := {_Color * [1,1,1, timeToLive / _fadeTime]};
    radius := {_toSize + (_fromSize - _toSize)/_fadeTime * timeToLive};
    edgeBlur := {radius/4};
    pos := sPos; vel := sVel;
    drawBorder := false; drawCake := false;
    density := 0.01; collideSet := 0; collideWater := false; airFrictionMult = 0;
  })
}
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: New 2.0.2 smoke

Postby Someone Else » Sat May 18, 2013 9:23 am

Nicely done, Kilinich.

Did someone say something about adding fire to go along with the smoke?
Code: Select all
scene.my.addFlame = (fPos, fVel, fromSize, toSize, fColor, fadeTime) => {
  scene.addCircle({
    _fadeTime := fadeTime; timeToLive := fadeTime;
    _fromSize := fromSize; _toSize := toSize;
    _color := fColor; color := {
      N = 3 * timeToLive / _fadeTime;
      _Color * [{N > 1} ? {1} : {N}, {N > 2} ? {1} : {N > 1} ? {N - 1} : {0}, {N > 2} ? {N - 2} : {0}, N / 3]
    };
    radius := {_toSize + (_fromSize - _toSize)/_fadeTime * timeToLive};
    edgeBlur := {radius/4};
    pos := fPos; vel := fVel;
    drawBorder := false; drawCake := false;
    density := 0.01; collideSet := 0; collideWater := false; airFrictionMult = 0;
  })
}

This code seems to work well if fColor is white- that way, the flame transitions from white, to yellow, to red. Other colors will work as well, but you'll wind up with a different (and perhaps less realistic) color of flame.
Keep in mind that as the flame fades, only one of the red, green, or blue channels will decrease at a time- blue first, then green, then red.
I've also found that plugging in sine or cosine functions of time for the velocity will result in a more realistic, flickery effect.
As an example of usage, try
Code: Select all
postStep = (e)=>{scene.my.addFlame(pos, [3 * math.sin(sim.time * 5), 10 + (2 * math.cos(sim.time * 4))], 1, 5, [1, 1, 1, 0.1], 1)}

in any random geom, on a black background.
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests