I found this great script to make it rain confetti: http://jsfiddle.net/hcxabsgh/ Note how the particles have this twist/turn/skew-effect to make it feel more natural.
I have been trying to make the particles round which also works nicely: http://jsfiddle.net/rqr9hb7x/2/
But i can't get the particles to twist/turn/skew around their axes like in the rectangular example.
I figured it should be doable with ctx.setTransform(), since it handles skew-parameters, but it seems to skew the whole canvas instead of the single particle. Anyone an idea on how to approach this properly?
this.draw = function () {
ctx.beginPath();
ctx.save();
//ctx.setTransform(1, 0, 0, 1, 0, 0); // straigt
ctx.setTransform(1, .3, 0, .7, 0, 0); // skewed - to make dynamic
ctx.arc(this.x + this.tilt, this.y + this.tilt + (this.r / 4), (this.r / 2), 0, Math.PI * 2, false);
ctx.restore();
ctx.fillStyle = this.color;
return ctx.fill();
}
Skew using
setTransform
You want to rotate the particles local x axis over time. The x axis is the first two arguments of
setTransform
. To rotate that axis over time you usecos(angle)
andsin(angle)
to set the x and y component of the x axis.As you want that to be local to the particle you need to also set the particle origin (point of rotation) and then draw the particle at 0,0. The origin is the last two arguments of
setTransform
The draw function you want is
Example
Looking at the code at the fiddle given, i could not work out what they were trying to do as it was way over complicated, so I rewrote the whole thing which now takes a 3rd as much code and no jQuery.
Run demo for the FX you are after...
maybe????