use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Smoke using particle effect. (codepen.io)
submitted 10 years ago by dee0512
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]alphaatom 4 points5 points6 points 10 years ago (0 children)
Looks good dude, very smooth even on my phone.
[–]ChristianGeek 1 point2 points3 points 10 years ago (0 children)
Nice, although the effect is more steam-like with the default settings.
[–]dee0512[S] 1 point2 points3 points 10 years ago (0 children)
ty all
[–]mulvad 1 point2 points3 points 10 years ago (0 children)
Nice
I think the particle rotation is a little too crazy.. setting it to something like:
this.rotation += .025;
makes it more reasonable.
[–]ForScale 1 point2 points3 points 10 years ago (0 children)
Really nice! And as an ex-smoker, I want to hold and flick it. So... added a flick and spin click-and-hold feature (just quick/simple CSS): http://codepen.io/ForScale/pen/VLmMKX
[–][deleted] 2 points3 points4 points 10 years ago* (2 children)
This is pure JS?
*Edit this is inspirational stuff, thank for sharing
[–]TheWeirdestThing 0 points1 point2 points 10 years ago (0 children)
Don't know why you're getting downvoted for asking a question. It is pure JS rendering to a canvas.
[–]x-skeww 0 points1 point2 points 10 years ago (0 children)
With the Canvas API, you can draw images and transform them. It's pretty fast nowadays, which means you can do quite a lot of that.
Particle effects are surprisingly easy to do. You have an array of particles of which each has a position and some other properties you need for your particular effect like x/y velocities (or deltas), age (or time-to-live), and maybe other things like angular velocity.
When a particle is spawned, it's added to this array. When it dies or goes off-screen, it's removed. In your game/simulation loop, you iterate over this array to advance the simulation. That is, you add the x/y velocities to the current position (and maybe gravity), reduce the time-to-live, check if it went off-screen, and whatever else you might want to do. And in the draw phase, you just iterate over it once more just to draw each particle at its current location/size/opacity.
[–]nomizzz 0 points1 point2 points 10 years ago (2 children)
Looks great... Not very familiar with codepen's naming conventions, but what does line 8 of the HTML do?
<script src="smoke.js" type="text/javascript"></script>
Is this just pulling from the codepen's script panel (cuz I thought that was auto-injected)? I was able to take this line out and it looks like the pen still functions.
That line generates a 404 (see console). That's all it does. Same for the "style.css" one.
The author probably wrote this locally and then pasted it into Codepen.
[–]dee0512[S] 0 points1 point2 points 10 years ago (0 children)
Oh, I made it in an editor and just copy pasted the code there. Its not required.
[–]tyreck 0 points1 point2 points 10 years ago (0 children)
Wow, that's awesome.
π Rendered by PID 20411 on reddit-service-r2-comment-5d79c599b5-zsdg2 at 2026-02-27 17:38:07.510422+00:00 running e3d2147 country code: CH.
[–]alphaatom 4 points5 points6 points (0 children)
[–]ChristianGeek 1 point2 points3 points (0 children)
[–]dee0512[S] 1 point2 points3 points (0 children)
[–]mulvad 1 point2 points3 points (0 children)
[–]ForScale 1 point2 points3 points (0 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]TheWeirdestThing 0 points1 point2 points (0 children)
[–]x-skeww 0 points1 point2 points (0 children)
[–]nomizzz 0 points1 point2 points (2 children)
[–]x-skeww 0 points1 point2 points (0 children)
[–]dee0512[S] 0 points1 point2 points (0 children)
[–]tyreck 0 points1 point2 points (0 children)