Skip to content

Allows tilt and wobble control, solving issue #244#250

Open
QGRRK wants to merge 1 commit intocatdad:masterfrom
QGRRK:feat/244-expose-tilt-wobble
Open

Allows tilt and wobble control, solving issue #244#250
QGRRK wants to merge 1 commit intocatdad:masterfrom
QGRRK:feat/244-expose-tilt-wobble

Conversation

@QGRRK
Copy link

@QGRRK QGRRK commented May 3, 2025

Expose tilt & wobble parameters for finer animation control, solving issue #244

This PR adds four new options that let callers tune particle orientation and path wobble:

Option Unit / type What it does Default (keeps 1.x look)
tiltRange [min,max] radians Initial tilt angle [-Math.PI/2, Math.PI/2]
tiltSpeed [min,max] rad ∙ tick⁻¹ Tilt speed over time [0.05, 0.4]
wobbleRange [min,max] px Wobble radius [5, 10]
wobbleSpeed [min,max] rad ∙ tick⁻¹ Wobble angular velocity [0.1, 0.2]

No code changes are required for existing users; omitted fields keep current behaviour, and flat: true still disables all 3‑D motion.


Quick example

confetti({
  particleCount : 40,
  tiltRange     : [-Math.PI/4, Math.PI/4],
  tiltSpeed     : [0.05, 0.1],
  wobbleRange   : [3, 8],
  wobbleSpeed   : [0.05, 0.15]
});

Implementation highlights

  1. defaults extended with the four ranges.

  2. randomPhysics() now pulls values from those ranges (or defaults) and stores wobble, wobbleSpeed, tiltAngle, tiltIncrement on each particle.

  3. updateFetti() uses those fields instead of hard‑coded constants.

Tests

Back‑compat visual suite – all legacy tests still green.

Motion test – freezes velocity & gravity, fires one particle, captures two frames 100 ms apart, asserts centroid moved ≥ 8 px while palette stayed the same.

Parameter presence test – with front end testing, confirms particles receive the exact wobble/tilt values passed in.

Copy link

@puffcocos puffcocos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed this feature as well! Glad to see this PR.

//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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this line might override the new tiltAngle.

scalar: 1
scalar: 1,
/* New feature 3-D wobble/tilt control */
tiltRange: [-Math.PI * 0.5, Math.PI * 0.5], // [min,max] radians

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original canvas-confetti tiltAngle calculation logic:

tiltAngle: (Math.random() * (0.75 - 0.25) + 0.25) * Math.PI
// Result: 0.25π ~ 0.75π (45° ~ 135°)

The current PR's default value is -90° ~ 90°, but to maintain the original behavior, I think it should be 45° ~ 135°.

Suggestion:

tiltRange: [Math.PI * 0.25, Math.PI * 0.75] 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants