New 2.0.2 smoke
4 posts • Page 1 of 1
New 2.0.2 smoke
- 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...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: New 2.0.2 smoke
Cool.
For high quality, toggling anti-aliasing ON in option menu is required.

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).
Hi, Algodoo lovers. Have you read next topic? Featured scenes suggestions
To translators: English.cfg changelog will be useful (even for me).
-
tatt61880 - [Most Helpful Person 2010]
- Posts: 1150
- Joined: Mon Aug 31, 2009 5:45 pm
- Location: Tokyo, Japan
Re: New 2.0.2 smoke
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...
-
Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: New 2.0.2 smoke
Nicely done, Kilinich.
Did someone say something about adding fire to go along with the smoke?
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
in any random geom, on a black background.
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...
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.
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.
-
Someone Else - Posts: 1147
- Joined: Sun Nov 21, 2010 10:53 pm
- Location: The Milky Way Galaxy
4 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 4 guests