Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions src/confetti.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,12 @@
],
// probably should be true, but back-compat
disableForReducedMotion: false,
scalar: 1
scalar: 1,
/* New feature 3-D wobble/tilt control */
tiltRange: [-Math.PI * 0.5, Math.PI * 0.5], // [min,max] radians
tiltSpeed: [0.05, 0.40], // radians per frame
wobbleRange:[0,10], // “radius” units
wobbleSpeed:[0.05,0.11] // per-frame
};

function convert(val, transform) {
Expand Down Expand Up @@ -342,8 +347,13 @@
return {
x: opts.x,
y: opts.y,
wobble: Math.random() * 10,
wobbleSpeed: Math.min(0.11, Math.random() * 0.1 + 0.05),
//New 3-D wobble/tilt control
wobble: Math.random() * (opts.wobbleRange[1] - opts.wobbleRange[0]) + opts.wobbleRange[0],
wobbleSpeed: Math.random() * (opts.wobbleSpeed[1] - opts.wobbleSpeed[0]) + opts.wobbleSpeed[0],
tiltAngle: Math.random() * (opts.tiltRange[1] - opts.tiltRange[0]) + opts.tiltRange[0],
tiltIncrement: Math.random() * (opts.tiltSpeed[1] - opts.tiltSpeed[0]) + opts.tiltSpeed[0],
//wobble: Math.random() * 10,
//wobbleSpeed: Math.min(0.11, Math.random() * 0.1 + 0.05),
velocity: (opts.startVelocity * 0.5) + (Math.random() * opts.startVelocity),
angle2D: -radAngle + ((0.5 * radSpread) - (Math.random() * radSpread)),
tiltAngle: (Math.random() * (0.75 - 0.25) + 0.25) * Math.PI,
Expand Down Expand Up @@ -378,12 +388,15 @@
fetti.tiltSin = 0;
fetti.tiltCos = 0;
fetti.random = 1;
// New 3-d wobble/tilt control
fetti.tiltIncrement = 0;
} else {
fetti.wobble += fetti.wobbleSpeed;
fetti.wobbleX = fetti.x + ((10 * fetti.scalar) * Math.cos(fetti.wobble));
fetti.wobbleY = fetti.y + ((10 * fetti.scalar) * Math.sin(fetti.wobble));

fetti.tiltAngle += 0.1;
//fetti.tiltAngle += 0.1;
fetti.tiltAngle += (fetti.tiltIncrement || 0.1);
fetti.tiltSin = Math.sin(fetti.tiltAngle);
fetti.tiltCos = Math.cos(fetti.tiltAngle);
fetti.random = Math.random() + 2;
Expand Down Expand Up @@ -569,6 +582,13 @@
var shapes = prop(options, 'shapes');
var scalar = prop(options, 'scalar');
var flat = !!prop(options, 'flat');

// NEW 3-D wobble/tilt control
var tiltRange = prop(options, 'tiltRange');
var tiltSpeed = prop(options, 'tiltSpeed');
var wobbleRange = prop(options, 'wobbleRange');
var wobbleSpeed = prop(options, 'wobbleSpeed');

var origin = getOrigin(options);

var temp = particleCount;
Expand All @@ -592,7 +612,12 @@
gravity: gravity,
drift: drift,
scalar: scalar,
flat: flat
flat: flat,
// NEW 3-D wobble/tilt control
tiltRange: tiltRange,
tiltSpeed: tiltSpeed,
wobbleRange: wobbleRange,
wobbleSpeed: wobbleSpeed
})
);
}
Expand Down