Skip to content

Commit

Permalink
✨ add launchSpeed prop
Browse files Browse the repository at this point in the history
  • Loading branch information
almond-bongbong committed Apr 18, 2023
1 parent a8c8974 commit 142bc5c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 34 deletions.
5 changes: 5 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const DEFAULT_OPTIONS = {
x: 0.5,
y: 0.5,
colors: ['#ff577f', '#ff884b', '#ffd384', '#fff9b0'],
launchSpeed: 1,
};

function App() {
Expand Down Expand Up @@ -57,6 +58,9 @@ function App() {
.onChange((v) => handleChangeOption('spreadDeg', v));
confetti.add(target, 'x', 0, 1).onChange((v) => handleChangeOption('x', v));
confetti.add(target, 'y', 0, 1).onChange((v) => handleChangeOption('y', v));
confetti
.add(target, 'launchSpeed', 0, 3)
.onChange((v) => handleChangeOption('launchSpeed', v));

const colors = gui.addFolder('Colors');
colors.open();
Expand Down Expand Up @@ -84,6 +88,7 @@ function App() {
x={options.x}
y={options.y}
colors={options.colors}
launchSpeed={options.launchSpeed}
/>
</div>
);
Expand Down
19 changes: 6 additions & 13 deletions lib/index.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/index.esm.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 6 additions & 13 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-confetti-boom",
"version": "0.0.1",
"version": "0.0.2",
"description": "A customizable React confetti explosion component for celebrations and special events",
"author": "almond-bongbong <bal.dongdongdong@gmail.com>",
"homepage": "https://github.com/almond-bongbong/react-confetti-boom",
Expand Down
10 changes: 5 additions & 5 deletions src/js/Particle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Particle {
this.width = shapeSize;
this.height = shapeSize;
this.theta = (Math.PI / 180) * randomNumBetween(deg - spread, deg + spread);
this.radius = randomNumBetween(20, 70);
this.radius = randomNumBetween(20 * launchSpeed, 70 * launchSpeed);
this.vx = this.radius * Math.cos(this.theta);
this.vy = this.radius * Math.sin(this.theta);
this.friction = 0.87;
Expand All @@ -55,19 +55,19 @@ class Particle {
this.colors[Math.floor(randomNumBetween(0, this.colors.length))],
);
this.shapes = shapes;
this.shape = this.shapes[Math.floor(randomNumBetween(0, this.shapes.length))];
this.shape =
this.shapes[Math.floor(randomNumBetween(0, this.shapes.length))];
this.swingOffset = randomNumBetween(0, Math.PI * 2);
this.swingSpeed = Math.random() * 0.05 + 0.01;
this.swingAmplitude = randomNumBetween(0, 0.4);

console.log(launchSpeed);
}

update() {
this.vx *= this.friction;
this.vy *= this.friction;
this.vy += this.gravity;
if (this.vy > 0) this.vx += Math.sin(this.swingOffset) * this.swingAmplitude;
if (this.vy > 0)
this.vx += Math.sin(this.swingOffset) * this.swingAmplitude;
this.x += this.vx;
this.y += this.vy;
this.opacity -= 0.004;
Expand Down

0 comments on commit 142bc5c

Please sign in to comment.