Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
alampros committed Jun 17, 2020
2 parents 1184141 + 5b8fe1e commit 52ce76a
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export default () => {
| `friction` | `Number` | 0.99 | |
| `wind` | `Number` | 0 | |
| `gravity` | `Number` | 0.1 | |
| `initialVelocityX` | `Number` | 4 | How fast confetti is emitted horizontally |
| `initialVelocityY` | `Number` | 10 | How fast confetti is emitted vertically |
| `initialVelocityX` | `Number | { min: Number, max: Number }` | 4 | Range of values between which confetti is emitted horizontally, positive numbers being rightward, and negative numbers being leftward. Giving a number `x` is equivalent to giving a range `{ min: -x, max: x }`. |
| `initialVelocityY` | `Number | { min: Number, max: Number }` | 10 | Range of values between which confetti is emitted vertically, positive numbers being downward, and negative numbers being upward. Giving a number `y` is equivalent to giving a range `{ min: -y, max: 0 }`.|
| `colors` | `String[]` | `['#f44336'`</br>`'#e91e63'`</br>`'#9c27b0'`</br>`'#673ab7'`</br>`'#3f51b5'`</br>`'#2196f3'`</br>`'#03a9f4'`</br>`'#00bcd4'`</br>`'#009688'`</br>`'#4CAF50'`</br>`'#8BC34A'`</br>`'#CDDC39'`</br>`'#FFEB3B'`</br>`'#FFC107'`</br>`'#FF9800'`</br>`'#FF5722'`</br>`'#795548']`</br> | All available Colors for the confetti pieces. |
| `opacity` | `Number` | 1.0 | |
| `recycle` | `Bool` | true | Keep spawning confetti after `numberOfPieces` pieces have been shown. |
Expand Down
4 changes: 2 additions & 2 deletions src/Confetti.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ export interface IConfettiOptions {
* How fast the confetti is emitted horizontally
* @default 4
*/
initialVelocityX: number
initialVelocityX: {min: number, max: number} | number
/**
* How fast the confetti is emitted vertically
* @default 10
*/
initialVelocityY: number
initialVelocityY: {min: number, max: number} | number
/**
* Array of colors to choose from.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Particle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export default class Particle {
this.w = randomRange(5, 20)
this.h = randomRange(5, 20)
this.radius = randomRange(5, 10)
this.vx = randomRange(-initialVelocityX, initialVelocityX)
this.vy = randomRange(-initialVelocityY, 0)
this.vx = typeof initialVelocityX === 'number' ? randomRange(-initialVelocityX, initialVelocityX) : randomRange(initialVelocityX.min, initialVelocityX.max)
this.vy = typeof initialVelocityY === 'number' ? randomRange(-initialVelocityY, 0) : randomRange(initialVelocityY.min, initialVelocityY.max)
this.shape = randomInt(0, 2)
this.angle = degreesToRads(randomRange(0, 360))
this.angularSpin = randomRange(-0.2, 0.2)
Expand Down
114 changes: 114 additions & 0 deletions stories/velocity-options.story.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import React from 'react'
import PropTypes from 'prop-types'
import useWindowSize from 'react-use/lib/useWindowSize'
import SizedConfetti from './SizedConfetti'
import { withKnobs, boolean, number } from '@storybook/addon-knobs'
import { storiesOf } from '@storybook/react'

const VelocityConfetti = (
{ numericX, initialVelocityX, initialVelocityXMin, initialVelocityXMax,
numericY, initialVelocityY, initialVelocityYMin, initialVelocityYMax,
...passedProps }
) => {
const { width, height } = useWindowSize()
return (
<SizedConfetti
width={width}
height={height}
confettiSource={{
w: 10,
h: 10,
x: width / 2,
y: height / 2,
}}
initialVelocityX={numericX ? initialVelocityX : { min: initialVelocityXMin, max: initialVelocityXMax }}
initialVelocityY={numericY ? initialVelocityY : { min: initialVelocityYMin, max: initialVelocityYMax }}
{...passedProps}
/>
)
}

VelocityConfetti.propTypes = {
numericX: PropTypes.bool.isRequired,
initialVelocityX: PropTypes.number.isRequired,
initialVelocityXMin: PropTypes.number.isRequired,
initialVelocityXMax: PropTypes.number.isRequired,
numericY: PropTypes.bool.isRequired,
initialVelocityY: PropTypes.number.isRequired,
initialVelocityYMin: PropTypes.number.isRequired,
initialVelocityYMax: PropTypes.number.isRequired,
}

storiesOf('Props|Demos', module)
.addDecorator(withKnobs)
.add('Initial Velocity Options', () => (
<VelocityConfetti
friction={1}
run={boolean('Run', true)}
recycle={boolean('Recycle', true)}
numberOfPieces={number('# Pieces', 200, {
range: true,
min: 0,
max: 2000,
step: 10,
})}
wind={number('Wind', 0, {
range: true,
min: -0.5,
max: 0.5,
step: 0.001,
})}
gravity={number('Gravity', 0.1, {
range: true,
min: -1,
max: 1,
step: 0.01,
})}
opacity={number('Opacity', 100, {
range: true,
min: 0,
max: 100,
step: 1,
}) / 100}
numericX={boolean('Numeric Initial X', true, 'Initial Velocity')}
numericY={boolean('Numeric Initial Y', true, 'Initial Velocity')}
initialVelocityX={number('Initial X: Numeric', 2, {
range: true,
min: 0,
max: 10,
step: 0.1,
}, 'Initial Velocity')}
initialVelocityXMin={number('Initial X: Range Min', -2, {
range: true,
min: -20,
max: 20,
step: 0.1,
}, 'Initial Velocity')}
initialVelocityXMax={number('Initial X: Range Max', 2, {
range: true,
min: -20,
max: 20,
step: 0.1,
}, 'Initial Velocity')}
initialVelocityY={number('Initial Y: Numeric', 5, {
range: true,
min: 0,
max: 20,
step: 0.1,
}, 'Initial Velocity')}
initialVelocityYMin={number('Initial Y: Range Min', -5, {
range: true,
min: -20,
max: 20,
step: 0.1,
}, 'Initial Velocity')}
initialVelocityYMax={number('Initial Y: Range Max', 0, {
range: true,
min: -20,
max: 20,
step: 0.1,
}, 'Initial Velocity')}
/>
), {
notes: 'Uses a custom `confettiSource` option to emit confetti from a small source in the center of the canvas.',
})
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12040,9 +12040,9 @@ websocket-driver@>=0.5.1:
websocket-extensions ">=0.1.1"

websocket-extensions@>=0.1.1:
version "0.1.3"
resolved "https://registry.yarnpkg.com/websocket-extensions/-/websocket-extensions-0.1.3.tgz#5d2ff22977003ec687a4b87073dfbbac146ccf29"
integrity sha512-nqHUnMXmBzT0w570r2JpJxfiSD1IzoI+HGVdd3aZ0yNi3ngvQ4jv1dtHt5VGxfI2yj5yqImPhOK4vmIh2xMbGg==
version "0.1.4"
resolved "https://registry.yarnpkg.com/websocket-extensions/-/websocket-extensions-0.1.4.tgz#7f8473bc839dfd87608adb95d7eb075211578a42"
integrity sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg==

whatwg-fetch@>=0.10.0:
version "3.0.0"
Expand Down

0 comments on commit 52ce76a

Please sign in to comment.