Skip to content

Conversation

TechnicalDree
Copy link

@TechnicalDree TechnicalDree commented May 3, 2025

Description:

This PR addresses Issue #183 by adding support for double-sided confetti rendering. The key addition is the enableDoubleSided option, which allows the front and back sides of confetti pieces to be rendered in different colors based on their tilt.

Changes Made:

  • enableDoubleSided (boolean): when true, the confetti will render with different front and back colors depending on the tilt direction.
  • frontColors (array): RGB color options for the front face of confetti.
  • backColors (array): RGB color options for the back face of confetti.

Rendering Update:

In the draw loop, the fillStyle is conditionally set to colorFront or colorBack based on the value of tiltCos when enableDoubleSided is true.

Example Configuration:

confetti({
  enableDoubleSided: true,
  frontColors: ['#4ddcff', '#ba74ff', '#ff7e95', '#aaff7a', '#fdff76', '#ffb84d', '#ff66ff'],
  backColors: ['#990099', '#b35900', '#bdbd00', '#5fbf3a', '#cc3f5e', '#6b36c2', '#1399cc']
});

Backward Compatibility:

  • If enableDoubleSided is not specified, the confetti will render using the existing colors option as before, ensuring backward compatibility.
  • disableForReducedMotion remains false by default to preserve the current behavior.

Added Unit Tests Under test/index.test.js (All Passing):

  • 'shoots double-sided confetti'
  • 'double-sided confetti falls back to main colors'
  • 'double-sided confetti works with default colors when front/back not specified'
Recording.2025-05-02.074406.mp4

@catdad

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.

3 participants