GithubHelp home page GithubHelp logo

crashmax-dev / fireworks-js Goto Github PK

View Code? Open in Web Editor NEW
1.0K 7.0 77.0 3.92 MB

🎆 A simple fireworks library! Ready to use components available for React, Vue 3, Svelte, Angular, Preact, Solid, and Web Components.

Home Page: https://fireworks.js.org

License: MIT License

TypeScript 18.97% HTML 1.36% TypeScript 67.40% HTML 2.14% JavaScript 0.66% CSS 4.00% Svelte 3.25% Vue 2.23%
fireworks animation canvas javascript typescript library react npm-package preact angular

fireworks-js's Introduction

A simple fireworks library! | fireworks.js.org

GitHub Workflow Status GitHub npm npm npm bundle size


Table of Contents

Warning
This readme refers to upcoming v2 version, read here for v1 documentation.

Features

Browsers support

IE / Edge
Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
iOS Safari
iOS Safari
Opera
Opera
Yandex
Yandex

Demo

You can play with fireworks-js at fireworks.js.org or codesandbox.io

Installation

npm install fireworks-js
yarn add fireworks-js
pnpm add fireworks-js
Package Status Description
fireworks-js Vanilla JS
@fireworks-js/react React component
@fireworks-js/preact Preact component
@fireworks-js/solid Solid component
@fireworks-js/vue Vue 3 component
@fireworks-js/svelte Svelte component
@fireworks-js/angular Angular component
@fireworks-js/web Web components

CDN

<!-- jsDelivr  -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/index.umd.js"></script>

<!-- UNPKG -->
<script src="https://unpkg.com/[email protected]/dist/index.umd.js"></script>

<!-- Usage -->
<script>
  const container = document.querySelector('.fireworks')
  const fireworks = new Fireworks.default(container)
  fireworks.start()
</script>

Usage

import { Fireworks } from 'fireworks-js'

const container = document.querySelector('.container')
const fireworks = new Fireworks(container, { /* options */ })
fireworks.start()

Edit @fireworks-js/react

npm install @fireworks-js/react

Edit @fireworks-js/react

npm install @fireworks-js/preact
npm install @fireworks-js/solid
npm install @fireworks-js/vue
npm install @fireworks-js/svelte
npm install @fireworks-js/angular
npm install @fireworks-js/web

Documentation

Options

Note
The options is optional, as are each of its properties.

Property Type Default
hue object hue
rocketsPoint object rocketsPoint
mouse object mouse
boundaries object boundaries
sound object sound
delay object delay
brightness object brightness
decay object decay
lineWidth object lineWidth
lineStyle string round
explosion number 5
opacity number 0.5
acceleration number 1.05
friction number 0.95
gravity number 1.5
particles number 50
traceLength number 3
flickering number 50
intensity number 30
traceSpeed number 10
intensity number 30
autoresize boolean true

The hue, delay, decay, brightness, lineWidth.explosion, lineWidth.trace, sound.volume and rocketsPoint options accept an object:

Property Type
min number
max number

Note
The min and max properties are used to randomly select values from the range.

The mouse options accept an object:

Property Type Default
click boolean false
move boolean false
max number 1

Note
The max property has no effect if click is false.

The sound options accept an object:

Property Type Default
enabled boolean false
files string[] files
volume object volume
const fireworks = new Fireworks(container, {
  autoresize: true,
  opacity: 0.5,
  acceleration: 1.05,
  friction: 0.97,
  gravity: 1.5,
  particles: 50,
  traceLength: 3,
  traceSpeed: 10,
  explosion: 5,
  intensity: 30,
  flickering: 50,
  lineStyle: 'round',
  hue: {
    min: 0,
    max: 360
  },
  delay: {
    min: 30,
    max: 60
  },
  rocketsPoint: {
    min: 50,
    max: 50
  },
  lineWidth: {
    explosion: {
      min: 1,
      max: 3
    },
    trace: {
      min: 1,
      max: 2
    }
  },
  brightness: {
    min: 50,
    max: 80
  },
  decay: {
    min: 0.015,
    max: 0.03
  },
  mouse: {
    click: false,
    move: false,
    max: 1
  }
})

API

.start()

Start fireworks.

.launch(count)

Launching a specified number of fireworks.
Type: number
Default 1

.stop(dispose)

Stop fireworks.
Type: boolean
Default: false

.waitStop(dispose)

Asynchronous stopping of the fireworks.
Type: boolean
Default: false

.pause()

Start/stop fireworks.

.clear()

Cleaning the canvas from fireworks.

.currentOptions

Getting current fireworks options.

.updateOptions(options)

Force update fireworks options.
Type: options

.updateSize(sizes)

Force update canvas size.
Type: sizes

.updateBoundaries(boundaries)

Force update canvas boundaries.
Type: boundaries

Community

Star History

Star History Chart

Author

License

fireworks-js's People

Contributors

actions-user avatar crashmax-dev avatar cwbudde avatar dependabot[bot] avatar dineshsonachalam avatar gbale avatar hiwayne avatar kelvinsjk avatar sbnoone avatar sentisso avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

fireworks-js's Issues

How to make use of the API (start, waitStop) when using the Vue wrapper?

Issue

I'm using the Vue wrapper and there doesn't seem to be a way to start the fireworks in "stopped" mode, there is a "autostart" option that seems to be missing.

I'd like to use waitStop in order to have a graceful finish after a few seconds of fireworks.

Would really appreciate an example that makes use of Vue that showcases a start/waitStop flow.

Many thanks! Love your plugin!

event listeners not removed in unmount

looks like copy-paste error, why events added and not removed here?

unmount(): void {
window.removeEventListener('resize', this.windowResize)
this._canvas.addEventListener('mousedown', this.mouseDown)
this._canvas.addEventListener('mouseup', this.mouseUp)
this._canvas.addEventListener('mousemove', this.mouseMove)
}

Error: Module Not Found

Description

When I do ng serve in my project, it generates an error. My angular is version 13.3.0

Error message below:

./src/app/app.module.ts:42:0-82 - Error: Module not found: Error: Package path ./lib/ng-fireworks.module is not exported from package C:\Dev-world\new-website\node_modules\@fireworks-js\angular (see exports field in C:\Dev-world\new-website\node_modules\@fireworks-js\angular\package.json)

Error: node_modules/@fireworks-js/angular/lib/ng-fireworks.directive.d.ts:11:18 - error TS2314: Generic type 'ɵɵDirectiveDeclaration' requires 6 type argument(s).

11     static ɵdir: i0.ɵɵDirectiveDeclaration<FireworksDirective, "[ngFireworks], ng-fireworks", ["ngF

11     static ɵdir: i0.ɵɵDirectiveDeclaration<FireworksDirective, "[ngFireworks], ng-fireworks", ["ngFireworks"], { "options": "options"; }, {}, never, never, false>;

Does anyone know what the issue is?

Which package are you using?

@fireworks-js/angular

fireworks-js version

2.10.5

Browser

Chrome Version 114.0.5735.134 (Official Build) (64-bit)

If repeated, it does not work after the second time.

Description

const container = document.querySelector(".fireworks-container");
if (container) {
  const fireworks = new Fireworks(container, {
    acceleration: 1.0,
    delay: {
      min: 10,
      max: 100,
    },
    sound: {
      enabled: true,
      files: [
        "fireworks_0.mp3",
        "fireworks_1.mp3",
        "fireworks_2.mp3",
      ],
      volume: {
        min: 60,
        max: 80,
      },
    },
  });

  fireworks.start();
  setTimeout(() => {
    fireworks.stop();
  }, 10000);
}

If repeated, it does not work after the second time.
Sound is produced.

Which package are you using?

@fireworks-js/react

fireworks-js version

2.0.4

Browser

chrome latest

Make parameters independent of rendering speed

Several parameters (such as the decay time) are currently dependent on the rendering time. This means that the output is significantly different for a different frame rate. I.e. with 60 fps the rays decay earlier than with 30 fps (twice as fast). In fact it should take the time since the last rendering into account.

To do so, the additional 'timestamp' from the requestAnimationFrame call can be used. This must only be compared to the previous timestamp. The initial timestamp can be retrieved by using window.now

Cannot find module './sound' or its corresponding type declarations.

I have installed the latest version v1.1.1 in my angular project, I am facing the below error while building.

ERROR in node_modules/fireworks-js/dist/fireworks.d.ts:1:30 - error TS2307: Cannot find module './sound' or its corresponding type declarations.
Import { SoundOptions } from './sound';

angular-core: ^10.0.0
typescript: ~3.9.5

non-working boundaries after `2.10.0` update

Description

I came across one example in #90 that allowed to limit the boundaries of explosions.

I wanted to reproduce this "feature" in my project and it didn't seem to work. I then noticed that the working example uses version 2.9.0 and my non-working project was using the newest 2.10.2 version.
Then I figured out that some changes made in the 2.10.0 version broke the boundaries setting.

Working boundaries (2.9.0): https://codesandbox.io/s/fireworks-js-launch-2-9-0-5k1ypf?file=/src/index.ts
Non-working boundaries (2.10.0): https://codesandbox.io/s/fireworks-js-launch-2-10-0-zyxj43?file=/src/index.ts

The only difference in the above examples is the package version of fireworks-js in package.json.

Which package are you using?

fireworks-js

fireworks-js version

2.10.0

Browser

any

Graceful stop

Feature Proposal

Thanks for your work on this library! It's pretty cool.

When calling stop(), the effect is pretty abrupt: everything associated with the fireworks just suddenly disappears from the screen.
Instead, it would be nice to have "stop" mean more like what it does in real fireworks shows: no more rockets are launched, but the ones already in flight and the glowing particles already falling continue on course.

Motivation

I have fireworks going for only a limited time, and when they stop, it's a bit jarring.

Example

Now:

if(endAfterSeconds !== null) {
	await wait(endAfterSeconds*1000);
	fireworks.stop();
}

Future code could be the same with new behavior, or for better backwards compatibility:

if(endAfterSeconds !== null) {
	await wait(endAfterSeconds*1000);
	fireworks.stopLaunching();
        //The existing animations continue to be displayed, but no new fireworks are launched.
        //A startLaunching() function might resume.
}

Improve React component

We need to decide which is better pattern: props getters or custom hooks 🤔

So far i cannot give such conclusions...

React fireworks - no fireworks is showing

I tried the following implementation and I just get a black square with no fireworks showing up whatsoever. Any idea why ?

import { FireworksOptions } from "fireworks-js/dist/fireworks";
import { Fireworks } from "fireworks-js/dist/react";
import React, { CSSProperties } from "react";


const UserScoreScreen = ({
}: {
}) => {
  const options: FireworksOptions = {
    speed: 3,
  };
  const FireworksStyle: CSSProperties = {
    width: "400px",
    height: "400px",
    background: "#000",
    position: "absolute",
  };

  return (
    <>
      <div className="relative flex flex-col items-center h-full p-4 border-2 border-white border-opacity-30 bg-glassomorphism3 rounded-10">
        <div className="z-40">
          <Fireworks options={options} style={FireworksStyle} />
        </div>
      </div>
    </>
  );
};


export default UserScoreScreen;

Fireworks for limited amount of time

Feature Proposal

option 1: a variable in the options object to set the amount of seconds that the library will generate projectiles.
option 2: A function that when called will stop generating new projectiles.

the pause & stop function doesn't satisfy this because:

  • the pause function freezes the canvas instantly
  • the stop function clears the canvas instantly

the goal is to make the transition from fireworks all around to no fireworks seem natural.

Motivation

I want fireworks to blast for a limited amount of time. I have fireworks in the background of a cta/feature div.
By keeping the fireworks on indefinitely the screen looks very busy and is hard to read. But i like the attention it grabs in the beginning.

Example

const fireworks = new Fireworks(container,
                {
                    traceSpeed: 1,
                    acceleration: 1.01,
                    rocketsPoint: 25,
                    explosion: 3,
                    trace: 2,
                    delay: { min: 20, max: 30 },
                    generationMs: 5000 //5 seconds
                });

fireworks.start();

//option2
let stopped = false;
window.addEventListener('scroll', function() { //lets say fireworks is at the top of my page and i want to disable it on scrolling.
        if (!stopped){
                stopped = true;
                fireworks.stopGenerating(); 
        }
}

Error when building Next project

Due to the type imports in react.d.ts the project crashes when building Next project.
Works if import is done like this:
import type { FireworksOptions } from './fireworks';
instead of:
import { type FireworksOptions } from './fireworks';
I have TS version 4.4.4 and next 12.1.4

output as svg?

So nice and pretty project,i am very interesting with this can show up in a svg format?

Thanks so much!

About Firework Shapes

Feature Proposal

Thanks for this fun library, the fireworks look so pretty!

I was wondering if I could provide more firework shapes, such as circles, pentagrams, etc.
Even similar to fireworks in reality, they can show some simple text after they explode.

Motivation

No response

Example

No response

Fire function

Feature Proposal

Can you add a fire function, which will render a single firework at random position or specified position on the screen?

Motivation

No response

Example

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.