Skip to content

Commit da7a6aa

Browse files
authored
Merge pull request #18 from zarocknz/firework-designer
WIP: Firework designer
2 parents 6a4a862 + ad7ae43 commit da7a6aa

File tree

13 files changed

+1739
-236
lines changed

13 files changed

+1739
-236
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 DouG
3+
Copyright (c) 2017 Douglas McKechie.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,41 @@
22
Create fireworks on HTML canvas with Skyrocket.js
33

44
## Description
5-
Skyrocket.js is a JavaScript library which displays skyrocket fireworks on HTML canvas.
5+
Skyrocket.js is a JavaScript library which displays skyrocket fireworks on HTML canvas. Skyrockets launch from the bottom center of the screen, fly up, explode, then fade. There is a code generated background of a city skyline which is different each time the page is loaded. The message at the bottom center of the screen can easily be changed to fit the occasion.
66

7-
Skyrockets launch from the bottom center of the screen, fly up, explode, then fade.
7+
![Example](docs/img/Screenshot-Fireworks.png)
88

9-
Rocket properties are defined in rocket_definitions.js with rockets being picked at random.
9+
GreenSock's Animation Platform (GSAP) is used to power the rocket and explosion animations, the rest is plain JavaScript
10+
so you should be able to include this library in any web project you like.
1011

11-
Also there is a code generated background of a city skyline which is different each time the page is loaded.
12+
## Design your own Skyrockets!
13+
One of the big features of this library is that you can create your own skyrockets using the visual designer
1214

13-
GreenSock's Animation Platform (GSAP) is used to power the rocket and explosion animations.
15+
![Example](docs/img/Screenshot-Designer.png)
1416

15-
## Example
16-
For an example, load the included index.html file in your browser.
17+
This allows you to visually design the explosion shapes and set the animation properties, then click a button to generate the JSON config needed by the skyrocket.js to use these in the fireworks show.
18+
19+
Note: place the generated config in skyrockets/explosions.js
20+
21+
Open tools/designer.html to get creating your own skyrocket explosions or edit existing ones.
22+
23+
Another important file is skyrockets/colors.js which defines sets of colours used by the rockets. Add your own or adjust the existing colours by specifying the RGB values for the colours.
24+
25+
## How to use
26+
For an example of how to use this library, load the included index.html file in your browser.
27+
28+
A canvas must be included, along with the js files needed for the backdrop, skyrockets and their definition.
1729

1830
As you will see there is a function called addFirework() which is called repeatedly to spawn new fireworks at a random interval.
1931

32+
An explosion and colour are selected at random from those defined in skyrockets/colors.js and skyrockets/explosions.js
33+
34+
You could choose specific colours and explosions if desired to suit a particular occasion. You will likely need to create your own as well because there are only a small number of included types.
35+
2036
## Tutorials and other documentation
21-
Sorry, there are none at this time. Currently this library is in a alpha state with the inital 0.0.1 created during a hackday. Please look at the included index.html and other source code for what is required.
37+
Sorry, there are none at this time. Currently this library is in a alpha state with the initial 0.0.1 created during a hackday. Please look at the included index.html and other source code for what is required and to read the comments.
38+
39+
The visual designer in tools/designer.html should be pretty straightforward to use, just follow the on-screen instructions.
2240

2341
## Maintainer
2442
Douglas McKechie https://github.com/zarocknz
@@ -35,13 +53,13 @@ Special thanks to these people who collaborated with me on this during the hackd
3553
Also a big thank you to Catalyst http://www.catalyst.net.nz/ for having a hackday to celebrate 20 years and allowing us to get this open source library off off the ground.
3654

3755
## TODO
38-
Heaps, which may include the following (not in any particular order)...
39-
40-
* Define more and better firework explosion shapes and colours
41-
* Perhaps de-couple firework explosion shapes from the colours so users can pick a shape and specify any colour
42-
* Allow images to be used for the rockets
43-
* Add launch and explosion sounds, either pre-recorded or perhaps audio API generated
44-
* Allow explosion particles to have tails (will aid in creating different looking explosions)
45-
* Allow the user to specify where along the screen (x axis) the rocket launches from rather than always in the center, perhaps there is an option for this to be random
46-
* Ensure that backdrop is optional and there are some config parameters for it
56+
May include the following...
57+
58+
* Allow an image to be placed in the background of the designer (as a guide) which will make it easier to create complex shapes by "tracing" particles over the top.
59+
* Allow explosion particles to have tails which are lines (will allow for more interesting shapes).
60+
* Even more firework shapes and colour combinations.
61+
* Allow images to be used for the rocket bodies?
62+
* Add launch and explosion sounds, either pre-recorded or perhaps audio API generated?
63+
* Simplify the use of the library even more, ensuring things are nice an configurable.
64+
* Add the ability to queue up skyrockets in a particular order so can chain them to say particular messages such as "happy, 2018, everyone"
4765
* Create some documentation and examples

docs/img/Screenshot-Designer.png

77 KB
Loading

docs/img/Screenshot-Fireworks.png

43.3 KB
Loading

index.html

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ <h3>Merry new year!</h3>
2222

2323
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.2/TweenMax.min.js"></script>
2424
<script src="js/backdrop.js"></script>
25-
<script src="js/rocket_definitions.js"></script>
25+
<script src="skyrockets/colors.js"></script>
26+
<script src="skyrockets/explosions.js"></script>
2627
<script src="js/skyrocket.js"></script>
2728
<script>
2829
var canvas = document.getElementById('canvas');
@@ -33,11 +34,14 @@ <h3>Merry new year!</h3>
3334
// Check if the window has focus, only if yes then add more skyrockets. This is to prevent 100s of rockets
3435
// firing off if the browser tab has been in the background for some time.
3536
if (document.hasFocus()) {
36-
// Choose a random firework from the definition of the fireworks above.
37-
var randWork = Math.floor(Math.random() * skyrockets.length);
37+
// Choose a random explosion and firework colour from those defined in the /skyrockets directory.
38+
var randExplosion = Math.floor(Math.random() * explosions.length);
39+
var randColor = Math.floor(Math.random() * colors.length);
3840

3941
// Create a new firework and launch it straight away.
40-
fireworks[fireCount] = new Firework(fireCount, skyrockets[randWork]);
42+
//++ @TODO it might be nice if the firework added itelf to the array and incremented the fireCount in
43+
//++ its constructor rather than the developer having to worry about this.
44+
fireworks[fireCount] = new Firework(fireCount, explosions[randExplosion], colors[randColor]);
4145
fireworks[fireCount].launch();
4246

4347
// Increment this for next time.
@@ -53,10 +57,11 @@ <h3>Merry new year!</h3>
5357
canvas.onclick = function (e)
5458
{
5559
// Choose a random skyrocket.
56-
var randWork = Math.floor(Math.random() * skyrockets.length);
60+
var randExplosion = Math.floor(Math.random() * explosions.length);
61+
var randColor = Math.floor(Math.random() * colors.length);
5762

5863
// Create a new firework.
59-
var rocket = new Firework(fireCount, skyrockets[randWork]);
64+
var rocket = new Firework(fireCount, explosions[randExplosion], colors[randColor]);
6065

6166
// Set target x and y to mouse poistion.
6267
rocket.targetX = e.clientX;

js/backdrop.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
This file contains the code which generates the sky scraper background. If you want to do your own custom
3+
background, perhaps an SVG, then simply don't include this file on the index.html page.
4+
*/
5+
16
// Calculate the skyscraper dimensions
27
function skyline() {
38
// Get all backdrop divs by class name.

js/rocket_definitions.js

Lines changed: 0 additions & 134 deletions
This file was deleted.

0 commit comments

Comments
 (0)