Browse files

more work

  • Loading branch information...
1 parent 55cd4bc commit a6402fc07d9a7066a3c4d3f1ce41918f6d467d18 @jeromeetienne committed Jul 19, 2012
View
193 build/fireworks-bundle.js
@@ -14,6 +14,7 @@ Fireworks.Emitter = function(opts){
this._effects = [];
this._started = false;
this._onUpdated = null;
+ this._intensity = 0;
this._effectsStackBuilder = new Fireworks.EffectsStackBuilder(this)
}
@@ -71,6 +72,27 @@ Fireworks.Emitter.prototype.spawner = function(spawner){
}
/**
+ * Getter/setter for intensity
+*/
+Fireworks.Emitter.prototype.intensity = function(value){
+ // if it is a getter, return value
+ if( value === undefined ) return this._intensity;
+ // if the value didnt change, return for chained api
+ if( value === this._intensity ) return this;
+ // sanity check
+ console.assert( value >= 0, 'Fireworks.Emitter.intensity: invalid value.', value);
+ console.assert( value <= 1, 'Fireworks.Emitter.intensity: invalid value.', value);
+ // update the value
+ this._intensity = value;
+ // notify all effects
+ this._effects.forEach(function(effect){
+ if( !effect.onIntensityChange ) return;
+ effect.onIntensityChange(this._intensity);
+ }.bind(this));
+ return this; // for chained API
+}
+
+/**
* for backward compatibility only
*/
Fireworks.Emitter.prototype.setSpawner = Fireworks.Emitter.prototype.spawner;
@@ -114,7 +136,7 @@ Fireworks.Emitter.prototype.start = function()
effect.onCreate(particle, particleIdx);
})
}.bind(this));
-
+
return this; // for chained API
}
@@ -142,6 +164,10 @@ Fireworks.Emitter.prototype.render = function(){
effect.onRender(particle);
})
}.bind(this));
+ this._effects.forEach(function(effect){
+ if( !effect.onPostRender ) return;
+ effect.onPostRender();
+ }.bind(this));
return this; // for chained API
}
@@ -168,6 +194,7 @@ Fireworks.Emitter.prototype.killParticle = function(particle)
* Spawn a particle
*/
Fireworks.Emitter.prototype.spawnParticle = function(){
+ console.assert(this._deadParticles.length >= 1, 'no more particle available' );
// change the particles
var particle = this.deadParticles().pop();
this.liveParticles().push(particle);
@@ -270,6 +297,14 @@ Fireworks.createEffect = function(name, opts){
effect.onRender = val;
return methods;
},
+ onPostRender: function(val){
+ effect.onPostRender = val;
+ return methods;
+ },
+ onIntensityChange: function(val){
+ effect.onIntensityChange= val;
+ return methods;
+ },
pushTo : function(emitter){
emitter.effects().push(effect);
return methods;
@@ -653,7 +688,7 @@ Fireworks.EffectsStackBuilder.prototype.friction = function(value)
Fireworks.createEffect('friction')
.onCreate(function(particle, particleIdx){
particle.set('friction', {
- value : value,
+ value : value
});
})
.onBirth(function(particle){
@@ -683,7 +718,7 @@ Fireworks.EffectsStackBuilder.prototype.lifeTime = function(minAge, maxAge)
var emitter = this._emitter;
Fireworks.createEffect('lifeTime', {
minAge : minAge,
- maxAge : maxAge,
+ maxAge : maxAge
}).onCreate(function(particle){
var data = particle.set('lifeTime', {
curAge : 0,
@@ -711,7 +746,7 @@ Fireworks.EffectsStackBuilder.prototype.lifeTime = function(minAge, maxAge)
Fireworks.EffectsStackBuilder.prototype.position = function(shape)
{
console.assert( shape instanceof Fireworks.Shape );
- Fireworks.createEffect('Position', {
+ Fireworks.createEffect('position', {
shape : shape
}).onCreate(function(particle){
particle.set('position', {
@@ -778,23 +813,11 @@ Fireworks.EffectsStackBuilder.prototype.renderToCanvas = function(opts)
var effect = Fireworks.createEffect('renderToCanvas', {
ctx : ctx
}).pushTo(this._emitter);
-
-
- if( opts.type === 'arc' ){
- effect.onCreate(function(particle, particleIdx){
- particle.set('renderToCanvas', {
- size : 3
- // TODO it may contains color too
- });
- }).onRender(function(particle){
- var position = particle.get('position').vector;
- var size = particle.get('renderToCanvas').size;
- ctx.beginPath();
- ctx.arc(position.x, position.y, size, 0, Math.PI*2, true);
- ctx.fill();
- })
- }else{
+
+ if( opts.type === 'arc' ) ctorTypeArc(effect);
+ else if( opts.type === 'drawImage' ) ctorTypeDrawImage(effect);
+ else{
console.assert(false, 'renderToCanvas opts.type is invalid: ');
}
@@ -816,6 +839,67 @@ Fireworks.EffectsStackBuilder.prototype.renderToCanvas = function(opts)
// return ctx
return ctx;
}
+
+ function ctorTypeArc(){
+ return effect.onCreate(function(particle, particleIdx){
+ particle.set('renderToCanvas', {
+ size : 3
+ });
+ }).onRender(function(particle){
+ var position = particle.get('position').vector;
+ var size = particle.get('renderToCanvas').size;
+
+ ctx.beginPath();
+ ctx.arc(position.x + canvas.width /2,
+ position.y + canvas.height/2, size, 0, Math.PI*2, true);
+ ctx.fill();
+ });
+ };
+ function ctorTypeDrawImage(){
+ // handle parameter polymorphism
+ if( typeof(opts.image) === 'string' ){
+ var images = [new Image];
+ image[0].src = opts.image;
+ }else if( opts.image instanceof Image ){
+ var images = [opts.image];
+ }else if( opts.image instanceof Array ){
+ var images = opts.image;
+ }else console.assert(false, 'invalid .renderToCanvas() options')
+
+ return effect.onCreate(function(particle, particleIdx){
+ particle.set('renderToCanvas', {
+ scale : 1, // should that be there ? or in its own effect ?
+ opacity : 1, // should that be there ? or in its own effect ?
+ rotation : 0*Math.PI
+ });
+ }).onRender(function(particle){
+ var position = particle.get('position').vector;
+ var data = particle.get('renderToCanvas');
+ var canonAge = particle.get('lifeTime').normalizedAge();
+ var imageIdx = Math.floor(canonAge * images.length);
+ var image = images[imageIdx];
+ // save the context
+ ctx.save();
+ // translate in canvas's center, and the particle position
+ ctx.translate(position.x + canvas.width/2, position.y + canvas.height/2);
+ // set the scale of this particles
+ ctx.scale(data.scale, data.scale);
+ // set the rotation
+ ctx.rotate(data.rotation);
+ // set ctx.globalAlpha
+ ctx.globalAlpha = data.opacity;
+ // draw the image itself
+ if( image instanceof Image ){
+ ctx.drawImage(image, -image.width/2, -image.height/2);
+ }else if( typeof(image) === 'object' ){
+ ctx.drawImage(image.image
+ , image.offsetX, image.offsetY , image.width, image.height
+ , -image.width/2, -image.height/2, image.width, image.height);
+ }else console.assert(false);
+ // restore the context
+ ctx.restore();
+ });
+ };
};
/**
* render to three.js THREE.Object3D
@@ -944,7 +1028,7 @@ Fireworks.EffectsStackBuilder.prototype.renderToThreejsParticleSystem = function
*/
Fireworks.EffectsStackBuilder.prototype.velocity = function(shape)
{
- Fireworks.createEffect('Velocity', {
+ Fireworks.createEffect('velocity', {
shape : shape
}).onCreate(function(particle){
particle.set('velocity', {
@@ -972,20 +1056,27 @@ Fireworks.BindTriggerDomEvents = function(emitter, domElement){
this._domElement= domElement || document.body;
// bind mouse event
- this._onMouseDown = function(){
- emitter.spawner().start();
- };
+ this._onMouseDown = function(){ emitter.spawner().start(); };
+ this._onMouseUp = function(){ emitter.spawner().stop(); };
this._domElement.addEventListener('mousedown' , this._onMouseDown );
- this._onMouseUp = function(){
- emitter.spawner().stop();
- };
this._domElement.addEventListener('mouseup' , this._onMouseUp );
+
+ // change emitter intensity on mousewheel
+ this._onMouseWheel = function(event){
+ var intensity = emitter.intensity();
+ intensity += event.wheelDelta < 0 ? -0.05 : 0.05;
+ intensity = Math.max(intensity, 0);
+ intensity = Math.min(intensity, 1);
+ emitter.intensity(intensity);
+ };
+ this._domElement.addEventListener('mousewheel' , this._onMouseWheel );
}
-Fireworks.BindTriggerDomEvents.prototype.destroy = function() {
- this._domElement.removeEventListener('mousedown', this._onMouseDown );
- this._domElement.removeEventListener('mouseup' , this._onMouseUp );
+Fireworks.BindTriggerDomEvents.prototype.destroy = function(){
+ this._domElement.removeEventListener('mousedown' , this._onMouseDown );
+ this._domElement.removeEventListener('mouseup' , this._onMouseUp );
+ this._domElement.removeEventListener('mousewheel' , this._onMouseWheel );
};
Fireworks.DatGui4Emitter = function(emitter){
var gui = new dat.GUI();
@@ -1161,7 +1252,7 @@ Fireworks.SpawnerOneShot = function(nParticles){
Fireworks.Spawner.call( this );
// init class variables
this._nParticles = nParticles || 1;
- this._completed = false;
+ this._nSent = 0;
// start the spawner on init
this.start();
}
@@ -1172,17 +1263,28 @@ Fireworks.SpawnerOneShot.prototype.constructor = Fireworks.SpawnerOneShot;
Fireworks.SpawnerOneShot.prototype.update = function(emitter, deltaTime){
// if already completed, do nothing
- if( this._completed ) return;
+ if( this._nParticles === this._nSent ) return;
// spawn each particle
- for(var i = 0; i < this._nParticles; i++){
+ var nParticles = this._nParticles - this._nSent;
+ nParticles = Math.min(nParticles, emitter.deadParticles().length);
+ for(var i = 0; i < nParticles; i++){
emitter.spawnParticle();
}
+ // update the amount of sent particles
+ this._nSent += nParticles;
// mark it as completed
this._completed = true;
}
/**
+ * reset the spawner
+*/
+Fireworks.SpawnerOneShot.prototype.reset = function(){
+ this._nSent = 0;
+}/**
* Make the emitter use a SpawnerSteadyRate
+ *
+ * @param {Number?} rate the rate at which it gonna emit
*/
Fireworks.Emitter.prototype.useSpawnerSteadyRate = function(rate){
var spawner = new Fireworks.SpawnerSteadyRate(rate);
@@ -1191,8 +1293,9 @@ Fireworks.Emitter.prototype.useSpawnerSteadyRate = function(rate){
/**
* Spawner deliverying paricles at a steady rate
+ *
+ * @param {Number?} rate the rate at which it gonna emit
*/
-Fireworks.SpawnerRate = // for backward compatibility only
Fireworks.SpawnerSteadyRate = function(rate){
// call constructor of parent calss
Fireworks.Spawner.call( this );
@@ -1207,6 +1310,28 @@ Fireworks.SpawnerSteadyRate = function(rate){
Fireworks.SpawnerSteadyRate.prototype = new Fireworks.Spawner();
Fireworks.SpawnerSteadyRate.prototype.constructor = Fireworks.SpawnerSteadyRate;
+//////////////////////////////////////////////////////////////////////////////////
+// //
+//////////////////////////////////////////////////////////////////////////////////
+
+/**
+ * Getter/Setter for the rate
+ *
+ * @param {Number?} value the value to change
+ * @returns {Fireworks.SpawnerSteadyRate} for chained API
+*/
+Fireworks.SpawnerSteadyRate.prototype.rate = function(value){
+ if( value === undefined ) return this._rate;
+ this._rate = value;
+ return this;
+}
+
+/**
+ * update the spawner
+ *
+ * @param {Fireworks.Emitter} emitter the emitter for which Fireworks.Spawner
+ * @param {Number} deltaTime the amount of seconds since last iteration
+*/
Fireworks.SpawnerSteadyRate.prototype.update = function(emitter, deltaTime){
// if the spawner is not running, return now
if( this.isRunning() === false ) return;
View
46 build/fireworks-bundle.min.js
@@ -1 +1,45 @@
-
+var Fireworks={createEmitter:function(a){return new Fireworks.Emitter(a)},Emitter:function(a){this._nParticles=void 0!==a.nParticles?a.nParticles:100;this._particles=[];this._spawner=null;this._effects=[];this._started=!1;this._onUpdated=null;this._intensity=0;this._effectsStackBuilder=new Fireworks.EffectsStackBuilder(this)}};Fireworks.Emitter.prototype.destroy=function(){this._effects.forEach(function(a){a.destroy()});this._spawner&&this._spawner.destroy();this._particles.forEach(function(a){a.destroy()})};
+Fireworks.Emitter.prototype.effects=function(){return this._effects};Fireworks.Emitter.prototype.effectByName=function(a){for(var b=0;b<this._effects.length;b++){var c=this._effects[b];if(c.name===a)return c}return null};Fireworks.Emitter.prototype.particles=function(){return this._particles};Fireworks.Emitter.prototype.liveParticles=function(){return this._liveParticles};Fireworks.Emitter.prototype.deadParticles=function(){return this._deadParticles};Fireworks.Emitter.prototype.nParticles=function(){return this._nParticles};
+Fireworks.Emitter.prototype.effectsStackBuilder=function(){return this._effectsStackBuilder};Fireworks.Emitter.prototype.spawner=function(a){if(void 0===a)return this._spawner;this._spawner=a;return this};
+Fireworks.Emitter.prototype.intensity=function(a){if(void 0===a)return this._intensity;if(a===this._intensity)return this;console.assert(0<=a,"Fireworks.Emitter.intensity: invalid value.",a);console.assert(1>=a,"Fireworks.Emitter.intensity: invalid value.",a);this._intensity=a;this._effects.forEach(function(a){if(a.onIntensityChange)a.onIntensityChange(this._intensity)}.bind(this));return this};Fireworks.Emitter.prototype.setSpawner=Fireworks.Emitter.prototype.spawner;
+Fireworks.Emitter.prototype.setParticleData=function(a,b,c){a.set(b,c)};Fireworks.Emitter.prototype.getParticleData=function(a,b){return a.get(b)};
+Fireworks.Emitter.prototype.start=function(){console.assert(this._spawner,"a spawner MUST be set");console.assert(0<this._effects.length,"Some effects MUST be set");console.assert(!1===this._started);this._particles=Array(this._nParticles);for(var a=0;a<this._nParticles;a++)this._particles[a]=new Fireworks.Particle;this._liveParticles=[];this._deadParticles=this._particles.slice(0);this._started=!0;this._effects.forEach(function(a){a.onCreate&&this._particles.forEach(function(c,d){a.onCreate(c,d)})}.bind(this));
+return this};Fireworks.Emitter.prototype.update=function(a){this._spawner.update(this,a);this._effects.forEach(function(b){b.onUpdate&&this._liveParticles.forEach(function(c){b.onUpdate(c,a)})}.bind(this));return this};
+Fireworks.Emitter.prototype.render=function(){this._effects.forEach(function(a){if(a.onPreRender)a.onPreRender()}.bind(this));this._effects.forEach(function(a){a.onRender&&this._liveParticles.forEach(function(b){a.onRender(b)})}.bind(this));this._effects.forEach(function(a){if(a.onPostRender)a.onPostRender()}.bind(this));return this};
+Fireworks.Emitter.prototype.killParticle=function(a){var b=this._liveParticles.indexOf(a);console.assert(-1!==b);this._liveParticles.splice(b,1);this._deadParticles.push(a);this.effects().forEach(function(b){b.onDeath&&b.onDeath(a)}.bind(this))};Fireworks.Emitter.prototype.spawnParticle=function(){console.assert(1<=this._deadParticles.length,"no more particle available");var a=this.deadParticles().pop();this.liveParticles().push(a);this.effects().forEach(function(b){b.onBirth&&b.onBirth(a)}.bind(this))};
+Fireworks.Spawner=function(){this._isRunning=!1};Fireworks.Spawner.prototype.start=function(){this._isRunning=!0};Fireworks.Spawner.prototype.stop=function(){this._isRunning=!1};Fireworks.Spawner.prototype.isRunning=function(){return this._isRunning};Fireworks.Particle=function(){};Fireworks.Particle.prototype.set=function(a,b){console.assert(void 0===this[a],"key already defined: "+a);this[a]=b;return this[a]};
+Fireworks.Particle.prototype.get=function(a){console.assert(void 0!==this[a],"key undefined: "+a);return this[a]};Fireworks.Particle.prototype.has=function(a){return void 0!==this[a]?!0:!1};Fireworks.EffectsStackBuilder=function(a){this._emitter=a};Fireworks.EffectsStackBuilder.prototype.back=function(){return this._emitter};Fireworks.EffectsStackBuilder.prototype.createEffect=function(a,b){return Fireworks.createEffect(a,b).pushTo(this._emitter).back(this)};
+Fireworks.createEffect=function(a,b){"object"===typeof a&&(b=a,a=void 0);var c=new Fireworks.Effect;c.opts=b;c.name=a;c.back=null;var d={onCreate:function(a){c.onCreate=a;return d},onBirth:function(a){c.onBirth=a;return d},onUpdate:function(a){c.onUpdate=a;return d},onDeath:function(a){c.onDeath=a;return d},onPreRender:function(a){c.onPreRender=a;return d},onRender:function(a){c.onRender=a;return d},onPostRender:function(a){c.onPostRender=a;return d},onIntensityChange:function(a){c.onIntensityChange=
+a;return d},pushTo:function(a){a.effects().push(c);return d},back:function(a){if(a===void 0)return c.back;c.back=a;return d},effect:function(){return c}};return d};Fireworks.Effect=function(){};Fireworks.Shape=function(){};Fireworks.createVector=function(a,b,c){return new Fireworks.Vector(a,b,c)};Fireworks.Vector=function(a,b,c){this.x=a||0;this.y=b||0;this.z=c||0};
+Fireworks.Vector.prototype={constructor:Fireworks.Vector,set:function(a,b,c){this.x=a;this.y=b;this.z=c;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},setZ:function(a){this.z=a;return this},random:function(){this.x=Math.random()-0.5;this.y=Math.random()-0.5;this.z=Math.random()-0.5;return this},toString:function(){return JSON.stringify(this)},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=
+a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;
+this.z*=a;return this},divideSelf:function(a){this.x/=a.x;this.y/=a.y;this.z/=a.z;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a):this.z=this.y=this.x=0;return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},
+cross:function(a,b){this.x=a.y*b.z-a.z*b.y;this.y=a.z*b.x-a.x*b.z;this.z=a.x*b.y-a.y*b.x;return this},crossSelf:function(a){var b=this.x,c=this.y,d=this.z;this.x=c*a.z-d*a.y;this.y=d*a.x-b*a.z;this.z=b*a.y-c*a.x;return this},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},distanceToSquared:function(a){return(new Fireworks.Vector).sub(this,a).lengthSq()},equals:function(a){return a.x===this.x&&a.y===this.y&&a.z===this.z},isZero:function(){return 1E-4>this.lengthSq()},clone:function(){return new Fireworks.Vector(this.x,
+this.y,this.z)}};
+Fireworks.EffectsStackBuilder.prototype.acceleration=function(a){var a=a||{},b=a.effectId||"acceleration";console.assert(a.shape instanceof Fireworks.Shape);Fireworks.createEffect(b,{shape:a.shape}).onCreate(function(a){a.set("acceleration",{vector:new Fireworks.Vector})}).onBirth(function(a){a=a.get("acceleration").vector;this.opts.shape.randomPoint(a)}).onUpdate(function(a,b){var e=a.get("velocity").vector,f=a.get("acceleration").vector;e.x+=f.x*b;e.y+=f.y*b;e.z+=f.z*b}).pushTo(this._emitter);return this};
+Fireworks.EffectsStackBuilder.prototype.friction=function(a){a=void 0!==a?a:1;console.assert(0<=a&&1>=a);Fireworks.createEffect("friction").onCreate(function(b){b.set("friction",{value:a})}).onBirth(function(b){b.get("friction").value=a}).onUpdate(function(a){var c=a.get("friction").value;a.get("velocity").vector.multiplyScalar(c)}).pushTo(this._emitter);return this};
+Fireworks.EffectsStackBuilder.prototype.lifeTime=function(a,b){console.assert(void 0!==a);void 0===b&&(b=a);console.assert(void 0!==b);var c=this._emitter;Fireworks.createEffect("lifeTime",{minAge:a,maxAge:b}).onCreate(function(a){var b=a.set("lifeTime",{curAge:0,minAge:0,maxAge:0,normalizedAge:function(){return(b.curAge-b.minAge)/(b.maxAge-b.minAge)}})}).onBirth(function(a){a=a.get("lifeTime");a.curAge=0;a.maxAge=this.opts.minAge+Math.random()*(this.opts.maxAge-this.opts.minAge)}).onUpdate(function(a,
+b){var f=a.get("lifeTime");f.curAge+=b;f.curAge>f.maxAge&&c.killParticle(a)}).pushTo(this._emitter);return this};Fireworks.EffectsStackBuilder.prototype.position=function(a){console.assert(a instanceof Fireworks.Shape);Fireworks.createEffect("position",{shape:a}).onCreate(function(a){a.set("position",{vector:new Fireworks.Vector})}).onBirth(function(a){a=a.get("position").vector;this.opts.shape.randomPoint(a)}).pushTo(this._emitter);return this};
+Fireworks.EffectsStackBuilder.prototype.radialVelocity=function(a,b){Fireworks.createEffect("radialVelocity",{minSpeed:a,maxSpeed:b}).onCreate(function(a){a.set("velocity",{vector:new Fireworks.Vector})}).onBirth(function(a){var b=a.get("position").vector,a=a.get("velocity").vector,e=this.opts.minSpeed+(this.opts.maxSpeed-this.opts.minSpeed)*Math.random();a.copy(b).setLength(e)}).onUpdate(function(a,b){var e=a.get("position").vector,f=a.get("velocity").vector;e.x+=f.x*b;e.y+=f.y*b;e.z+=f.z*b}).pushTo(this._emitter);
+return this};Fireworks.EffectsStackBuilder.prototype.randomVelocityDrift=function(a){Fireworks.createEffect("randomVelocityDrift",{drift:a}).onUpdate(function(a,c){var d=a.get("velocity").vector;d.x+=(2*Math.random()-1)*this.opts.drift.x*c;d.y+=(2*Math.random()-1)*this.opts.drift.y*c;d.z+=(2*Math.random()-1)*this.opts.drift.z*c}).pushTo(this._emitter);return this};
+Fireworks.EffectsStackBuilder.prototype.renderToCanvas=function(a){var a=a||{},b;if(!(b=a.ctx))b=document.createElement("canvas"),b.width=window.innerWidth,b.height=window.innerHeight,document.body.appendChild(b),b.style.position="absolute",b.style.left=0,b.style.top=0,b=b.getContext("2d");var c=b;b=Fireworks.createEffect("renderToCanvas",{ctx:c}).pushTo(this._emitter);if("arc"===a.type)b.onCreate(function(a){a.set("renderToCanvas",{size:3})}).onRender(function(a){var b=a.get("position").vector,a=
+a.get("renderToCanvas").size;c.beginPath();c.arc(b.x+canvas.width/2,b.y+canvas.height/2,a,0,2*Math.PI,!0);c.fill()});else if("drawImage"===a.type){if("string"===typeof a.image){var d=[new Image];image[0].src=a.image}else a.image instanceof Image?d=[a.image]:a.image instanceof Array?d=a.image:console.assert(!1,"invalid .renderToCanvas() options");b.onCreate(function(a){a.set("renderToCanvas",{scale:1,opacity:1,rotation:0*Math.PI})}).onRender(function(a){var b=a.get("position").vector,g=a.get("renderToCanvas"),
+a=a.get("lifeTime").normalizedAge(),a=d[Math.floor(a*d.length)];c.save();c.translate(b.x+canvas.width/2,b.y+canvas.height/2);c.scale(g.scale,g.scale);c.rotate(g.rotation);c.globalAlpha=g.opacity;a instanceof Image?c.drawImage(a,-a.width/2,-a.height/2):"object"===typeof a?c.drawImage(a.image,a.offsetX,a.offsetY,a.width,a.height,-a.width/2,-a.height/2,a.width,a.height):console.assert(!1);c.restore()})}else console.assert(!1,"renderToCanvas opts.type is invalid: ");return this};
+Fireworks.EffectsStackBuilder.prototype.renderToThreejsObject3D=function(a){var b=a.container;Fireworks.createEffect(a.effectId||"renderToThreeParticleSystem").onCreate(function(b){b.set("threejsObject3D",{object3d:a.create()});console.assert(b.get("threejsObject3D").object3d instanceof THREE.Object3D);b.get("threejsObject3D")}).onBirth(function(a){a=a.get("threejsObject3D").object3d;b.add(a)}).onDeath(function(a){a=a.get("threejsObject3D").object3d;b.remove(a)}).onRender(function(a){var b=a.get("threejsObject3D").object3d,
+a=a.get("position").vector;b.position.set(a.x,a.y,a.z)}).pushTo(this._emitter);return this};
+Fireworks.EffectsStackBuilder.prototype.renderToThreejsParticleSystem=function(a){function b(a){for(var b=new THREE.Geometry,c=0;c<a.nParticles();c++)b.vertices.push(new THREE.Vector3);var a=THREE.ParticleBasicMaterial,c=128,d=document.createElement("canvas"),h=d.getContext("2d");d.width=d.height=c;var i=h.createRadialGradient(d.width/2,d.height/2,0,d.width/2,d.height/2,d.width/2);i.addColorStop(0,"rgba(255,255,255,1)");i.addColorStop(0.5,"rgba(255,255,255,1)");i.addColorStop(0.7,"rgba(128,128,128,1)");
+i.addColorStop(1,"rgba(0,0,0,1)");h.beginPath();h.arc(c/2,c/2,c/2,0,2*Math.PI,!1);h.closePath();h.fillStyle=i;h.fill();c=new THREE.Texture(d);c.needsUpdate=!0;a=new a({size:5,sizeAttenuation:!0,color:14687082,map:c,blending:THREE.AdditiveBlending,depthWrite:!1,transparent:!0});b=new THREE.ParticleSystem(b,a);b.dynamic=!0;b.sortParticles=!0;return b}var a=a||{},c=a.effectId||"renderToThreejsParticleSystem",a=a.particleSystem||b;"function"===typeof a&&(a=a(this._emitter));console.assert(a instanceof
+THREE.ParticleSystem,"particleSystem MUST be THREE.ParticleSystem");var d=a.geometry;console.assert(d.vertices.length>=this._emitter.nParticles());Fireworks.createEffect(c,{particleSystem:a}).onCreate(function(a,b){a.set("threejsParticle",{particleIdx:b});d.vertices[b].set(Infinity,Infinity,Infinity)}).onDeath(function(a){a=a.get("threejsParticle").particleIdx;d.vertices[a].set(Infinity,Infinity,Infinity)}).onRender(function(a){var b=a.get("threejsParticle").particleIdx,b=d.vertices[b],a=a.get("position").vector;
+b.set(a.x,a.y,a.z)}).pushTo(this._emitter);return this};Fireworks.EffectsStackBuilder.prototype.velocity=function(a){Fireworks.createEffect("velocity",{shape:a}).onCreate(function(a){a.set("velocity",{vector:new Fireworks.Vector})}).onBirth(function(a){a=a.get("velocity").vector;this.opts.shape.randomPoint(a)}).onUpdate(function(a,c){var d=a.get("position").vector,e=a.get("velocity").vector;d.x+=e.x*c;d.y+=e.y*c;d.z+=e.z*c}).pushTo(this._emitter);return this};
+Fireworks.Emitter.prototype.bindTriggerDomEvents=function(a){new Fireworks.BindTriggerDomEvents(this,a);return this};
+Fireworks.BindTriggerDomEvents=function(a,b){this._domElement=b||document.body;this._onMouseDown=function(){a.spawner().start()};this._onMouseUp=function(){a.spawner().stop()};this._domElement.addEventListener("mousedown",this._onMouseDown);this._domElement.addEventListener("mouseup",this._onMouseUp);this._onMouseWheel=function(b){var d=a.intensity(),d=d+(0>b.wheelDelta?-0.05:0.05),d=Math.max(d,0),d=Math.min(d,1);a.intensity(d)};this._domElement.addEventListener("mousewheel",this._onMouseWheel)};
+Fireworks.BindTriggerDomEvents.prototype.destroy=function(){this._domElement.removeEventListener("mousedown",this._onMouseDown);this._domElement.removeEventListener("mouseup",this._onMouseUp);this._domElement.removeEventListener("mousewheel",this._onMouseWheel)};
+Fireworks.DatGui4Emitter=function(a){var b=new dat.GUI;a.effects().forEach(function(a,d){var e=a.name||"effect-"+d,f=a.opts||{},g=Object.keys(f).filter(function(a){return f[a]instanceof Fireworks.Vector?!0:"object"===typeof f[a]?!1:!0});if(g.length){var j=b.addFolder("Effect: "+e);g.forEach(function(a){f[a]instanceof Fireworks.Vector?(j.add(f[a],"x").name(a+"X"),j.add(f[a],"y").name(a+"Y"),j.add(f[a],"z").name(a+"Z")):j.add(f,a)})}});return b};
+Fireworks.createShapeBox=function(a,b,c,d,e,f){a=new Fireworks.Vector(a,b,c);d=new Fireworks.Vector(d,e,f);return new Fireworks.Shape.Box(a,d)};Fireworks.Shape.Box=function(a,b){this.center=a;this.size=b;this._vector=new Fireworks.Vector};Fireworks.Shape.Box.prototype=new Fireworks.Shape;Fireworks.Shape.Box.prototype.constructor=Fireworks.Shape.Box;
+Fireworks.Shape.Box.prototype.contains=function(a){a=this._vector.sub(a,this.center);return Math.abs(a.x)>this.size.x/2||Math.abs(a.y)>this.size.y/2||Math.abs(a.z)>this.size.z/2?!1:!0};Fireworks.Shape.Box.prototype.randomPoint=function(a){a=a||this._vector;a.x=Math.random()*this.size.x-this.size.x/2;a.y=Math.random()*this.size.y-this.size.y/2;a.z=Math.random()*this.size.z-this.size.z/2;a.addSelf(this.center);return a};Fireworks.createShapePoint=function(a,b,c){a=new Fireworks.Vector(a,b,c);return new Fireworks.Shape.Point(a)};
+Fireworks.Shape.Point=function(a){this.position=a;this._vector=new Fireworks.Vector};Fireworks.Shape.Point.prototype=new Fireworks.Shape;Fireworks.Shape.Point.prototype.constructor=Fireworks.Shape.Point;Fireworks.Shape.Point.prototype.contains=function(a){return a.x!==this.position.x||a.y!==this.position.y||a.z!==this.position.z?!1:!0};Fireworks.Shape.Point.prototype.randomPoint=function(a){a=a||this._vector;a.copy(this.position);return a};
+Fireworks.createShapeSphere=function(a,b,c,d){a=new Fireworks.Vector(a,b,c);return new Fireworks.ShapeSphere(a,d)};Fireworks.ShapeSphere=function(a,b){this.center=a;this.radius=b;this._vector=new Fireworks.Vector};Fireworks.ShapeSphere.prototype=new Fireworks.Shape;Fireworks.ShapeSphere.prototype.constructor=Fireworks.ShapeSphere;Fireworks.ShapeSphere.prototype.contains=function(a){return this._vector.sub(a,this.center).length()<=this.radius};
+Fireworks.ShapeSphere.prototype.randomPoint=function(a){a=a||this._vector;a.x=Math.random()-0.5;a.y=Math.random()-0.5;a.z=Math.random()-0.5;var b=Math.random()*this.radius;a.setLength(b);a.addSelf(this.center);return a};Fireworks.Emitter.prototype.useSpawnerOneShot=function(a){a=void 0!==a?a:this.nParticles();a=new Fireworks.SpawnerOneShot(a);return this.setSpawner(a)};Fireworks.SpawnerOneShot=function(a){Fireworks.Spawner.call(this);this._nParticles=a||1;this._nSent=0;this.start()};
+Fireworks.SpawnerOneShot.prototype=new Fireworks.Spawner;Fireworks.SpawnerOneShot.prototype.constructor=Fireworks.SpawnerOneShot;Fireworks.SpawnerOneShot.prototype.update=function(a){if(this._nParticles!==this._nSent){for(var b=this._nParticles-this._nSent,b=Math.min(b,a.deadParticles().length),c=0;c<b;c++)a.spawnParticle();this._nSent+=b;this._completed=!0}};Fireworks.SpawnerOneShot.prototype.reset=function(){this._nSent=0};
+Fireworks.Emitter.prototype.useSpawnerSteadyRate=function(a){a=new Fireworks.SpawnerSteadyRate(a);return this.setSpawner(a)};Fireworks.SpawnerSteadyRate=function(a){Fireworks.Spawner.call(this);this._rate=a||10;this._nToCreate=1;this.start()};Fireworks.SpawnerSteadyRate.prototype=new Fireworks.Spawner;Fireworks.SpawnerSteadyRate.prototype.constructor=Fireworks.SpawnerSteadyRate;Fireworks.SpawnerSteadyRate.prototype.rate=function(a){if(void 0===a)return this._rate;this._rate=a;return this};
+Fireworks.SpawnerSteadyRate.prototype.update=function(a,b){if(!1!==this.isRunning()){this._nToCreate+=this._rate*b;var c=Math.floor(this._nToCreate),c=Math.min(c,a.deadParticles().length);this._nToCreate-=c;for(var d=0;d<c;d++)a.spawnParticle()}};
View
37 build/fireworks.js
@@ -13,6 +13,7 @@ Fireworks.Emitter = function(opts){
this._effects = [];
this._started = false;
this._onUpdated = null;
+ this._intensity = 0;
this._effectsStackBuilder = new Fireworks.EffectsStackBuilder(this)
}
@@ -70,6 +71,27 @@ Fireworks.Emitter.prototype.spawner = function(spawner){
}
/**
+ * Getter/setter for intensity
+*/
+Fireworks.Emitter.prototype.intensity = function(value){
+ // if it is a getter, return value
+ if( value === undefined ) return this._intensity;
+ // if the value didnt change, return for chained api
+ if( value === this._intensity ) return this;
+ // sanity check
+ console.assert( value >= 0, 'Fireworks.Emitter.intensity: invalid value.', value);
+ console.assert( value <= 1, 'Fireworks.Emitter.intensity: invalid value.', value);
+ // update the value
+ this._intensity = value;
+ // notify all effects
+ this._effects.forEach(function(effect){
+ if( !effect.onIntensityChange ) return;
+ effect.onIntensityChange(this._intensity);
+ }.bind(this));
+ return this; // for chained API
+}
+
+/**
* for backward compatibility only
*/
Fireworks.Emitter.prototype.setSpawner = Fireworks.Emitter.prototype.spawner;
@@ -113,7 +135,7 @@ Fireworks.Emitter.prototype.start = function()
effect.onCreate(particle, particleIdx);
})
}.bind(this));
-
+
return this; // for chained API
}
@@ -141,6 +163,10 @@ Fireworks.Emitter.prototype.render = function(){
effect.onRender(particle);
})
}.bind(this));
+ this._effects.forEach(function(effect){
+ if( !effect.onPostRender ) return;
+ effect.onPostRender();
+ }.bind(this));
return this; // for chained API
}
@@ -167,6 +193,7 @@ Fireworks.Emitter.prototype.killParticle = function(particle)
* Spawn a particle
*/
Fireworks.Emitter.prototype.spawnParticle = function(){
+ console.assert(this._deadParticles.length >= 1, 'no more particle available' );
// change the particles
var particle = this.deadParticles().pop();
this.liveParticles().push(particle);
@@ -269,6 +296,14 @@ Fireworks.createEffect = function(name, opts){
effect.onRender = val;
return methods;
},
+ onPostRender: function(val){
+ effect.onPostRender = val;
+ return methods;
+ },
+ onIntensityChange: function(val){
+ effect.onIntensityChange= val;
+ return methods;
+ },
pushTo : function(emitter){
emitter.effects().push(effect);
return methods;
View
19 build/fireworks.min.js
@@ -1,13 +1,16 @@
-var Fireworks={createEmitter:function(a){return new Fireworks.Emitter(a)},Emitter:function(a){this._nParticles=void 0!==a.nParticles?a.nParticles:100;this._particles=[];this._spawner=null;this._effects=[];this._started=!1;this._onUpdated=null;this._effectsStackBuilder=new Fireworks.EffectsStackBuilder(this)}};Fireworks.Emitter.prototype.destroy=function(){this._effects.forEach(function(a){a.destroy()});this._spawner&&this._spawner.destroy();this._particles.forEach(function(a){a.destroy()})};
+var Fireworks={createEmitter:function(a){return new Fireworks.Emitter(a)},Emitter:function(a){this._nParticles=void 0!==a.nParticles?a.nParticles:100;this._particles=[];this._spawner=null;this._effects=[];this._started=!1;this._onUpdated=null;this._intensity=0;this._effectsStackBuilder=new Fireworks.EffectsStackBuilder(this)}};Fireworks.Emitter.prototype.destroy=function(){this._effects.forEach(function(a){a.destroy()});this._spawner&&this._spawner.destroy();this._particles.forEach(function(a){a.destroy()})};
Fireworks.Emitter.prototype.effects=function(){return this._effects};Fireworks.Emitter.prototype.effectByName=function(a){for(var b=0;b<this._effects.length;b++){var c=this._effects[b];if(c.name===a)return c}return null};Fireworks.Emitter.prototype.particles=function(){return this._particles};Fireworks.Emitter.prototype.liveParticles=function(){return this._liveParticles};Fireworks.Emitter.prototype.deadParticles=function(){return this._deadParticles};Fireworks.Emitter.prototype.nParticles=function(){return this._nParticles};
-Fireworks.Emitter.prototype.effectsStackBuilder=function(){return this._effectsStackBuilder};Fireworks.Emitter.prototype.spawner=function(a){if(void 0===a)return this._spawner;this._spawner=a;return this};Fireworks.Emitter.prototype.setSpawner=Fireworks.Emitter.prototype.spawner;Fireworks.Emitter.prototype.setParticleData=function(a,b,c){a.set(b,c)};Fireworks.Emitter.prototype.getParticleData=function(a,b){return a.get(b)};
+Fireworks.Emitter.prototype.effectsStackBuilder=function(){return this._effectsStackBuilder};Fireworks.Emitter.prototype.spawner=function(a){if(void 0===a)return this._spawner;this._spawner=a;return this};
+Fireworks.Emitter.prototype.intensity=function(a){if(void 0===a)return this._intensity;if(a===this._intensity)return this;console.assert(0<=a,"Fireworks.Emitter.intensity: invalid value.",a);console.assert(1>=a,"Fireworks.Emitter.intensity: invalid value.",a);this._intensity=a;this._effects.forEach(function(a){if(a.onIntensityChange)a.onIntensityChange(this._intensity)}.bind(this));return this};Fireworks.Emitter.prototype.setSpawner=Fireworks.Emitter.prototype.spawner;
+Fireworks.Emitter.prototype.setParticleData=function(a,b,c){a.set(b,c)};Fireworks.Emitter.prototype.getParticleData=function(a,b){return a.get(b)};
Fireworks.Emitter.prototype.start=function(){console.assert(this._spawner,"a spawner MUST be set");console.assert(0<this._effects.length,"Some effects MUST be set");console.assert(!1===this._started);this._particles=Array(this._nParticles);for(var a=0;a<this._nParticles;a++)this._particles[a]=new Fireworks.Particle;this._liveParticles=[];this._deadParticles=this._particles.slice(0);this._started=!0;this._effects.forEach(function(a){a.onCreate&&this._particles.forEach(function(c,d){a.onCreate(c,d)})}.bind(this));
-return this};Fireworks.Emitter.prototype.update=function(a){this._spawner.update(this,a);this._effects.forEach(function(b){b.onUpdate&&this._liveParticles.forEach(function(c){b.onUpdate(c,a)})}.bind(this));return this};Fireworks.Emitter.prototype.render=function(){this._effects.forEach(function(a){if(a.onPreRender)a.onPreRender()}.bind(this));this._effects.forEach(function(a){a.onRender&&this._liveParticles.forEach(function(b){a.onRender(b)})}.bind(this));return this};
-Fireworks.Emitter.prototype.killParticle=function(a){var b=this._liveParticles.indexOf(a);console.assert(-1!==b);this._liveParticles.splice(b,1);this._deadParticles.push(a);this.effects().forEach(function(b){b.onDeath&&b.onDeath(a)}.bind(this))};Fireworks.Emitter.prototype.spawnParticle=function(){var a=this.deadParticles().pop();this.liveParticles().push(a);this.effects().forEach(function(b){b.onBirth&&b.onBirth(a)}.bind(this))};Fireworks.Spawner=function(){this._isRunning=!1};
-Fireworks.Spawner.prototype.start=function(){this._isRunning=!0};Fireworks.Spawner.prototype.stop=function(){this._isRunning=!1};Fireworks.Spawner.prototype.isRunning=function(){return this._isRunning};Fireworks.Particle=function(){};Fireworks.Particle.prototype.set=function(a,b){console.assert(void 0===this[a],"key already defined: "+a);this[a]=b;return this[a]};Fireworks.Particle.prototype.get=function(a){console.assert(void 0!==this[a],"key undefined: "+a);return this[a]};
-Fireworks.Particle.prototype.has=function(a){return void 0!==this[a]?!0:!1};Fireworks.EffectsStackBuilder=function(a){this._emitter=a};Fireworks.EffectsStackBuilder.prototype.back=function(){return this._emitter};Fireworks.EffectsStackBuilder.prototype.createEffect=function(a,b){return Fireworks.createEffect(a,b).pushTo(this._emitter).back(this)};
-Fireworks.createEffect=function(a,b){"object"===typeof a&&(b=a,a=void 0);var c=new Fireworks.Effect;c.opts=b;c.name=a;c.back=null;var d={onCreate:function(a){c.onCreate=a;return d},onBirth:function(a){c.onBirth=a;return d},onUpdate:function(a){c.onUpdate=a;return d},onDeath:function(a){c.onDeath=a;return d},onPreRender:function(a){c.onPreRender=a;return d},onRender:function(a){c.onRender=a;return d},pushTo:function(a){a.effects().push(c);return d},back:function(a){if(a===void 0)return c.back;c.back=
-a;return d},effect:function(){return c}};return d};Fireworks.Effect=function(){};Fireworks.Shape=function(){};Fireworks.createVector=function(a,b,c){return new Fireworks.Vector(a,b,c)};Fireworks.Vector=function(a,b,c){this.x=a||0;this.y=b||0;this.z=c||0};
+return this};Fireworks.Emitter.prototype.update=function(a){this._spawner.update(this,a);this._effects.forEach(function(b){b.onUpdate&&this._liveParticles.forEach(function(c){b.onUpdate(c,a)})}.bind(this));return this};
+Fireworks.Emitter.prototype.render=function(){this._effects.forEach(function(a){if(a.onPreRender)a.onPreRender()}.bind(this));this._effects.forEach(function(a){a.onRender&&this._liveParticles.forEach(function(b){a.onRender(b)})}.bind(this));this._effects.forEach(function(a){if(a.onPostRender)a.onPostRender()}.bind(this));return this};
+Fireworks.Emitter.prototype.killParticle=function(a){var b=this._liveParticles.indexOf(a);console.assert(-1!==b);this._liveParticles.splice(b,1);this._deadParticles.push(a);this.effects().forEach(function(b){b.onDeath&&b.onDeath(a)}.bind(this))};Fireworks.Emitter.prototype.spawnParticle=function(){console.assert(1<=this._deadParticles.length,"no more particle available");var a=this.deadParticles().pop();this.liveParticles().push(a);this.effects().forEach(function(b){b.onBirth&&b.onBirth(a)}.bind(this))};
+Fireworks.Spawner=function(){this._isRunning=!1};Fireworks.Spawner.prototype.start=function(){this._isRunning=!0};Fireworks.Spawner.prototype.stop=function(){this._isRunning=!1};Fireworks.Spawner.prototype.isRunning=function(){return this._isRunning};Fireworks.Particle=function(){};Fireworks.Particle.prototype.set=function(a,b){console.assert(void 0===this[a],"key already defined: "+a);this[a]=b;return this[a]};
+Fireworks.Particle.prototype.get=function(a){console.assert(void 0!==this[a],"key undefined: "+a);return this[a]};Fireworks.Particle.prototype.has=function(a){return void 0!==this[a]?!0:!1};Fireworks.EffectsStackBuilder=function(a){this._emitter=a};Fireworks.EffectsStackBuilder.prototype.back=function(){return this._emitter};Fireworks.EffectsStackBuilder.prototype.createEffect=function(a,b){return Fireworks.createEffect(a,b).pushTo(this._emitter).back(this)};
+Fireworks.createEffect=function(a,b){"object"===typeof a&&(b=a,a=void 0);var c=new Fireworks.Effect;c.opts=b;c.name=a;c.back=null;var d={onCreate:function(a){c.onCreate=a;return d},onBirth:function(a){c.onBirth=a;return d},onUpdate:function(a){c.onUpdate=a;return d},onDeath:function(a){c.onDeath=a;return d},onPreRender:function(a){c.onPreRender=a;return d},onRender:function(a){c.onRender=a;return d},onPostRender:function(a){c.onPostRender=a;return d},onIntensityChange:function(a){c.onIntensityChange=
+a;return d},pushTo:function(a){a.effects().push(c);return d},back:function(a){if(a===void 0)return c.back;c.back=a;return d},effect:function(){return c}};return d};Fireworks.Effect=function(){};Fireworks.Shape=function(){};Fireworks.createVector=function(a,b,c){return new Fireworks.Vector(a,b,c)};Fireworks.Vector=function(a,b,c){this.x=a||0;this.y=b||0;this.z=c||0};
Fireworks.Vector.prototype={constructor:Fireworks.Vector,set:function(a,b,c){this.x=a;this.y=b;this.z=c;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},setZ:function(a){this.z=a;return this},random:function(){this.x=Math.random()-0.5;this.y=Math.random()-0.5;this.z=Math.random()-0.5;return this},toString:function(){return JSON.stringify(this)},copy:function(a){this.x=a.x;this.y=a.y;this.z=a.z;return this},add:function(a,b){this.x=a.x+b.x;this.y=a.y+b.y;this.z=
a.z+b.z;return this},addSelf:function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z;return this},addScalar:function(a){this.x+=a;this.y+=a;this.z+=a;return this},sub:function(a,b){this.x=a.x-b.x;this.y=a.y-b.y;this.z=a.z-b.z;return this},subSelf:function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z;return this},multiply:function(a,b){this.x=a.x*b.x;this.y=a.y*b.y;this.z=a.z*b.z;return this},multiplySelf:function(a){this.x*=a.x;this.y*=a.y;this.z*=a.z;return this},multiplyScalar:function(a){this.x*=a;this.y*=a;
this.z*=a;return this},divideSelf:function(a){this.x/=a.x;this.y/=a.y;this.z/=a.z;return this},divideScalar:function(a){a?(this.x/=a,this.y/=a,this.z/=a):this.z=this.y=this.x=0;return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y+this.z*a.z},lengthSq:function(){return this.x*this.x+this.y*this.y+this.z*this.z},length:function(){return Math.sqrt(this.lengthSq())},normalize:function(){return this.divideScalar(this.length())},setLength:function(a){return this.normalize().multiplyScalar(a)},
View
5 examples/plugins/fireworks.bindtriggerdomeventsto.js
@@ -12,20 +12,19 @@ Fireworks.BindTriggerDomEvents = function(emitter, domElement){
this._domElement.addEventListener('mousedown' , this._onMouseDown );
this._domElement.addEventListener('mouseup' , this._onMouseUp );
-
// change emitter intensity on mousewheel
this._onMouseWheel = function(event){
var intensity = emitter.intensity();
intensity += event.wheelDelta < 0 ? -0.05 : 0.05;
intensity = Math.max(intensity, 0);
intensity = Math.min(intensity, 1);
- emitter.intensity(intensity)
+ emitter.intensity(intensity);
};
this._domElement.addEventListener('mousewheel' , this._onMouseWheel );
}
-Fireworks.BindTriggerDomEvents.prototype.destroy = function() {
+Fireworks.BindTriggerDomEvents.prototype.destroy = function(){
this._domElement.removeEventListener('mousedown' , this._onMouseDown );
this._domElement.removeEventListener('mouseup' , this._onMouseUp );
this._domElement.removeEventListener('mousewheel' , this._onMouseWheel );
View
34 examples/renderer_canvas/canvas_example.html
@@ -1,28 +1,6 @@
<!doctype html><title>Example of firework.js</title>
-
-<script src="../../src/core.js"></script>
-<script src="../../src/emitter.js"></script>
-<script src="../../src/particle.js"></script>
-<script src="../../src/effect.js"></script>
-<script src="../../src/spawner.js"></script>
-<script src="../../src/shape.js"></script>
-<script src="../../src/vector.js"></script>
-
-<script src="../plugins/fireworks.bindtriggerdomeventsto.js"></script>
-
-<script src="../plugins/spawner.steadyrate.js"></script>
-<script src="../plugins/shape.box.js"></script>
-<script src="../plugins/shape.sphere.js"></script>
-<script src="../plugins/shape.point.js"></script>
-
-<script src="../plugins/effect.friction.js"></script>
-<script src="../plugins/effect.lifetime.js"></script>
-<script src="../plugins/effect.position.js"></script>
-<script src="../plugins/effect.velocity.js"></script>
-<script src="../plugins/effect.radialvelocity.js"></script>
-<script src="../plugins/effect.randomvelocitydrift.js"></script>
-<script src="../plugins/effect.rendertocanvas.js"></script>
-
+<script src="../../build/fireworks-bundle.js"></script>
+<script src="../vendor/dat.gui.js"></script>
<body><script>
// build canvas element
var canvas = document.createElement('canvas');
@@ -44,7 +22,7 @@
var emitter = Fireworks.createEmitter({nParticles : 400})
.useSpawnerSteadyRate(40)
- .bindTriggerDomEvents()
+ //.bindTriggerDomEvents()
.effectsStackBuilder()
.position(Fireworks.createShapeSphere(0, 0, 0, 10))
.radialVelocity(100, 200)
@@ -70,11 +48,15 @@
.createEffect('intensityChange')
.onIntensityChange(function(intensity){
emitter.spawner().rate(40*intensity);
- //console.log('intensity', emitter.intensity())
+ console.log('intensity', emitter.intensity())
}).back()
.back()
.start()
+ var data = {x:42};
+ var gui = new Fireworks.DatGui4Emitter(emitter);
+ var folder = gui.addFolder('test color');
+ folder.add(data, 'x')
setInterval(function(){
// clear the screen

0 comments on commit a6402fc

Please sign in to comment.