Skip to content

Commit

Permalink
Release v2.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tswaters committed Mar 12, 2021
1 parent 38b8353 commit 2824d67
Show file tree
Hide file tree
Showing 14 changed files with 723 additions and 349 deletions.
4 changes: 4 additions & 0 deletions CHANGES.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.6.0

- Adding cannons option

## 2.5.1

- Adding a new option rocketInitialPoint where a user can customise starting point of firework (thanks adityasatnur)
Expand Down
11 changes: 11 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ const options = {
explosionChance: 0.08, // chance in each tick the rocket will explode
width: container.clientWidth, // override the width, defaults to container width
height: container.clientHeight // override the height, defaults to container height


// array of points, defaults to []
// when x is null or not defined, uses random position between 0 -> container width
// when y is null or not defined, uses container height
cannons: [{ x: width * 0.2 }, { x: width * 0.8 }],

// defines a single cannon with null for height and provided value for X.
// will be apended to provided cannons
rocketInitialPoint: width * 0.5,

}

// instantiate the class and call start
Expand Down
6 changes: 6 additions & 0 deletions fireworks.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
declare type Point = {
x: number
y: number
}

declare class Fireworks {
constructor(container: HTMLElement, options?: Fireworks.FireworksOptions)
destroy(): void
Expand All @@ -20,6 +25,7 @@ declare namespace Fireworks {
explosionChance?: number
rocketSpawnInterval?: number
rocketInitialPoint?: number
cannons?: Point[]
}
}

Expand Down
35 changes: 25 additions & 10 deletions fireworks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */

var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};

function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
Expand Down Expand Up @@ -127,14 +138,18 @@

var Things = (function () {
function Things(_a) {
var maxRockets = _a.maxRockets, numParticles = _a.numParticles, cw = _a.cw, ch = _a.ch, rocketInitialPoint = _a.rocketInitialPoint;
var maxRockets = _a.maxRockets, numParticles = _a.numParticles, cw = _a.cw, ch = _a.ch, rocketInitialPoint = _a.rocketInitialPoint, cannons = _a.cannons;
this._set = new Set();
this.rockets = 0;
this.maxRockets = maxRockets;
this.numParticles = numParticles;
this.cw = cw;
this.ch = ch;
this.rocketInitialPoint = rocketInitialPoint;
this.cannons = cannons;
if (this.rocketInitialPoint) {
this.cannons.push({ x: this.rocketInitialPoint, y: this.ch });
}
}
Things.prototype.size = function () {
return this._set.size;
Expand All @@ -144,6 +159,7 @@
};
Things.prototype.clear = function () {
this._set.clear();
this.rockets = 0;
};
Things.prototype["delete"] = function (thing) {
this._set["delete"](thing);
Expand All @@ -161,12 +177,11 @@
};
Things.prototype.spawnRocket = function () {
this.rockets++;
var cannonIndex = Math.floor(random(0, this.cannons.length));
var cannon = this.cannons[cannonIndex] || {};
this.add(new Particle({
isRocket: true,
position: {
x: this.rocketInitialPoint ? this.rocketInitialPoint : random(0, this.cw),
y: this.ch
}
position: __assign(__assign(__assign({}, cannon), (cannon.x == null && { x: random(0, this.cw) })), (cannon.y == null && { y: this.ch }))
}));
};
Things.prototype.spawnRockets = function () {
Expand All @@ -179,7 +194,7 @@

var Fireworks = (function () {
function Fireworks(container, _a) {
var _b = _a === void 0 ? {} : _a, _c = _b.rocketSpawnInterval, rocketSpawnInterval = _c === void 0 ? 150 : _c, _d = _b.maxRockets, maxRockets = _d === void 0 ? 3 : _d, _e = _b.numParticles, numParticles = _e === void 0 ? 100 : _e, _f = _b.explosionMinHeight, explosionMinHeight = _f === void 0 ? 0.2 : _f, _g = _b.explosionMaxHeight, explosionMaxHeight = _g === void 0 ? 0.9 : _g, _h = _b.explosionChance, explosionChance = _h === void 0 ? 0.08 : _h, _j = _b.width, width = _j === void 0 ? container.clientWidth : _j, _k = _b.height, height = _k === void 0 ? container.clientHeight : _k, _l = _b.rocketInitialPoint, rocketInitialPoint = _l === void 0 ? null : _l;
var _b = _a === void 0 ? {} : _a, _c = _b.rocketSpawnInterval, rocketSpawnInterval = _c === void 0 ? 150 : _c, _d = _b.maxRockets, maxRockets = _d === void 0 ? 3 : _d, _e = _b.numParticles, numParticles = _e === void 0 ? 100 : _e, _f = _b.explosionMinHeight, explosionMinHeight = _f === void 0 ? 0.2 : _f, _g = _b.explosionMaxHeight, explosionMaxHeight = _g === void 0 ? 0.9 : _g, _h = _b.explosionChance, explosionChance = _h === void 0 ? 0.08 : _h, _j = _b.width, width = _j === void 0 ? container.clientWidth : _j, _k = _b.height, height = _k === void 0 ? container.clientHeight : _k, _l = _b.rocketInitialPoint, rocketInitialPoint = _l === void 0 ? null : _l, _m = _b.cannons, cannons = _m === void 0 ? [] : _m;
this.finishCallbacks = [];
this.container = container;
this.rocketSpawnInterval = rocketSpawnInterval;
Expand All @@ -189,7 +204,6 @@
this.maxH = this.ch * (1 - explosionMaxHeight);
this.minH = this.ch * (1 - explosionMinHeight);
this.chance = explosionChance;
this.rocketInitialPoint = rocketInitialPoint;
this.pixelRatio = window.devicePixelRatio || 1;
this.canvas = document.createElement('canvas');
this.ctx = this.canvas.getContext('2d');
Expand All @@ -199,7 +213,8 @@
numParticles: numParticles,
cw: this.cw,
ch: this.ch,
rocketInitialPoint: this.rocketInitialPoint
rocketInitialPoint: rocketInitialPoint,
cannons: cannons
});
this.updateDimensions();
}
Expand All @@ -219,8 +234,8 @@
Fireworks.prototype.updateDimensions = function () {
this.canvas.width = this.cw * this.pixelRatio;
this.canvas.height = this.ch * this.pixelRatio;
this.canvas.style.width = this.cw + 'px';
this.canvas.style.height = this.ch + 'px';
this.canvas.style.width = this.cw + "px";
this.canvas.style.height = this.ch + "px";
this.ctx.scale(this.pixelRatio, this.pixelRatio);
this.things.cw = this.cw;
this.things.ch = this.ch;
Expand Down
1 change: 1 addition & 0 deletions fireworks.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion fireworks.min.js

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

1 change: 1 addition & 0 deletions fireworks.min.js.map

Large diffs are not rendered by default.

Loading

0 comments on commit 2824d67

Please sign in to comment.