From 3a1726006311058a4344945a5b2806c64821cf9c Mon Sep 17 00:00:00 2001 From: ajie Date: Sun, 10 Sep 2017 14:51:37 +0800 Subject: [PATCH] update v2.2.1 update v2.2.1 --- README.md | 32 +- bower.json | 4 +- build/build.js | 105 +- build/config | 24 +- build/proton-2.1.0.min.js | 10 - build/{proton-2.1.0.js => proton.js} | 1494 +++++++++++++---- build/proton.min.js | 10 + example/behaviour/attraction/attraction1.html | 2 +- example/behaviour/attraction/attraction2.html | 2 +- example/behaviour/collision/collision.html | 2 +- .../behaviour/collision/collisionBall.html | 2 +- example/behaviour/color/color.html | 2 +- example/behaviour/custom/circle.html | 2 +- example/behaviour/force/force.html | 2 +- example/behaviour/force/star.html | 2 +- example/behaviour/gravitywell/linebug.html | 2 +- .../behaviour/randomDirft/randomdirft1.html | 2 +- .../behaviour/randomDirft/randomdirft2.html | 2 +- .../behaviour/randomDirft/randomdirft3.html | 2 +- example/behaviour/repulsion/fireflies.html | 2 +- example/behaviour/repulsion/repulsion.html | 2 +- example/behaviour/rotate/rotate.html | 2 +- .../emitter/followEmitter/followEmitter.html | 2 +- example/emitter/followEmitter/mouseDown.html | 2 +- example/game/colliejs/collie.html | 2 +- example/game/crafty/asteroids.html | 2 +- example/game/easeljs/easeljs.html | 2 +- example/game/quarkjs/squirrel.html | 2 +- example/helloworld/emitter/emitter.html | 2 +- example/initialize/imagetarget/Spitfire.html | 2 +- example/initialize/imagetarget/fire2.html | 2 +- .../initialize/imagetarget/imagetarget.html | 2 +- example/render/custom/pixijs.html | 2 +- example/render/dom/canvasVSdom.html | 2 +- example/render/dom/domrender.html | 2 +- example/render/dom/jpgmove.html | 2 +- example/render/dom/webglVSdom.html | 2 +- example/render/easeljs/easeljs.html | 2 +- example/render/pixel/google.html | 2 +- example/render/pixel/pixelrender.html | 2 +- example/render/pixel/thousand.html | 2 +- example/render/webgl/webglrender.html | 2 +- example/sparks/bigfire/bigfire.html | 2 +- example/sparks/bomb/bomb.html | 2 +- example/sparks/drugs/drugs.html | 2 +- .../sparks/eightDiagrams/eightDiagrams.html | 2 +- example/sparks/firework/fireworks.html | 2 +- example/sparks/sun/fireball.html | 2 +- example/sparks/sun/sun.html | 2 +- example/zone/circlezone/circlezone.html | 2 +- example/zone/imagezone/imagezone.html | 2 +- example/zone/linezone/bound.html | 2 +- example/zone/pointzone/pointzone.html | 2 +- package.json | 7 +- src/core/Particle.js | 10 +- src/core/Proton.js | 2 +- src/debug/Debug.js | 2 + src/debug/log.js | 35 - src/math/Vector2D.js | 60 - src/plus/ease.js | 134 +- 60 files changed, 1326 insertions(+), 695 deletions(-) delete mode 100644 build/proton-2.1.0.min.js rename build/{proton-2.1.0.js => proton.js} (77%) create mode 100644 build/proton.min.js delete mode 100644 src/debug/log.js diff --git a/README.md b/README.md index ec0af65..081ff3d 100644 --- a/README.md +++ b/README.md @@ -18,27 +18,33 @@ Check out examples at http://a-jie.github.io/Proton/ - Integratable into any game engine - Veriety of behaviors - Three kinds of emitters which can simulate many different physical effects -- The 3d version of the proton engine is here https://a-jie.github.io/three.proton/ +- The __3D version__ of the proton engine is here [https://a-jie.github.io/three.proton/](https://a-jie.github.io/three.proton/) ## Usage ```javascript var proton = new Proton(); var emitter = new Proton.Emitter(); + //set Rate emitter.rate = new Proton.Rate(Proton.getSpan(10, 20), 0.1); + //add Initialize emitter.addInitialize(new Proton.Radius(1, 12)); emitter.addInitialize(new Proton.Life(2, 4)); emitter.addInitialize(new Proton.Velocity(3, Proton.getSpan(0, 360), 'polar')); + //add Behaviour emitter.addBehaviour(new Proton.Color('ff0000', 'random')); emitter.addBehaviour(new Proton.Alpha(1, 0)); + //set emitter position emitter.p.x = canvas.width / 2; emitter.p.y = canvas.height / 2; emitter.emit(); + //add emitter to the proton proton.addEmitter(emitter); + // add canvas renderer var renderer = new Proton.Renderer('canvas', proton, canvas); renderer.start(); @@ -48,12 +54,24 @@ Proton.USE_CLOCK = false or true; ``` ## Building Proton -Node is a dependency, use terminal to install it with with:
-`git clone git://github.com/a-jie/Proton.git`
-Then navigate to the build directory by running:
-`cd ./build`
-Finally run the build command:
-`node build.js` +Node is a dependency, use terminal to install it with with: +`git clone git://github.com/a-jie/Proton.git` + +Then navigate to the build directory by running: + +``` +cd ./build +node build.js +``` + +Or use npm script +``` +npm run build +``` + +## Changelog +Detailed changes for each release are documented in the [release notes](https://github.com/a-jie/Proton/releases). + ## License Proton is released under the MIT License. http://www.opensource.org/licenses/mit-license diff --git a/bower.json b/bower.json index 6879f05..b2f3f08 100644 --- a/bower.json +++ b/bower.json @@ -1,12 +1,12 @@ { "name": "Proton", - "version": "2.1.0", + "version": "2.2.1", "homepage": "http://a-jie.github.io/Proton", "authors": [ "a-jie " ], "description": "Proton is an easily customizable html5 particle engine including five different types of renderers.", - "main": "build/proton-2.1.0.min.js", + "main": "build/proton.min.js", "license": "MIT", "ignore": [ "**/.*", diff --git a/build/build.js b/build/build.js index 8b66696..a285307 100644 --- a/build/build.js +++ b/build/build.js @@ -1,19 +1,19 @@ var fs = require("fs"), - uglify = { - parser: require("./lib/parse-js.js"), - processor: require("./lib/process.js") - }, - - // Set the config filename - configfile = "config", - - config, version, source_dir, output_full, output_min, head, filenames, foot, i, - ast, minified_source, - - files = [], - numFiles = 0, - - source = ""; + uglify = { + parser: require("./lib/parse-js.js"), + processor: require("./lib/process.js") + }, + + // Set the config filename + configfile = "config", + + config, version, source_dir, output_full, output_min, head, umd, filenames, foot, i, + ast, minified_source, + + files = [], + numFiles = 0, + + source = ""; // Get config file console.log("Reading config file..."); @@ -21,60 +21,51 @@ config = fs.readFileSync(configfile, "UTF-8"); // Get variables from config file version = /^version = (.*)$/m.exec(config)[1], -source_dir = /^source_dir = (.*)$/m.exec(config)[1], -output_full = /^output_full = (.*)$/m.exec(config)[1].replace("{version}", version), -output_min = /^output_min = (.*)$/m.exec(config)[1].replace("{version}", version), -head = /head\s-----\s([\s\S]*?)-----\s/g.exec(config)[1].replace("{version}", version).replace("{year}", "2011-" + (new Date()).getFullYear()), -filenames = /files\s-----\s([\s\S]*?)\s-----/g.exec(config)[1].split(/\s/); -foot = /foot\s-----\s([\s\S]*?)\s-----/g.exec(config)[1].split(/\s/); + source_dir = /^source_dir = (.*)$/m.exec(config)[1], + output_full = /^output_full = (.*)$/m.exec(config)[1].replace("{version}", version), + output_min = /^output_min = (.*)$/m.exec(config)[1].replace("{version}", version), + head = /head\s-----\s([\s\S]*?)-----\s/g.exec(config)[1].replace("{version}", version).replace("{year}", "2011-" + (new Date()).getFullYear()), + umd = /umd\s-----\s([\s\S]*?)-----\s/g.exec(config)[1], + filenames = /files\s-----\s([\s\S]*?)\s-----/g.exec(config)[1].split(/\s/); + numFiles = filenames.length; -filenames = filenames.concat(foot); // Get all the source files for (i = 0; i < filenames.length; i++) { - console.log("Reading file: " + filenames[i]); - - // Add current file - files.push({ - name: filenames[i], - content: fs.readFileSync(source_dir + filenames[i], "UTF-8") - }); + console.log("Reading file: " + filenames[i]); + + // Add current file + files.push({ + name: filenames[i], + content: fs.readFileSync(source_dir + filenames[i], "UTF-8") + }); } - + // Start the building process console.log("Building source file..."); -// Add the head code to the top of the file -source = head; - -// Loop through all files and append the source +source = head + umd; for (i = 0; i < numFiles; i++) { - // Replace the self executing anonymous functions that wrap each file - // Only the end of core will be removed, and added to the end of the new file - if (files[i].name === "core/Proton.js") { - files[i].content = files[i].content.replace(/\}(\s|)\)(\s|)\(window(\s|)\);/, ""); - } else { - files[i].content = files[i].content.replace(/\(function(\s|)\((\s|)Proton,(\s|)undefined(\s|)\)(\s|)\{/, ""); - files[i].content = files[i].content.replace(/\}(\s|)\)(\s|)\((\s|)Proton(\s|)\);/, ""); - } - - // Append the file to the full source - source += "\n" + files[i].content; - - // Append the end of the core wrapper - if (i === numFiles - 1) { - source += "\n})(window);"; - } -} + if (files[i].name === "core/Proton.js") { + files[i].content = files[i].content.replace(/\}(\s|)\)(\s|)\(window(\s|)\);/, ""); + files[i].content = files[i].content.replace(/\(function\(window\,\sundefined\)\s\{/, ""); + files[i].content = files[i].content.replace(/window\.Proton\s\=\sProton\;/, ""); + } else { + files[i].content = files[i].content.replace(/\(function(\s|)\((\s|)Proton,(\s|)undefined(\s|)\)(\s|)\{/, ""); + files[i].content = files[i].content.replace(/\}(\s|)\)(\s|)\((\s|)Proton(\s|)\);/, ""); + } -// Loop through all foot files -for (i = numFiles; i < numFiles + foot.length; i++) { + // Append the file to the full source + source += "\n" + files[i].content; - // Append the file to the full source - source += "\n" + files[i].content; + // Append the end of the core wrapper + if (i === numFiles - 1) { + //source += "\n})(window);"; + source += "\n\n return Proton;\n}));"; + } } - +///console.log(umd); // Save source to output file fs.writeFile(output_full, source, "UTF-8"); console.log("Source file saved as: " + output_full); @@ -89,4 +80,4 @@ minified_source = uglify.processor.gen_code(ast); // Save minified source file fs.writeFile(output_min, head + minified_source, "UTF-8"); -console.log("Minified source file saved as: " + output_min); +console.log("Minified source file saved as: " + output_min); \ No newline at end of file diff --git a/build/config b/build/config index aafad3b..dbbedc7 100644 --- a/build/config +++ b/build/config @@ -1,7 +1,7 @@ -version = 2.1.0 +version = 2.2.1 source_dir = ../src/ -output_full = proton-{version}.js -output_min = proton-{version}.min.js +output_full = proton.js +output_min = proton.min.js head ----- @@ -16,6 +16,19 @@ head */ ----- +umd +----- +(function (root, factory) { + if (typeof define === 'function' && define.amd) { + define([], factory); + } else if (typeof module !== 'undefined' && module.exports) { + module.exports = factory(); + } else { + root.Proton = factory(); + } +}(this, function () { +----- + files ----- core/Proton.js @@ -73,11 +86,6 @@ zone/CircleZone.js zone/PointZone.js zone/RectZone.js zone/ImageZone.js -debug/log.js debug/Debug.js ------ - -foot ------ plus/requestAnimationFrame.js ----- \ No newline at end of file diff --git a/build/proton-2.1.0.min.js b/build/proton-2.1.0.min.js deleted file mode 100644 index e545898..0000000 --- a/build/proton-2.1.0.min.js +++ /dev/null @@ -1,10 +0,0 @@ -/*! - * Proton v2.1.0 - * https://github.com/a-jie/Proton - * - * Copyright 2011-2016, A-JIE - * Licensed under the MIT license - * http://www.opensource.org/licenses/mit-license - * - */ -(function(a,b){function bf(a,b,c,d){bf._super_.call(this),this.reset(a,b,c,d)}function be(a,b,c,d){be._super_.call(this),this.x=a,this.y=b,this.width=c,this.height=d}function bd(a,b){bd._super_.call(this),this.x=a,this.y=b}function bc(a,b,c){bc._super_.call(this),this.x=a,this.y=b,this.radius=c,this.angle=0,this.center={x:this.x,y:this.y}}function bb(a,b,d,e,f){bb._super_.call(this),d-a>=0?(this.x1=a,this.y1=b,this.x2=d,this.y2=e):(this.x1=d,this.y1=e,this.x2=a,this.y2=b),this.dx=this.x2-this.x1,this.dy=this.y2-this.y1,this.minx=Math.min(this.x1,this.x2),this.miny=Math.min(this.y1,this.y2),this.maxx=Math.max(this.x1,this.x2),this.maxy=Math.max(this.y1,this.y2),this.dot=this.x2*this.y1-this.x1*this.y2,this.xxyy=this.dx*this.dx+this.dy*this.dy,this.gradient=this.getGradient(),this.length=this.getLength(),this.direction=c.Util.initValue(f,">")}function ba(){this.vector=new c.Vector2D(0,0),this.random=0,this.crossType="dead",this.alert=!0}function _(a,b){_._super_.call(this,a,b),this.gl=this.element.getContext("experimental-webgl",{antialias:!0,stencil:!1,depth:!1}),this.gl||alert("Sorry your browser do not suppest WebGL!"),this.initVar(),this.setMaxRadius(),this.initShaders(),this.initBuffers(),this.gl.blendEquation(this.gl.FUNC_ADD),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.enable(this.gl.BLEND)}function $(a,b,c){$._super_.call(this,a,b),this.context=this.element.getContext("2d"),this.imageData=null,this.rectangle=null,this.rectangle=c,this.createImageData(c)}function Z(a,b){Z._super_.call(this,a,b),this.stroke=null,this.context=this.element.getContext("2d"),this.bufferCache={}}function Y(a,b,c){Y._super_.call(this,a,b),this.stroke=c}function X(a,b){X._super_.call(this,a,b),this.stroke=null}function W(a,b,d){this.proton=a,this.element=b,this.stroke=d,this.pool=new c.Pool}function V(a,b,d){this.element=d,this.type=c.Util.initValue(a,"canvas"),this.proton=b,this.renderer=this.getRenderer()}function T(b,d,e){this.mouseTarget=c.Util.initValue(b,a),this.ease=c.Util.initValue(d,.7),this._allowEmitting=!1,this.initEventHandler(),T._super_.call(this,e)}function S(a){this.selfBehaviours=[],S._super_.call(this,a)}function R(a){this.initializes=[],this.particles=[],this.behaviours=[],this.emitTime=0,this.emitTotalTimes=-1,this.damping=.006,this.bindEmitter=!0,this.rate=new c.Rate(1,.1),R._super_.call(this,a),this.id="emitter_"+R.ID++}function Q(a,b,d,e){Q._super_.call(this,d,e),this.distanceVec=new c.Vector2D,this.centerPoint=c.Util.initValue(a,new c.Vector2D),this.force=c.Util.initValue(this.normalizeValue(b),100),this.name="GravityWell"}function P(a,b,c,d){P._super_.call(this,c,d),this.reset(a,b),this.name="Color"}function O(a,b,c,d,e){O._super_.call(this,d,e),this.reset(a,b,c),this.name="Rotate"}function N(a,b,c,d){N._super_.call(this,c,d),this.reset(a,b),this.name="Scale"}function M(a,b,c,d){M._super_.call(this,c,d),this.reset(a,b),this.name="Alpha"}function L(a,b,c,d){L._super_.call(this,c,d),this.reset(a,b),this.name="CrossZone"}function K(a,b,c,d,e){K._super_.call(this,d,e),this.reset(a,b,c),this.name="Collision"}function J(a,b,c){J._super_.call(this,0,a,b,c),this.name="Gravity"}function I(a,b,c,d,e){I._super_.call(this,a,b,c,d,e),this.force*=-1,this.name="Repulsion"}function H(a,b,c,d,e){H._super_.call(this,d,e),this.reset(a,b,c),this.time=0,this.name="RandomDrift"}function G(a,b,d,e,f){G._super_.call(this,e,f),this.targetPosition=c.Util.initValue(a,new c.Vector2D),this.radius=c.Util.initValue(d,1e3),this.force=c.Util.initValue(this.normalizeValue(b),100),this.radiusSq=this.radius*this.radius,this.attractionForce=new c.Vector2D,this.lengthSq=0,this.name="Attraction"}function F(a,b,d,e){F._super_.call(this,d,e),this.force=this.normalizeForce(new c.Vector2D(a,b)),this.name="Force"}function E(a,b,d){E._super_.call(this),this.image=this.setSpanValue(a),this.w=c.Util.initValue(b,20),this.h=c.Util.initValue(d,this.w)}function D(a,b,d){D._super_.call(this),this.radius=c.Util.setSpanValue(a,b,d)}function C(a,b,d){C._super_.call(this),this.massPan=c.Util.setSpanValue(a,b,d)}function B(a,b,d){B._super_.call(this),this.rPan=c.Util.setSpanValue(a),this.thaPan=c.Util.setSpanValue(b),this.type=c.Util.initValue(d,"vector")}function A(a){A._super_.call(this),this.zone=c.Util.initValue(a,new c.PointZone)}function z(a,b,d){z._super_.call(this),this.lifePan=c.Util.setSpanValue(a,b,d)}function x(){}function w(a,b){this.numPan=c.Util.initValue(a,1),this.timePan=c.Util.initValue(b,1),this.numPan=c.Util.setSpanValue(this.numPan),this.timePan=c.Util.setSpanValue(this.timePan),this.startTime=0,this.nextTime=0,this.init()}function v(a,b){this.id="Behaviour_"+v.id++,this.life=c.Util.initValue(a,Infinity),this.easing=c.ease.setEasingByName(b),this.age=0,this.energy=1,this.dead=!1,this.parents=[],this.name="Behaviour"}function t(a,b,c,d){this.x=a,this.y=b,this.width=c,this.height=d,this.bottom=this.y+this.height,this.right=this.x+this.width}function s(a){c.Util.isArray(a)?this.colorArr=a:this.colorArr=[a]}function r(a,b,d){this.isArray=!1,c.Util.isArray(a)?(this.isArray=!0,this.a=a):(this.a=c.Util.initValue(a,1),this.b=c.Util.initValue(b,this.a),this.center=c.Util.initValue(d,!1))}function k(){this.cID=0,this.list={}}function j(a){this.id="particle_"+j.ID++,this.reset(!0),c.Util.setPrototypeByObject(this,a)}function i(){this.mats=[],this.size=0;for(var a=0;a<20;a++)this.mats.push(c.Mat3.create([0,0,0,0,0,0,0,0,0]))}function d(){this.initialize()}function c(a,b){this.integrationType=c.Util.initValue(b,c.EULER),this.emitters=[],this.renderers=[],this.time=0,this.oldTime=0,c.pool=new c.Pool(100),c.integrator=new c.NumericalIntegration(this.integrationType)}c.POOL_MAX=1e3,c.TIME_STEP=60,c.USE_CLOCK=!1,c.MEASURE=100,c.EULER="euler",c.RK2="runge-kutta2",c.RK4="runge-kutta4",c.VERLET="verlet",c.PARTICLE_CREATED="partilcleCreated",c.PARTICLE_UPDATE="partilcleUpdate",c.PARTICLE_SLEEP="particleSleep",c.PARTICLE_DEAD="partilcleDead",c.PROTON_UPDATE="protonUpdate",c.PROTON_UPDATE_AFTER="protonUpdateAfter",c.EMITTER_ADDED="emitterAdded",c.EMITTER_REMOVED="emitterRemoved",c.amendChangeTabsBug=!0,c.TextureBuffer={},c.TextureCanvasBuffer={},c.prototype={addRender:function(a){a.proton=this,this.renderers.push(a.proton)},addEmitter:function(a){this.emitters.push(a),a.parent=this,this.dispatchEvent(c.EMITTER_ADDED,a)},removeEmitter:function(a){var b=this.emitters.indexOf(a);this.emitters.splice(b,1),a.parent=null,this.dispatchEvent(c.EMITTER_REMOVED,a)},update:function(){this.dispatchEvent(c.PROTON_UPDATE);if(c.USE_CLOCK){this.oldTime||(this.oldTime=(new Date).getTime());var a=(new Date).getTime();this.elapsed=(a-this.oldTime)/1e3,c.amendChangeTabsBug&&this.amendChangeTabsBug(),this.oldTime=a}else this.elapsed=.0167;if(this.elapsed>0)for(var b=0;b.5&&(this.oldTime=(new Date).getTime(),this.elapsed=0)},getCount:function(){var a=0,b=this.emitters.length;for(var c=0;c>b;return a+1},makeTranslation:function(a,b){return[1,0,0,0,1,0,a,b,1]},makeRotation:function(a){var b=Math.cos(a),c=Math.sin(a);return[b,-c,0,c,b,0,0,0,1]},makeScale:function(a,b){return[a,0,0,0,b,0,0,0,1]},matrixMultiply:function(a,b){var c=a[0],d=a[1],e=a[2],f=a[3],g=a[4],h=a[5],i=a[6],j=a[7],k=a[8],l=b[0],m=b[1],n=b[2],o=b[3],p=b[4],q=b[5],r=b[6],s=b[7],t=b[8];return[c*l+d*o+e*r,c*m+d*p+e*s,c*n+d*q+e*t,f*l+g*o+h*r,f*m+g*p+h*s,f*n+g*q+h*t,i*l+j*o+k*r,i*m+j*p+k*s,i*n+j*q+k*t]}};c.WebGLUtil=g;var h=h||{createCanvas:function(a,b,c,d){var e=document.createElement("canvas"),f=d?d:"absolute";e.id=a,e.width=b,e.height=c,e.style.position=f,e.style.opacity=0,this.transformDom(e,-500,-500,0,0);return e},transformDom:function(a,b,c,d,e){a.style.WebkitTransform="translate("+b+"px, "+c+"px) "+"scale("+d+") "+"rotate("+e+"deg)",a.style.MozTransform="translate("+b+"px, "+c+"px) "+"scale("+d+") "+"rotate("+e+"deg)",a.style.OTransform="translate("+b+"px, "+c+"px) "+"scale("+d+") "+"rotate("+e+"deg)",a.style.msTransform="translate("+b+"px, "+c+"px) "+"scale("+d+") "+"rotate("+e+"deg)",a.style.transform="translate("+b+"px, "+c+"px) "+"scale("+d+") "+"rotate("+e+"deg)"}};c.DomUtil=h,i.prototype.set=function(a,b){b==0?c.Mat3.set(a,this.mats[0]):c.Mat3.multiply(this.mats[b-1],a,this.mats[b]),this.size=Math.max(this.size,b+1)},i.prototype.push=function(a){this.size==0?c.Mat3.set(a,this.mats[0]):c.Mat3.multiply(this.mats[this.size-1],a,this.mats[this.size]),this.size++},i.prototype.pop=function(){this.size>0&&this.size--},i.prototype.top=function(){return this.mats[this.size-1]},c.MStack=i,j.ID=0,j.prototype={getDirection:function(){return Math.atan2(this.v.x,-this.v.y)*(180/Math.PI)},reset:function(a){this.life=Infinity,this.age=0,this.energy=1,this.dead=!1,this.sleep=!1,this.target=null,this.sprite=null,this.parent=null,this.mass=1,this.radius=10,this.alpha=1,this.scale=1,this.rotation=0,this.color=null,this.easing=c.ease.setEasingByName(c.easeLinear),a?(this.transform={},this.p=new c.Vector2D,this.v=new c.Vector2D,this.a=new c.Vector2D,this.old={p:new c.Vector2D,v:new c.Vector2D,a:new c.Vector2D},this.behaviours=[]):(c.Util.destroyObject(this.transform),this.p.set(0,0),this.v.set(0,0),this.a.set(0,0),this.old.p.set(0,0),this.old.v.set(0,0),this.old.a.set(0,0),this.removeAllBehaviours()),this.transform.rgb={r:255,g:255,b:255};return this},update:function(a,b){if(!this.sleep){this.age+=a;var c=this.behaviours.length,d;for(d=0;d=this.life)this.destroy();else{var e=this.easing(this.age/this.life);this.energy=Math.max(1-e,0)}},addBehaviour:function(a){this.behaviours.push(a),a.hasOwnProperty("parents")&&a.parents.push(this),a.initialize(this)},addBehaviours:function(a){var b=a.length,c;for(c=0;c-1){var a=this.behaviours.splice(b,1);a.parents=null}},removeAllBehaviours:function(){c.Util.destroyArray(this.behaviours)},destroy:function(){this.removeAllBehaviours(),this.energy=0,this.dead=!0,this.parent=null}},c.Particle=j,k.prototype={create:function(a,b){this.cID++;return typeof a=="function"?c.Util.classApply(a,b):a.clone()},getCount:function(){var a=0;for(var b in this.list)a+=this.list[b].length;return a++},get:function(a,b){var c,d=a.__puid||l.id(a);this.list[d]&&this.list[d].length>0?c=this.list[d].pop():c=this.create(a,b),c.__puid=a.__puid||d;return c},set:function(a){return this._getList(a.__puid).push(a)},destroy:function(){for(var a in this.list)this.list[a].length=0,delete this.list[a]},_getList:function(a){a=a||"default",this.list[a]||(this.list[a]=[]);return this.list[a]}},c.Pool=k;var l={_id:0,_uids:{},id:function(a){for(var b in this._uids)if(this._uids[b]==a)return b;var c="PUID_"+this._id++;this._uids[c]=a;return c},hash:function(a){return}},m={randomAToB:function(a,b,c){return c?Math.floor(Math.random()*(b-a))+a:a+Math.random()*(b-a)},randomFloating:function(a,b,c){return m.randomAToB(a-b,a+b,c)},randomZone:function(a){},degreeTransform:function(a){return a*Math.PI/180},toColor16:function(a){return"#"+a.toString(16)},randomColor:function(){return"#"+("00000"+(Math.random()*16777216<<0).toString(16)).slice(-6)}};c.MathUtils=m;var o=function(a){this.type=c.Util.initValue(a,c.EULER)};o.prototype={integrate:function(a,b,c){this.eulerIntegrate(a,b,c)},eulerIntegrate:function(a,b,c){a.sleep||(a.old.p.copy(a.p),a.old.v.copy(a.v),a.a.multiplyScalar(1/a.mass),a.v.add(a.a.multiplyScalar(b)),a.p.add(a.old.v.multiplyScalar(b)),c&&a.v.multiplyScalar(c),a.a.clear())}},c.NumericalIntegration=o;var p=function(a,b){this.x=a||0,this.y=b||0};p.prototype={set:function(a,b){this.x=a,this.y=b;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},setComponent:function(a,b){switch(a){case 0:this.x=b;break;case 1:this.y=b;break;default:throw new Error("index is out of range: "+a)}},getGradient:function(){if(this.x!=0)return Math.atan2(this.y,this.x);if(this.y>0)return Math.PI/2;if(this.y<0)return-Math.PI/2},getComponent:function(a){switch(a){case 0:return this.x;case 1:return this.y;default:throw new Error("index is out of range: "+a)}},copy:function(a){this.x=a.x,this.y=a.y;return this},add:function(a,c){if(c!==b)return this.addVectors(a,c);this.x+=a.x,this.y+=a.y;return this},addXY:function(a,b){this.x+=a,this.y+=b;return this},addVectors:function(a,b){this.x=a.x+b.x,this.y=a.y+b.y;return this},addScalar:function(a){this.x+=a,this.y+=a;return this},sub:function(a,c){if(c!==b)return this.subVectors(a,c);this.x-=a.x,this.y-=a.y;return this},subVectors:function(a,b){this.x=a.x-b.x,this.y=a.y-b.y;return this},multiplyScalar:function(a){this.x*=a,this.y*=a;return this},divideScalar:function(a){a!==0?(this.x/=a,this.y/=a):this.set(0,0);return this},min:function(a){this.x>a.x&&(this.x=a.x),this.y>a.y&&(this.y=a.y);return this},max:function(a){this.xb.x&&(this.x=b.x),this.yb.y&&(this.y=b.y);return this},negate:function(){return this.multiplyScalar(-1)},dot:function(a){return this.x*a.x+this.y*a.y},lengthSq:function(){return this.x*this.x+this.y*this.y},length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},normalize:function(){return this.divideScalar(this.length())},distanceTo:function(a){return Math.sqrt(this.distanceToSquared(a))},rotate:function(a){var b=this.x,c=this.y;this.x=b*Math.cos(a)+c*Math.sin(a),this.y=-b*Math.sin(a)+c*Math.cos(a);return this},distanceToSquared:function(a){var b=this.x-a.x,c=this.y-a.y;return b*b+c*c},setLength:function(a){var b=this.length();b!==0&&a!==b&&this.multiplyScalar(a/b);return this},lerp:function(a,b){this.x+=(a.x-this.x)*b,this.y+=(a.y-this.y)*b;return this},equals:function(a){return a.x===this.x&&a.y===this.y},toArray:function(){return[this.x,this.y]},clear:function(){this.x=0,this.y=0;return this},clone:function(){return new c.Vector2D(this.x,this.y)}},c.Vector2D=p;var q=function(a,b){this.r=Math.abs(a)||0,this.tha=b||0};q.prototype={set:function(a,b){this.r=a,this.tha=b;return this},setR:function(a){this.r=a;return this},setTha:function(a){this.tha=a;return this},copy:function(a){this.r=a.r,this.tha=a.tha;return this},toVector:function(){return new c.Vector2D(this.getX(),this.getY())},getX:function(){return this.r*Math.sin(this.tha)},getY:function(){return-this.r*Math.cos(this.tha)},normalize:function(){this.r=1;return this},equals:function(a){return a.r===this.r&&a.tha===this.tha},toArray:function(){return[this.r,this.tha]},clear:function(){this.r=0,this.tha=0;return this},clone:function(){return new c.Polar2D(this.r,this.tha)}},c.Polar2D=q,r.prototype={getValue:function(a){return this.isArray?this.a[Math.floor(this.a.length*Math.random())]:this.center?c.MathUtils.randomFloating(this.a,this.b,a):c.MathUtils.randomAToB(this.a,this.b,a)}},c.Span=r,c.getSpan=function(a,b,d){return new c.Span(a,b,d)},c.Util.inherits(s,c.Span),s.prototype.getValue=function(){var a=this.colorArr[Math.floor(this.colorArr.length*Math.random())];return a=="random"||a=="Random"?c.MathUtils.randomColor():a},c.ColorSpan=s,t.prototype={contains:function(a,b){return a<=this.right&&a>=this.x&&b<=this.bottom&&b>=this.y?!0:!1}},c.Rectangle=t;var u=u||{create:function(a){var b=new Float32Array(9);a&&this.set(a,b);return b},set:function(a,b){for(var c=0;c<9;c++)b[c]=a[c];return b},multiply:function(a,b,c){var d=a[0],e=a[1],f=a[2],g=a[3],h=a[4],i=a[6],j=a[7],k=b[0],l=b[1],m=b[2],n=b[3],o=b[4],p=b[6],q=b[7];c[0]=k*d+l*g,c[1]=k*e+l*h,c[2]=f*m,c[3]=n*d+o*g,c[4]=n*e+o*h,c[6]=p*d+q*g+i,c[7]=p*e+q*h+j;return c},inverse:function(a,b){var c=a[0],d=a[1],e=a[3],f=a[4],g=a[6],h=a[7],i=f,j=-e,k=h*e-f*g,l=c*i+d*j,m;m=1/l,b[0]=i*m,b[1]=-d*m,b[3]=j*m,b[4]=c*m,b[6]=k*m,b[7]=(-h*c+d*g)*m;return b},multiplyVec2:function(a,b,c){var d=b[0],e=b[1];c[0]=d*a[0]+e*a[3]+a[6],c[1]=d*a[1]+e*a[4]+a[7];return c}};c.Mat3=u,v.id=0,v.prototype={reset:function(a,b){this.life=c.Util.initValue(a,Infinity),this.easing=c.Util.initValue(b,c.ease.setEasingByName(c.easeLinear))},normalizeForce:function(a){return a.multiplyScalar(c.MEASURE)},normalizeValue:function(a){return a*c.MEASURE},initialize:function(a){},applyBehaviour:function(a,b,c){this.age+=b;if(this.age>=this.life||this.dead)this.energy=0,this.dead=!0,this.destroy();else{var d=this.easing(a.age/a.life);this.energy=Math.max(1-d,0)}},destroy:function(){var a,b=this.parents.length,c;for(c=0;c=this.nextTime){this.startTime=0,this.nextTime=this.timePan.getValue();return this.numPan.b==1?this.numPan.getValue(!1)>.5?1:0:this.numPan.getValue(!0)}return 0}},c.Rate=w,x.prototype.reset=function(){},x.prototype.init=function(a,b){b?this.initialize(b):this.initialize(a)},x.prototype.initialize=function(a){},c.Initialize=x;var y={initialize:function(a,b,d){var e=d.length,f;for(f=0;f4e-6&&this.lengthSq=this.delay&&(a.a.addXY(c.MathUtils.randomAToB(-this.panFoce.x,this.panFoce.x),c.MathUtils.randomAToB(-this.panFoce.y,this.panFoce.y)),this.time=0)},c.RandomDrift=H,c.Util.inherits(I,c.Attraction),I.prototype.reset=function(a,b,c,d,e){I._super_.prototype.reset.call(this,a,b,c,d,e),this.force*=-1},c.Repulsion=I,c.Util.inherits(J,c.Force),J.prototype.reset=function(a,b,c){J._super_.prototype.reset.call(this,0,a,b,c)},c.Gravity=J,c.G=J,c.Util.inherits(K,c.Behaviour),K.prototype.reset=function(a,b,d,e,f){this.emitter=c.Util.initValue(a,null),this.mass=c.Util.initValue(b,!0),this.callback=c.Util.initValue(d,null),this.collisionPool=[],this.delta=new c.Vector2D,e&&K._super_.prototype.reset.call(this,e,f)},K.prototype.applyBehaviour=function(a,b,c){var d=this.emitter?this.emitter.particles.slice(c):this.pool.slice(c),e,f,g,h,i,j=d.length;for(var k=0;k-1&&this.initializes.splice(b,1)},R.prototype.removeInitializers=function(){c.Util.destroyArray(this.initializes)},R.prototype.addBehaviour=function(){var a=arguments.length,b;for(b=0;b-1&&this.behaviours.splice(b,1)},R.prototype.removeAllBehaviours=function(){c.Util.destroyArray(this.behaviours)},R.prototype.integrate=function(a){var b=1-this.damping;c.integrator.integrate(this,a,b);var d=this.particles.length,e;for(e=0;e=this.life||this.dead)&&this.destroy(),this.emitting(a),this.integrate(a);var b,d=this.particles.length,e;for(e=d-1;e>=0;e--)b=this.particles[e],b.dead&&(this.dispatchEvent(c.PARTICLE_DEAD,b),c.pool.set(b),this.particles.splice(e,1))},R.prototype.setupParticle=function(a,b,d){var e=this.initializes,f=this.behaviours;b&&(b instanceof Array?e=b:e=[b]),d&&(d instanceof Array?f=d:f=[d]),a.reset(),c.InitializeUtil.initialize(this,a,e),a.addBehaviours(f),a.parent=this,this.particles.push(a)},R.prototype.destroy=function(){this.dead=!0,this.emitTotalTimes=-1,this.particles.length==0&&(this.removeInitializers(),this.removeAllBehaviours(),this.parent&&this.parent.removeEmitter(this))},c.Emitter=R,c.Util.inherits(S,c.Emitter),S.prototype.addSelfBehaviour=function(){var a=arguments.length,b;for(b=0;b-1&&this.selfBehaviours.splice(b,1)},S.prototype.update=function(a){S._super_.prototype.update.call(this,a);if(!this.sleep){var b=this.selfBehaviours.length,c;for(c=0;cthis.element.width||c<0||c>this.elementwidth)){var f=((c>>0)*a.width+(b>>0))*4;a.data[f]=e.r,a.data[f+1]=e.g,a.data[f+2]=e.b,a.data[f+3]=d.alpha*255}},$.prototype.onParticleDead=function(a){},c.PixelRender=$,c.Util.inherits(_,c.BaseRender),_.prototype.resize=function(a,b){this.umat[4]=-2,this.umat[7]=1,this.smat[0]=1/a,this.smat[4]=1/b,this.mstack.set(this.umat,0),this.mstack.set(this.smat,1),this.gl.viewport(0,0,a,b),this.element.width=a,this.element.height=b},_.prototype.setMaxRadius=function(a){this.circleCanvasURL=this.createCircle(a)},_.prototype.getVertexShader=function(){var a=["uniform vec2 viewport;","attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","uniform mat3 tMat;","varying vec2 vTextureCoord;","varying float alpha;","void main() {","vec3 v = tMat * vec3(aVertexPosition, 1.0);","gl_Position = vec4(v.x, v.y, 0, 1);","vTextureCoord = aTextureCoord;","alpha = tMat[0][2];","}"].join("\n");return a},_.prototype.getFragmentShader=function(){var a=["precision mediump float;","varying vec2 vTextureCoord;","varying float alpha;","uniform sampler2D uSampler;","uniform vec4 color;","uniform bool useTexture;","uniform vec3 uColor;","void main() {","vec4 textureColor = texture2D(uSampler, vTextureCoord);","gl_FragColor = textureColor * vec4(uColor, 1.0);","gl_FragColor.w *= alpha;","}"].join("\n");return a},_.prototype.initVar=function(){this.mstack=new c.MStack,this.umat=c.Mat3.create([2,0,1,0,-2,0,-1,1,1]),this.smat=c.Mat3.create([.01,0,1,0,.01,0,0,0,1]),this.texturebuffers={}},_.prototype.start=function(){_._super_.prototype.start.call(this),this.resize(this.element.width,this.element.height)},_.prototype.blendEquation=function(a){this.gl.blendEquation(this.gl[a])},_.prototype.blendFunc=function(a,b){this.gl.blendFunc(this.gl[a],this.gl[b])},_.prototype.getShader=function(a,b,c){var d;c?d=a.createShader(a.FRAGMENT_SHADER):d=a.createShader(a.VERTEX_SHADER),a.shaderSource(d,b),a.compileShader(d);if(!a.getShaderParameter(d,a.COMPILE_STATUS)){alert(a.getShaderInfoLog(d));return null}return d},_.prototype.initShaders=function(){var a=this.getShader(this.gl,this.getFragmentShader(),!0),b=this.getShader(this.gl,this.getVertexShader(),!1);this.sprogram=this.gl.createProgram(),this.gl.attachShader(this.sprogram,b),this.gl.attachShader(this.sprogram,a),this.gl.linkProgram(this.sprogram),this.gl.getProgramParameter(this.sprogram,this.gl.LINK_STATUS)||alert("Could not initialise shaders"),this.gl.useProgram(this.sprogram),this.sprogram.vpa=this.gl.getAttribLocation(this.sprogram,"aVertexPosition"),this.sprogram.tca=this.gl.getAttribLocation(this.sprogram,"aTextureCoord"),this.gl.enableVertexAttribArray(this.sprogram.tca),this.gl.enableVertexAttribArray(this.sprogram.vpa),this.sprogram.tMatUniform=this.gl.getUniformLocation(this.sprogram,"tMat"),this.sprogram.samplerUniform=this.gl.getUniformLocation(this.sprogram,"uSampler"),this.sprogram.useTex=this.gl.getUniformLocation(this.sprogram,"useTexture"),this.sprogram.color=this.gl.getUniformLocation(this.sprogram,"uColor"),this.gl.uniform1i(this.sprogram.useTex,1)},_.prototype.initBuffers=function(){this.unitIBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.unitIBuffer);var a=[0,3,1,0,2,3];this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,new Uint16Array(a),this.gl.STATIC_DRAW);var b=[];for(var c=0;c<100;c++)b.push(c);idx=new Uint16Array(b),this.unitI33=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.unitI33),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,idx,this.gl.STATIC_DRAW),b=[];for(c=0;c<100;c++)b.push(c,c+1,c+2);idx=new Uint16Array(b),this.stripBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.stripBuffer),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,idx,this.gl.STATIC_DRAW)},_.prototype.createCircle=function(a){this.circleCanvasRadius=c.WebGLUtil.nhpot(c.Util.initValue(a,32));var b=c.DomUtil.createCanvas("circle_canvas",this.circleCanvasRadius*2,this.circleCanvasRadius*2),d=b.getContext("2d");d.beginPath(),d.arc(this.circleCanvasRadius,this.circleCanvasRadius,this.circleCanvasRadius,0,Math.PI*2,!0),d.closePath(),d.fillStyle="#FFF",d.fill();return b.toDataURL()},_.prototype.setImgInCanvas=function(a){var b=a.target.width,d=a.target.height,e=c.WebGLUtil.nhpot(a.target.width),f=c.WebGLUtil.nhpot(a.target.height),g=a.target.width/e,h=a.target.height/f;this.texturebuffers[a.transform.src]||(this.texturebuffers[a.transform.src]=[this.gl.createTexture(),this.gl.createBuffer(),this.gl.createBuffer()]),a.transform.texture=this.texturebuffers[a.transform.src][0],a.transform.vcBuffer=this.texturebuffers[a.transform.src][1],a.transform.tcBuffer=this.texturebuffers[a.transform.src][2],this.gl.bindBuffer(this.gl.ARRAY_BUFFER,a.transform.tcBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,0,g,0,0,h,h,h]),this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,a.transform.vcBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,0,b,0,0,d,b,d]),this.gl.STATIC_DRAW);var i=a.transform.canvas.getContext("2d"),j=i.getImageData(0,0,e,f);this.gl.bindTexture(this.gl.TEXTURE_2D,a.transform.texture),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,j),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR_MIPMAP_NEAREST),this.gl.generateMipmap(this.gl.TEXTURE_2D),a.transform.textureLoaded=!0,a.transform.textureWidth=b,a.transform.textureHeight=d},_.prototype.setStroke=function(a,b){},_.prototype.onProtonUpdate=function(){},_.prototype.onParticleCreated=function(a){var b=this;a.transform.textureLoaded=!1,a.transform.tmat=c.Mat3.create(),a.transform.tmat[8]=1,a.transform.imat=c.Mat3.create(),a.transform.imat[8]=1,a.target?c.Util.getImage(a.target,a,!0,function(a){b.setImgInCanvas.call(b,a),a.transform.oldScale=1}):c.Util.getImage(this.circleCanvasURL,a,!0,function(a){b.setImgInCanvas.call(b,a),a.transform.oldScale=a.radius/b.circleCanvasRadius})},_.prototype.onParticleUpdate=function(a){a.transform.textureLoaded&&(this.updateMatrix(a),this.gl.uniform3f(this.sprogram.color,a.transform.rgb.r/255,a.transform.rgb.g/255,a.transform.rgb.b/255),this.gl.uniformMatrix3fv(this.sprogram.tMatUniform,!1,this.mstack.top()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,a.transform.vcBuffer),this.gl.vertexAttribPointer(this.sprogram.vpa,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,a.transform.tcBuffer),this.gl.vertexAttribPointer(this.sprogram.tca,2,this.gl.FLOAT,!1,0,0),this.gl.bindTexture(this.gl.TEXTURE_2D,a.transform.texture),this.gl.uniform1i(this.sprogram.samplerUniform,0),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.unitIBuffer),this.gl.drawElements(this.gl.TRIANGLES,6,this.gl.UNSIGNED_SHORT,0),this.mstack.pop())},_.prototype.onParticleDead=function(a){},_.prototype.updateMatrix=function(a){var b=c.WebGLUtil.makeTranslation(-a.transform.textureWidth/2,-a.transform.textureHeight/2),d=c.WebGLUtil.makeTranslation(a.p.x,a.p.y),e=a.rotation*(Math.PI/180),f=c.WebGLUtil.makeRotation(e),g=a.scale*a.transform.oldScale,h=c.WebGLUtil.makeScale(g,g),i=c.WebGLUtil.matrixMultiply(b,h);i=c.WebGLUtil.matrixMultiply(i,f),i=c.WebGLUtil.matrixMultiply(i,d),c.Mat3.inverse(i,a.transform.imat),i[2]=a.alpha,this.mstack.push(i)},c.WebGLRender=_,ba.prototype={getPosition:function(){},crossing:function(a){}},c.Zone=ba,c.Util.inherits(bb,c.Zone),bb.prototype.getPosition=function(){this.random=Math.random(),this.vector.x=this.x1+this.random*this.length*Math.cos(this.gradient),this.vector.y=this.y1+this.random*this.length*Math.sin(this.gradient);return this.vector},bb.prototype.getDirection=function(a,b){var c=this.dy,d=-this.dx,e=this.dot,f=d==0?1:d;return(c*a+d*b+e)*f>0?!0:!1},bb.prototype.getDistance=function(a,b){var c=this.dy,d=-this.dx,e=this.dot,f=c*a+d*b+e;return f/Math.sqrt(this.xxyy)},bb.prototype.getSymmetric=function(a){var b=a.getGradient(),c=this.getGradient(),d=2*(c-b),e=a.x,f=a.y;a.x=e*Math.cos(d)-f*Math.sin(d),a.y=e*Math.sin(d)+f*Math.cos(d);return a},bb.prototype.getGradient=function(){return Math.atan2(this.dy,this.dx)},bb.prototype.getRange=function(a,b){var c=Math.abs(this.getGradient());c<=Math.PI/4?a.p.xthis.minx&&b():a.p.ythis.miny&&b()},bb.prototype.getLength=function(){return Math.sqrt(this.dx*this.dx+this.dy*this.dy)},bb.prototype.crossing=function(a){var b=this;this.crossType=="dead"?this.direction==">"||this.direction=="R"||this.direction=="right"||this.direction=="down"?this.getRange(a,function(){b.getDirection(a.p.x,a.p.y)&&(a.dead=!0)}):this.getRange(a,function(){b.getDirection(a.p.x,a.p.y)||(a.dead=!0)}):this.crossType=="bound"?this.getRange(a,function(){b.getDistance(a.p.x,a.p.y)<=a.radius&&(b.dx==0?a.v.x*=-1:b.dy==0?a.v.y*=-1:b.getSymmetric(a.v))}):this.crossType=="cross"&&this.alert&&(alert("Sorry lineZone does not support cross method"),this.alert=!1)},c.LineZone=bb,c.Util.inherits(bc,c.Zone),bc.prototype.getPosition=function(){this.random=Math.random(),this.angle=Math.PI*2*Math.random(),this.vector.x=this.x+this.random*this.radius*Math.cos(this.angle),this.vector.y=this.y+this.random*this.radius*Math.sin(this.angle);return this.vector},bc.prototype.setCenter=function(a,b){this.center.x=a,this.center.y=b},bc.prototype.crossing=function(a){var b=a.p.distanceTo(this.center);this.crossType=="dead"?b-a.radius>this.radius&&(a.dead=!0):this.crossType=="bound"?b+a.radius>=this.radius&&this.getSymmetric(a):this.crossType=="cross"&&this.alert&&(alert("Sorry CircleZone does not support cross method"),this.alert=!1)},bc.prototype.getSymmetric=function(a){var b=a.v.getGradient(),c=this.getGradient(a),d=2*(c-b),e=a.v.x,f=a.v.y;a.v.x=e*Math.cos(d)-f*Math.sin(d),a.v.y=e*Math.sin(d)+f*Math.cos(d)},bc.prototype.getGradient=function(a){return-Math.PI/2+Math.atan2(a.p.y-this.center.y,a.p.x-this.center.x)},c.CircleZone=bc,c.Util.inherits(bd,c.Zone),bd.prototype.getPosition=function(){this.vector.x=this.x,this.vector.y=this.y;return this.vector},bd.prototype.crossing=function(a){this.alert&&(alert("Sorry PointZone does not support crossing method"),this.alert=!1)},c.PointZone=bd,c.Util.inherits(be,c.Zone),be.prototype.getPosition=function(){this.vector.x=this.x+Math.random()*this.width,this.vector.y=this.y+Math.random()*this.height;return this.vector},be.prototype.crossing=function(a){this.crossType=="dead"?(a.p.x+a.radiusthis.x+this.width&&(a.dead=!0),a.p.y+a.radiusthis.y+this.height&&(a.dead=!0)):this.crossType=="bound"?(a.p.x-a.radiusthis.x+this.width&&(a.p.x=this.x+this.width-a.radius,a.v.x*=-1),a.p.y-a.radiusthis.y+this.height&&(a.p.y=this.y+this.height-a.radius,a.v.y*=-1)):this.crossType=="cross"&&(a.p.x+a.radiusthis.x+this.width&&a.v.x>=0&&(a.p.x=this.x-a.radius),a.p.y+a.radiusthis.y+this.height&&a.v.y>=0&&(a.p.y=this.y-a.radius))},c.RectZone=be,c.Util.inherits(bf,c.Zone),bf.prototype.reset=function(a,b,d,e){this.imageData=a,this.x=c.Util.initValue(b,0),this.y=c.Util.initValue(d,0),this.d=c.Util.initValue(e,2),this.vectors=[],this.setVectors()},bf.prototype.setVectors=function(){var a,b,c=this.imageData.width,d=this.imageData.height;for(a=0;a>0)*c+(a>>0))*4;this.imageData.data[e+3]>0&&this.vectors.push({x:a+this.x,y:b+this.y})}return this.vector},bf.prototype.getBound=function(a,b){var c=((b>>0)*this.imageData.width+(a>>0))*4;return this.imageData.data[c+3]>0?!0:!1},bf.prototype.getPosition=function(){return this.vector.copy(this.vectors[Math.floor(Math.random()*this.vectors.length)])},bf.prototype.getColor=function(a,b){a-=this.x,b-=this.y;var c=((b>>0)*this.imageData.width+(a>>0))*4;return{r:this.imageData.data[c],g:this.imageData.data[c+1],b:this.imageData.data[c+2],a:this.imageData.data[c+3]}},bf.prototype.crossing=function(a){this.crossType=="dead"?this.getBound(a.p.x-this.x,a.p.y-this.y)?a.dead=!0:a.dead=!1:this.crossType=="bound"&&(this.getBound(a.p.x-this.x,a.p.y-this.y)||a.v.negate())},c.ImageZone=bf;var bg=function(){if(a.console&&a.console.log){var b=arguments;if(typeof arguments[0]=="string")if(arguments[0].indexOf("+")==0){var c=parseInt(arguments[0]);bg.once .5) { this.oldTime = new Date().getTime(); @@ -115,6 +165,13 @@ } }, + /** + * Counts all particles from all emitters + * + * @method getCount + * @memberof Proton + * @instance + */ getCount: function() { var total = 0; var length = this.emitters.length; @@ -124,6 +181,13 @@ return total; }, + /** + * Destroys everything related to this Proton instance. This includes all emitters, and all properties + * + * @method destroy + * @memberof Proton + * @instance + */ destroy: function() { var length = this.emitters.length; for (var i = 0; i < length; i++) { @@ -138,7 +202,7 @@ } }; - window.Proton = Proton; + /* @@ -236,25 +300,78 @@ + + /** + * @namespace + * @memberof! Proton# + * @alias Proton.Util + */ var Util = Util || { + + /** + * Returns the default if the value is null or undefined + * + * @memberof Proton#Proton.Util + * @method initValue + * + * @param {Mixed} value a specific value, could be everything but null or undefined + * @param {Mixed} defaults the default if the value is null or undefined + */ initValue: function(value, defaults) { var value = (value != null && value != undefined) ? value : defaults; return value; }, + /** + * Checks if the value is a valid array + * + * @memberof Proton#Proton.Util + * @method isArray + * + * @param {Array} value Any array + * + * @returns {Boolean} + */ isArray: function(value) { return typeof value === 'object' && value.hasOwnProperty('length'); }, + /** + * Destroyes the given array + * + * @memberof Proton#Proton.Util + * @method destroyArray + * + * @param {Array} array Any array + */ destroyArray: function(array) { array.length = 0; }, + /** + * Destroyes the given object + * + * @memberof Proton#Proton.Util + * @method destroyObject + * + * @param {Object} obj Any object + */ destroyObject: function(obj) { for (var o in obj) delete obj[o]; }, + /** + * Returns the Vector2D - or creates a new one + * + * @memberof Proton#Proton.Util + * @method getVector2D + * + * @param {Proton.Vector2D | Number} postionOrX + * @param {Number} [y] just valid if 'postionOrX' is not an object + * + * @return {Proton.Vector2D} + */ getVector2D: function(postionOrX, y) { if (typeof(postionOrX) == 'object') { return postionOrX; @@ -264,6 +381,17 @@ } }, + /** + * Makes an instance of a class and binds the given array + * + * @memberof Proton#Proton.Util + * @method classApply + * + * @param {Function} constructor A class to make an instance from + * @param {Array} [argArray] Any array to bind it to the constructor + * + * @return {Object} The instance of constructor, optionally bind with argArray + */ classApply: function(constructor, argArray) { if (!argArray) return new constructor; @@ -272,6 +400,17 @@ return new factoryFunction(); }, + /** + * @memberof Proton#Proton.Util + * @method judgeVector2D + * + * @todo add description for param `pOBJ` + * @todo add description for function + * + * @param {Object} pOBJ + * + * @return {String} result + */ judgeVector2D: function(pOBJ) { var result = ''; if (pOBJ.hasOwnProperty('x') || pOBJ.hasOwnProperty('y') || pOBJ.hasOwnProperty('p') || pOBJ.hasOwnProperty('position')) @@ -284,6 +423,17 @@ return result; }, + /** + * @memberof Proton#Proton.Util + * @method setVector2DByObject + * + * @todo add description for param `target` + * @todo add description for param `pOBJ` + * @todo add description for function + * + * @param {Object} target + * @param {Object} pOBJ + */ setVector2DByObject: function(target, pOBJ) { if (pOBJ.hasOwnProperty('x')) target.p.x = pOBJ['x']; @@ -321,7 +471,23 @@ if (pOBJ.hasOwnProperty('accelerate')) particle.a.copy(pOBJ['accelerate']); }, - //强行添加属性 + + /** + * 强行添加属性 + * + * @memberof Proton#Proton.Util + * @method addPrototypeByObject + * + * @todo add description for param `target` + * @todo add description for param `filters` + * @todo translate desription from chinese to english + * + * @param {Object} target + * @param {Object} prototypeObject An object of single prototypes + * @param {Object} filters + * + * @return {Object} target + */ addPrototypeByObject: function(target, prototypeObject, filters) { for (var singlePrototype in prototypeObject) { if (filters) { @@ -334,7 +500,23 @@ return target; }, - //set prototype + + /** + * set the prototype in a given prototypeObject + * + * @memberof Proton#Proton.Util + * @method setPrototypeByObject + * + * @todo add description for param `target` + * @todo add description for param `filters` + * @todo translate desription from chinese to english + * + * @param {Object} target + * @param {Object} prototypeObject An object of single prototypes + * @param {Object} filters + * + * @return {Object} target + */ setPrototypeByObject: function(target, prototypeObject, filters) { for (var singlePrototype in prototypeObject) { if (target.hasOwnProperty(singlePrototype)) { @@ -350,6 +532,20 @@ return target; }, + /** + * Returns a new Proton.Span object + * + * @memberof Proton#Proton.Util + * @method setSpanValue + * + * @todo a, b and c should be 'Mixed' or 'Number'? + * + * @param {Mixed | Proton.Span} a + * @param {Mixed} b + * @param {Mixed} c + * + * @return {Proton.Span} + */ setSpanValue: function(a, b, c) { if (a instanceof Proton.Span) { return a; @@ -365,6 +561,16 @@ } }, + /** + * Returns the value from a Proton.Span, if the param is not a Proton.Span it will return the given parameter + * + * @memberof Proton#Proton.Util + * @method getSpanValue + * + * @param {Mixed | Proton.Span} pan + * + * @return {Mixed} the value of Proton.Span OR the parameter if it is not a Proton.Span + */ getSpanValue: function(pan) { if (pan instanceof Proton.Span) return pan.getValue(); @@ -372,6 +578,15 @@ return pan; }, + /** + * Inherits any class from the superclass. Acts like 'extends' in Java + * + * @memberof Proton#Proton.Util + * @method inherits + * + * @param {Object} subClass the child class + * @param {Object} superClass the parent/super class + */ inherits: function(subClass, superClass) { subClass._super_ = superClass; if (Object['create']) { @@ -389,6 +604,16 @@ } }, + /** + * This will get the image data. It could be necessary to create a Proton.Zone. + * + * @memberof Proton#Proton.Util + * @method getImageData + * + * @param {HTMLCanvasElement} context any canvas, must be a 2dContext 'canvas.getContext('2d')' + * @param {Object} image could be any dom image, e.g. document.getElementById('thisIsAnImgTag'); + * @param {Proton.Rectangle} rect + */ getImageData: function(context, image, rect) { context.drawImage(image, rect.x, rect.y); var imagedata = context.getImageData(rect.x, rect.y, rect.width, rect.height); @@ -396,6 +621,18 @@ return imagedata; }, + /** + * @memberof Proton#Proton.Util + * @method getImage + * + * @todo add description + * @todo describe fun + * + * @param {Mixed} img + * @param {Proton.Particle} particle + * @param {Boolean} drawCanvas set to true if a canvas should be saved into particle.transform.canvas + * @param {Boolean} fun + */ getImage: function(img, particle, drawCanvas, fun) { if (typeof(img) == 'string') { this.loadAndSetImage(img, particle, drawCanvas, fun); @@ -406,6 +643,20 @@ } }, + /** + * @memberof Proton#Proton.Util + * @method loadedImage + * + * @todo add description + * @todo describe fun + * @todo describe target + * + * @param {String} src the src of an img-tag + * @param {Proton.Particle} particle + * @param {Boolean} drawCanvas set to true if a canvas should be saved into particle.transform.canvas + * @param {Boolean} fun + * @param {Object} target + */ loadedImage: function(src, particle, drawCanvas, fun, target) { particle.target = target; particle.transform.src = src; @@ -427,6 +678,18 @@ fun(particle); }, + /** + * @memberof Proton#Proton.Util + * @method loadAndSetImage + * + * @todo add description + * @todo describe fun + * + * @param {String} src the src of an img-tag + * @param {Proton.Particle} particle + * @param {Boolean} drawCanvas set to true if a canvas should be saved into particle.transform.canvas + * @param {Boolean} fun + */ loadAndSetImage: function(src, particle, drawCanvas, fun) { if (Proton.TextureBuffer[src]) { this.loadedImage(src, particle, drawCanvas, fun, Proton.TextureBuffer[src]); @@ -440,6 +703,22 @@ } }, + /** + * @typedef {Object} rgbObject + * @property {Number} r red value + * @property {Number} g green value + * @property {Number} b blue value + */ + /** + * converts a hex value to a rgb object + * + * @memberof Proton#Proton.Util + * @method hexToRGB + * + * @param {String} h any hex value, e.g. #000000 or 000000 for black + * + * @return {rgbObject} + */ hexToRGB: function(h) { var hex16 = (h.charAt(0) == "#") ? h.substring(1, 7) : h; var r = parseInt(hex16.substring(0, 2), 16); @@ -453,6 +732,16 @@ } }, + /** + * converts a rgb value to a rgb string + * + * @memberof Proton#Proton.Util + * @method rgbToHex + * + * @param {Object | Proton.hexToRGB} rgb a rgb object like in {@link Proton#Proton.Util.hexToRGB} + * + * @return {String} rgb() + */ rgbToHex: function(rbg) { return 'rgb(' + rbg.r + ', ' + rbg.g + ', ' + rbg.b + ')'; } @@ -487,11 +776,40 @@ if (!Function.prototype.bind) { } + + /** + * @namespace + * @memberof! Proton# + * @alias Proton.WebGLUtil + */ var WebGLUtil = WebGLUtil || { + + /** + * @memberof Proton#Proton.WebGLUtil + * @method ipot + * + * @todo add description + * @todo add length description + * + * @param {Number} length + * + * @return {Boolean} + */ ipot : function(length) { return (length & (length - 1)) == 0; }, + /** + * @memberof Proton#Proton.WebGLUtil + * @method nhpot + * + * @todo add description + * @todo add length description + * + * @param {Number} length + * + * @return {Number} + */ nhpot : function(length) {--length; for (var i = 1; i < 32; i <<= 1) { length = length | length >> i; @@ -499,20 +817,70 @@ if (!Function.prototype.bind) { return length + 1; }, + /** + * @memberof Proton#Proton.WebGLUtil + * @method makeTranslation + * + * @todo add description + * @todo add tx, ty description + * @todo add return description + * + * @param {Number} tx either 0 or 1 + * @param {Number} ty either 0 or 1 + * + * @return {Object} + */ makeTranslation : function(tx, ty) { return [1, 0, 0, 0, 1, 0, tx, ty, 1]; }, + /** + * @memberof Proton#Proton.WebGLUtil + * @method makeRotation + * + * @todo add description + * @todo add return description + * + * @param {Number} angleInRadians + * + * @return {Object} + */ makeRotation : function(angleInRadians) { var c = Math.cos(angleInRadians); var s = Math.sin(angleInRadians); return [c, -s, 0, s, c, 0, 0, 0, 1]; }, + /** + * @memberof Proton#Proton.WebGLUtil + * @method makeScale + * + * @todo add description + * @todo add tx, ty description + * @todo add return description + * + * @param {Number} sx either 0 or 1 + * @param {Number} sy either 0 or 1 + * + * @return {Object} + */ makeScale : function(sx, sy) { return [sx, 0, 0, 0, sy, 0, 0, 0, 1]; }, + /** + * @memberof Proton#Proton.WebGLUtil + * @method matrixMultiply + * + * @todo add description + * @todo add a, b description + * @todo add return description + * + * @param {Object} a + * @param {Object} b + * + * @return {Object} + */ matrixMultiply : function(a, b) { var a00 = a[0 * 3 + 0]; var a01 = a[0 * 3 + 1]; @@ -540,7 +908,27 @@ if (!Function.prototype.bind) { + + /** + * @namespace + * @memberof! Proton# + * @alias Proton.DomUtil + */ var DomUtil = DomUtil || { + + /** + * Creates and returns a new canvas. The opacity is by default set to 0 + * + * @memberof Proton#Proton.DomUtil + * @method createCanvas + * + * @param {String} $id the canvas' id + * @param {Number} $width the canvas' width + * @param {Number} $height the canvas' height + * @param {String} [$position=absolute] the canvas' position, default is 'absolute' + * + * @return {Object} + */ createCanvas : function($id, $width, $height, $position) { var element = document.createElement("canvas"); var position = $position ? $position : 'absolute'; @@ -553,6 +941,18 @@ if (!Function.prototype.bind) { return element; }, + /** + * Adds a transform: translate(), scale(), rotate() to a given div element for all browsers + * + * @memberof Proton#Proton.DomUtil + * @method transformDom + * + * @param {HTMLDivElement} $div + * @param {Number} $x + * @param {Number} $y + * @param {Number} $scale + * @param {Number} $rotate + */ transformDom : function($div, $x, $y, $scale, $rotate) { $div.style.WebkitTransform = 'translate(' + $x + 'px, ' + $y + 'px) ' + 'scale(' + $scale + ') ' + 'rotate(' + $rotate + 'deg)'; $div.style.MozTransform = 'translate(' + $x + 'px, ' + $y + 'px) ' + 'scale(' + $scale + ') ' + 'rotate(' + $rotate + 'deg)'; @@ -617,7 +1017,7 @@ if (!Function.prototype.bind) { /** * The particle's id; * @property id - * @type {String} id + * @type {string} */ this.id = 'particle_' + Particle.ID++; this.reset(true); @@ -633,7 +1033,8 @@ if (!Function.prototype.bind) { reset : function(init) { this.life = Infinity; this.age = 0; - //能量损失 + + //Energy loss this.energy = 1; this.dead = false; this.sleep = false; @@ -647,6 +1048,7 @@ if (!Function.prototype.bind) { this.rotation = 0; this.color = null; this.easing = Proton.ease.setEasingByName(Proton.easeLinear); + if (init) { this.transform = {} this.p = new Proton.Vector2D(); @@ -666,6 +1068,7 @@ if (!Function.prototype.bind) { this.old.p.set(0, 0); this.old.v.set(0, 0); this.old.a.set(0, 0); + this.removeAllBehaviours(); } @@ -674,6 +1077,7 @@ if (!Function.prototype.bind) { g : 255, b : 255 } + return this; }, @@ -681,6 +1085,7 @@ if (!Function.prototype.bind) { if (!this.sleep) { this.age += time; var length = this.behaviours.length, i; + for ( i = 0; i < length; i++) { if (this.behaviours[i]) this.behaviours[i].applyBehaviour(this, time, index) @@ -702,11 +1107,13 @@ if (!Function.prototype.bind) { this.behaviours.push(behaviour); if (behaviour.hasOwnProperty('parents')) behaviour.parents.push(this); + behaviour.initialize(this); }, addBehaviours : function(behaviours) { var length = behaviours.length, i; + for ( i = 0; i < length; i++) { this.addBehaviour(behaviours[i]); } @@ -723,6 +1130,7 @@ if (!Function.prototype.bind) { removeAllBehaviours : function() { Proton.Util.destroyArray(this.behaviours); }, + /** * Destory this particle * @method destroy @@ -740,77 +1148,148 @@ if (!Function.prototype.bind) { - function Pool() { - this.cID = 0; - this.list = {}; - } - - Pool.prototype = { - create: function(obj, params) { - this.cID++; + /** + * @memberof! Proton# + * @constructor + * @alias Proton.Pool + * + * @todo add description + * @todo add description of properties + * + * @property {Number} cID + * @property {Object} list + */ + function Pool() { + this.cID = 0; + this.list = {}; + } + + Pool.prototype = { + + /** + * Creates a new class instance + * + * @todo add more documentation + * + * @method create + * @memberof Proton#Proton.Pool + * + * @param {Object|Function} obj any Object or Function + * @param {Object} [params] just add if `obj` is a function + * + * @return {Object} + */ + create: function(obj, params) { + this.cID++; - if (typeof obj == "function") - return Proton.Util.classApply(obj, params); - else - return obj.clone(); - }, + if (typeof obj == "function") + return Proton.Util.classApply(obj, params); + else + return obj.clone(); + }, - getCount: function() { - var count = 0; - for (var id in this.list) - count += this.list[id].length; + /** + * @todo add description - what is in the list? + * + * @method getCount + * @memberof Proton#Proton.Pool + * + * @return {Number} + */ + getCount: function() { + var count = 0; + for (var id in this.list) + count += this.list[id].length; - return count++;; - }, + return count++;; + }, - get: function(obj, params) { - var p, puid = obj.__puid || PUID.id(obj); - if (this.list[puid] && this.list[puid].length > 0) - p = this.list[puid].pop(); - else - p = this.create(obj, params); + /** + * @todo add description + * + * @method get + * @memberof Proton#Proton.Pool + * + * @param {Object|Function} obj + * @param {Object} [params] just add if `obj` is a function + * + * @return {Object} + */ + get: function(obj, params) { + var p, puid = obj.__puid || PUID.id(obj); + if (this.list[puid] && this.list[puid].length > 0) + p = this.list[puid].pop(); + else + p = this.create(obj, params); - p.__puid = obj.__puid || puid; - return p; - }, + p.__puid = obj.__puid || puid; + return p; + }, - set: function(obj) { - return this._getList(obj.__puid).push(obj); - }, + /** + * @todo add description + * + * @method set + * @memberof Proton#Proton.Pool + * + * @param {Object} obj + * + * @return {Object} + */ + set: function(obj) { + return this._getList(obj.__puid).push(obj); + }, - destroy: function() { - for (var id in this.list) { - this.list[id].length = 0; - delete this.list[id]; - } - }, + /** + * Destroyes all items from Pool.list + * + * @method destroy + * @memberof Proton#Proton.Pool + */ + destroy: function() { + for (var id in this.list) { + this.list[id].length = 0; + delete this.list[id]; + } + }, - _getList: function(uid) { - uid = uid || "default"; - if (!this.list[uid]) this.list[uid] = []; - return this.list[uid]; - } - } + /** + * Returns Pool.list + * + * @method _getList + * @memberof Proton#Proton.Pool + * @private + * + * @param {Number} uid the unique id + * + * @return {Object} + */ + _getList: function(uid) { + uid = uid || "default"; + if (!this.list[uid]) this.list[uid] = []; + return this.list[uid]; + } + } - Proton.Pool = Pool; + Proton.Pool = Pool; - var PUID = { - _id: 0, - _uids: {}, - id: function(obj) { - for (var id in this._uids) { - if (this._uids[id] == obj) return id; - } + var PUID = { + _id: 0, + _uids: {}, + id: function(obj) { + for (var id in this._uids) { + if (this._uids[id] == obj) return id; + } - var nid = "PUID_" + (this._id++); - this._uids[nid] = obj; - return nid; - }, + var nid = "PUID_" + (this._id++); + this._uids[nid] = obj; + return nid; + }, - hash: function(str) { - return; - } - } + hash: function(str) { + return; + } + } @@ -904,23 +1383,6 @@ if (!Function.prototype.bind) { }, - setComponent : function(index, value) { - - switch ( index ) { - - case 0: - this.x = value; - break; - case 1: - this.y = value; - break; - default: - throw new Error("index is out of range: " + index); - - } - - }, - getGradient : function() { if (this.x != 0) return Math.atan2(this.y, this.x); @@ -930,21 +1392,6 @@ if (!Function.prototype.bind) { return -Math.PI / 2; }, - getComponent : function(index) { - - switch ( index ) { - - case 0: - return this.x; - case 1: - return this.y; - default: - throw new Error("index is out of range: " + index); - - } - - }, - copy : function(v) { this.x = v.x; @@ -1080,34 +1527,6 @@ if (!Function.prototype.bind) { }, - clamp : function(min, max) { - - // This function assumes min < max, if this assumption isn't true it will not operate correctly - - if (this.x < min.x) { - - this.x = min.x; - - } else if (this.x > max.x) { - - this.x = max.x; - - } - - if (this.y < min.y) { - - this.y = min.y; - - } else if (this.y > max.y) { - - this.y = max.y; - - } - - return this; - - }, - negate : function() { return this.multiplyScalar(-1); @@ -1422,46 +1841,34 @@ if (!Function.prototype.bind) { Behaviour.id = 0; + /** * The Behaviour class is the base for the other Behaviour * - * @class Behaviour - * @constructor + * @memberof! - + * @interface + * @alias Proton.Behaviour + * + * @param {Number} life the behaviours life + * @param {String} easing The behaviour's decaying trend, for example Proton.easeOutQuart + * + * @property {String} id The behaviours id + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + * @property {Number} age=0 How long the particle should be 'alife' + * @property {Number} energy=1 + * @property {Boolean} dead=false The particle is dead at first + * @property {Array} parents The behaviour's parents array + * @property {String} name The behaviour name */ function Behaviour(life, easing) { - /** - * The behaviour's id; - * @property id - * @type {String} id - */ this.id = 'Behaviour_' + Behaviour.id++; this.life = Proton.Util.initValue(life, Infinity); - /** - * The behaviour's decaying trend, for example Proton.easeOutQuart; - * @property easing - * @type {String} - * @default Proton.easeLinear - */ this.easing = Proton.ease.setEasingByName(easing); this.age = 0; this.energy = 1; - /** - * The behaviour is Dead; - * @property dead - * @type {Boolean} - */ this.dead = false; - /** - * The behaviour's parents array; - * @property parents - * @type {Array} - */ this.parents = []; - /** - * The behaviour name; - * @property name - * @type {string} - */ this.name = 'Behaviour'; } @@ -1471,8 +1878,11 @@ if (!Function.prototype.bind) { * Reset this behaviour's parameters * * @method reset - * @param {Number} this behaviour's life - * @param {String} this behaviour's easing + * @memberof Proton.Behaviour + * @instance + * + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=easeLinear] this behaviour's easing */ reset : function(life, easing) { this.life = Proton.Util.initValue(life, Infinity); @@ -1482,6 +1892,9 @@ if (!Function.prototype.bind) { * Normalize a force by 1:100; * * @method normalizeForce + * @memberof Proton.Behaviour + * @instance + * * @param {Proton.Vector2D} force */ normalizeForce : function(force) { @@ -1492,6 +1905,9 @@ if (!Function.prototype.bind) { * Normalize a value by 1:100; * * @method normalizeValue + * @memberof Proton.Behaviour + * @instance + * * @param {Number} value */ normalizeValue : function(value) { @@ -1502,6 +1918,9 @@ if (!Function.prototype.bind) { * Initialize the behaviour's parameters for all particles * * @method initialize + * @memberof Proton.Behaviour + * @instance + * * @param {Proton.Particle} particle */ initialize : function(particle) { @@ -1511,9 +1930,12 @@ if (!Function.prototype.bind) { * Apply this behaviour for all particles every time * * @method applyBehaviour + * @memberof Proton.Behaviour + * @instance + * * @param {Proton.Particle} particle - * @param {Number} the integrate time 1/ms - * @param {Int} the particle index + * @param {Number} time the integrate time 1/ms + * @param {Int} index the particle index */ applyBehaviour : function(particle, time, index) { this.age += time; @@ -1529,7 +1951,10 @@ if (!Function.prototype.bind) { /** * Destory this behaviour + * * @method destroy + * @memberof Proton.Behaviour + * @instance */ destroy : function() { var index; @@ -1548,10 +1973,13 @@ if (!Function.prototype.bind) { /** * The number of particles per second emission (a [particle]/b [s]); - * @class Proton.Rate + * @namespace + * @memberof! Proton# * @constructor - * @param {Array or Number or Proton.Span} numpan the number of each emission; - * @param {Array or Number or Proton.Span} timepan the time of each emission; + * @alias Proton.Rate + * + * @param {Array | Number | Proton.Span} numpan the number of each emission; + * @param {Array | Number | Proton.Span} timepan the time of each emission; * for example: new Proton.Rate(new Proton.Span(10, 20), new Proton.Span(.1, .25)); */ function Rate(numpan, timepan) { @@ -1566,6 +1994,11 @@ if (!Function.prototype.bind) { Rate.prototype = { + /** + * @method init + * @memberof Proton#Proton.Rate + * @instance + */ init : function() { this.startTime = 0; this.nextTime = this.timePan.getValue(); @@ -1799,6 +2232,20 @@ if (!Function.prototype.bind) { + + /** + * @memberof! Proton# + * @augments Proton.Behaviour + * @constructor + * @alias Proton.Force + * + * @param {Number} fx + * @param {Number} fy + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + * + * @property {String} name The Behaviour name + */ function Force(fx, fy, life, easing) { Force._super_.call(this, life, easing); this.force = this.normalizeForce(new Proton.Vector2D(fx, fy)); @@ -1807,12 +2254,36 @@ if (!Function.prototype.bind) { Proton.Util.inherits(Force, Proton.Behaviour); + + /** + * Reset this behaviour's parameters + * + * @method reset + * @memberof Proton#Proton.Force + * @instance + * + * @param {Number} fx + * @param {Number} fy + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + */ Force.prototype.reset = function(fx, fy, life, easing) { this.force = this.normalizeForce(new Proton.Vector2D(fx, fy)); if (life) Force._super_.prototype.reset.call(this, life, easing); } + /** + * Apply this behaviour for all particles every time + * + * @method applyBehaviour + * @memberof Proton#Proton.Force + * @instance + * + * @param {Proton.Particle} particle + * @param {Number} the integrate time 1/ms + * @param {Int} the particle index + */ Force.prototype.applyBehaviour = function(particle, time, index) { Force._super_.prototype.applyBehaviour.call(this, particle, time, index); particle.a.add(this.force); @@ -1823,8 +2294,33 @@ if (!Function.prototype.bind) { + /** + * This behaviour let the particles follow one specific Proton.Vector2D + * + * @memberof! Proton# + * @augments Proton.Behaviour + * @constructor + * @alias Proton.Attraction + * + * @todo add description for 'force' and 'radius' + * + * @param {Proton.Vector2D} targetPosition the attraction point coordinates + * @param {Number} [force=100] + * @param {Number} [radius=1000] + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + * + * @property {Proton.Vector2D} targetPosition + * @property {Number} radius + * @property {Number} force + * @property {Number} radiusSq + * @property {Proton.Vector2D} attractionForce + * @property {Number} lengthSq + * @property {String} name The Behaviour name + */ function Attraction(targetPosition, force, radius, life, easing) { Attraction._super_.call(this, life, easing); + this.targetPosition = Proton.Util.initValue(targetPosition, new Proton.Vector2D); this.radius = Proton.Util.initValue(radius, 1000); this.force = Proton.Util.initValue(this.normalizeValue(force), 100); @@ -1836,6 +2332,22 @@ if (!Function.prototype.bind) { Proton.Util.inherits(Attraction, Proton.Behaviour); + + /** + * Reset this behaviour's parameters + * + * @method reset + * @memberof Proton#Proton.Attraction + * @instance + * + * @todo add description for 'force' and 'radius' + * + * @param {Proton.Vector2D} targetPosition the attraction point coordinates + * @param {Number} [force=100] + * @param {Number} [radius=1000] + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + */ Attraction.prototype.reset = function(targetPosition, force, radius, life, easing) { this.targetPosition = Proton.Util.initValue(targetPosition, new Proton.Vector2D); this.radius = Proton.Util.initValue(radius, 1000); @@ -1847,6 +2359,17 @@ if (!Function.prototype.bind) { Attraction._super_.prototype.reset.call(this, life, easing); } + /** + * Apply this behaviour for all particles every time + * + * @memberof Proton#Proton.Attraction + * @method applyBehaviour + * @instance + * + * @param {Proton.Particle} particle + * @param {Number} time the integrate time 1/ms + * @param {Int} index the particle index + */ Attraction.prototype.applyBehaviour = function(particle, time, index) { Attraction._super_.prototype.applyBehaviour.call(this, particle, time, index); this.attractionForce.copy(this.targetPosition); @@ -1865,6 +2388,22 @@ if (!Function.prototype.bind) { + + /** + * @memberof! Proton# + * @augments Proton.Behaviour + * @constructor + * @alias Proton.RandomDrift + * + * @param {Number} driftX X value of the new Proton.Vector2D + * @param {Number} driftY Y value of the new Proton.Vector2D + * @param {Number} delay How much delay the drift should have + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=easeLinear] this behaviour's easing + * + * @property {Number} time The time of the drift + * @property {String} name The Behaviour name + */ function RandomDrift(driftX, driftY, delay, life, easing) { RandomDrift._super_.call(this, life, easing); this.reset(driftX, driftY, delay); @@ -1872,8 +2411,21 @@ if (!Function.prototype.bind) { this.name = "RandomDrift"; } - Proton.Util.inherits(RandomDrift, Proton.Behaviour); + + /** + * Reset this behaviour's parameters + * + * @method reset + * @memberof Proton#Proton.RandomDrift + * @instance + * + * @param {Number} driftX X value of the new Proton.Vector2D + * @param {Number} driftY Y value of the new Proton.Vector2D + * @param {Number} delay How much delay the drift should have + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=easeLinear] this behaviour's easing + */ RandomDrift.prototype.reset = function(driftX, driftY, delay, life, easing) { this.panFoce = new Proton.Vector2D(driftX, driftY); this.panFoce = this.normalizeForce(this.panFoce); @@ -1882,6 +2434,17 @@ if (!Function.prototype.bind) { RandomDrift._super_.prototype.reset.call(this, life, easing); } + /** + * Apply this behaviour for all particles every time + * + * @method applyBehaviour + * @memberof Proton#Proton.RandomDrift + * @instance + * + * @param {Proton.Particle} particle + * @param {Number} time the integrate time 1/ms + * @param {Int} index the particle index + */ RandomDrift.prototype.applyBehaviour = function(particle, time, index) { RandomDrift._super_.prototype.applyBehaviour.call(this, particle, time, index); this.time += time; @@ -1896,39 +2459,125 @@ if (!Function.prototype.bind) { + + /** + * The oppisite of Proton.Attraction - turns the force + * + * @memberof! Proton# + * @augments Proton#Proton.Attraction + * @constructor + * @alias Proton.Repulsion + * + * @todo add description for 'force' and 'radius' + * + * @param {Proton.Vector2D} targetPosition the attraction point coordinates + * @param {Number} [force=100] + * @param {Number} [radius=1000] + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + * + * @property {Number} force + * @property {String} name The Behaviour name + */ function Repulsion(targetPosition, force, radius, life, easing) { Repulsion._super_.call(this, targetPosition, force, radius, life, easing); this.force *= -1; this.name = "Repulsion"; } - Proton.Util.inherits(Repulsion, Proton.Attraction); + + /** + * Reset this behaviour's parameters + * + * @method reset + * @memberof Proton#Proton.Repulsion + * @instance + * + * @todo add description for 'force' and 'radius' + * + * @param {Proton.Vector2D} targetPosition the attraction point coordinates + * @param {Number} [force=100] + * @param {Number} [radius=1000] + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + */ Repulsion.prototype.reset = function(targetPosition, force, radius, life, easing) { Repulsion._super_.prototype.reset.call(this, targetPosition, force, radius, life, easing); this.force *= -1; } + Proton.Repulsion = Repulsion; + + /** + * @memberof! Proton# + * @augments Proton#Proton.Force + * @constructor + * @alias Proton.Gravity + * + * @param {Number} g Gravity + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + * + * @property {String} name The Behaviour name + */ function Gravity(g, life, easing) { Gravity._super_.call(this, 0, g, life, easing); this.name = "Gravity"; } - Proton.Util.inherits(Gravity, Proton.Force); + + /** + * Reset this behaviour's parameters + * + * @method reset + * @memberof Proton#Proton.Gravity + * @instance + * + * @param {Number} g Gravity + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + */ Gravity.prototype.reset = function(g, life, easing) { Gravity._super_.prototype.reset.call(this, 0, g, life, easing); } + Proton.Gravity = Gravity; Proton.G = Gravity; //can use Collision(emitter,true,function(){}) or Collision(); + + /** + * The callback after collision + * + * @callback Callback + * + * @param {Proton.Particle} particle + * @param {Proton.Paritcle} otherParticle + */ + /** + * @memberof! Proton# + * @augments Proton.Behaviour + * @constructor + * @alias Proton.Collision + * + * @todo add description to mass + * + * @param {Proton.Emitter} [emitter=null] the attraction point coordinates + * @param {Boolean} [mass=true] + * @param {Callback} [callback=null] the callback after the collision + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + * + * @property {String} name The Behaviour name + */ function Collision(emitter, mass, callback, life, easing) { Collision._super_.call(this, life, easing); this.reset(emitter, mass, callback); @@ -1937,6 +2586,22 @@ if (!Function.prototype.bind) { Proton.Util.inherits(Collision, Proton.Behaviour); + + /** + * Reset this behaviour's parameters + * + * @memberof Proton#Proton.Collision + * @method reset + * @instance + * + * @todo add description to mass + * + * @param {Proton.Emitter} [emitter=null] the attraction point coordinates + * @param {Boolean} [mass=true] + * @param {Callback} [callback=null] the callback after the collision + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + */ Collision.prototype.reset = function(emitter, mass, callback, life, easing) { this.emitter = Proton.Util.initValue(emitter, null); this.mass = Proton.Util.initValue(mass, true); @@ -1947,6 +2612,17 @@ if (!Function.prototype.bind) { Collision._super_.prototype.reset.call(this, life, easing); } + /** + * Apply this behaviour for all particles every time + * + * @memberof Proton#Proton.Collision + * @method applyBehaviour + * @instance + * + * @param {Proton.Particle} particle + * @param {Number} time the integrate time 1/ms + * @param {Int} index the particle index + */ Collision.prototype.applyBehaviour = function(particle, time, index) { var newPool = this.emitter ? this.emitter.particles.slice(index) : this.pool.slice(index); var otherParticle; @@ -1982,15 +2658,42 @@ if (!Function.prototype.bind) { + + /** + * Defines what happens if the particles come to the end of the specified zone + * + * @memberof! Proton# + * @augments Proton.Behaviour + * @constructor + * @alias Proton.CrossZone + * + * @param {Proton.Zone} zone can be any Proton.Zone - e.g. Proton.RectZone() + * @param {String} [crossType=dead] what happens if the particles pass the zone - allowed strings: dead | bound | cross + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + * + * @property {String} name The Behaviour name + */ function CrossZone(zone, crossType, life, easing) { CrossZone._super_.call(this, life, easing); this.reset(zone, crossType); - ///dead /bound /cross this.name = "CrossZone"; } - Proton.Util.inherits(CrossZone, Proton.Behaviour); + + /** + * Reset this behaviour's parameters + * + * @method reset + * @memberof Proton#Proton.CrossZone + * @instance + * + * @param {Proton.Zone} zone can be any Proton.Zone - e.g. Proton.RectZone() + * @param {String} [crossType=dead] what happens if the particles pass the zone - allowed strings: dead | bound | cross + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=easeLinear] this behaviour's easing + */ CrossZone.prototype.reset = function(zone, crossType, life, easing) { this.zone = zone; this.zone.crossType = Proton.Util.initValue(crossType, "dead"); @@ -1998,6 +2701,17 @@ if (!Function.prototype.bind) { CrossZone._super_.prototype.reset.call(this, life, easing); } + /** + * Apply this behaviour for all particles every time + * + * @method applyBehaviour + * @memberof Proton#Proton.CrossZone + * @instance + * + * @param {Proton.Particle} particle + * @param {Number} the integrate time 1/ms + * @param {Int} the particle index + */ CrossZone.prototype.applyBehaviour = function(particle, time, index) { CrossZone._super_.prototype.applyBehaviour.call(this, particle, time, index); this.zone.crossing(particle); @@ -2007,19 +2721,45 @@ if (!Function.prototype.bind) { + + /** + * @memberof! Proton# + * @augments Proton.Behaviour + * @constructor + * @alias Proton.Alpha + * + * @todo add description for 'a' and 'b' + * + * @param {Number} a + * @param {String} b + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + * + * @property {String} name The Behaviour name + */ function Alpha(a, b, life, easing) { Alpha._super_.call(this, life, easing); this.reset(a, b); - /** - * The Behaviour name; - * @property name - * @type {string} - */ this.name = "Alpha"; } Proton.Util.inherits(Alpha, Proton.Behaviour); + + /** + * Reset this behaviour's parameters + * + * @method reset + * @memberof Proton#Proton.Alpha + * @instance + * + * @todo add description for 'a' and 'b' + * + * @param {Number} a + * @param {String} b + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + */ Alpha.prototype.reset = function(a, b, life, easing) { if (b == null || b == undefined) this.same = true; @@ -2031,6 +2771,15 @@ if (!Function.prototype.bind) { Alpha._super_.prototype.reset.call(this, life, easing); } + /** + * Sets the new alpha value of the particle + * + * @method initialize + * @memberof Proton#Proton.Alpha + * @instance + * + * @param {Proton.Particle} particle A single Proton generated particle + */ Alpha.prototype.initialize = function(particle) { particle.transform.alphaA = this.a.getValue(); if (this.same) @@ -2039,6 +2788,15 @@ if (!Function.prototype.bind) { particle.transform.alphaB = this.b.getValue(); }; + /** + * @method applyBehaviour + * @memberof Proton#Proton.Alpha + * @instance + * + * @param {Proton.Particle} particle + * @param {Number} time the integrate time 1/ms + * @param {Int} index the particle index + */ Alpha.prototype.applyBehaviour = function(particle, time, index) { Alpha._super_.prototype.applyBehaviour.call(this, particle, time, index); particle.alpha = particle.transform.alphaB + (particle.transform.alphaA - particle.transform.alphaB) * this.energy; @@ -2050,6 +2808,22 @@ if (!Function.prototype.bind) { + + /** + * @memberof! Proton# + * @augments Proton.Behaviour + * @constructor + * @alias Proton.Scale + * + * @todo add description for 'a' and 'b' + * + * @param {Number} a + * @param {String} b + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + * + * @property {String} name The Behaviour name + */ function Scale(a, b, life, easing) { Scale._super_.call(this, life, easing); this.reset(a, b); @@ -2058,6 +2832,19 @@ if (!Function.prototype.bind) { Proton.Util.inherits(Scale, Proton.Behaviour); + + /** + * Reset this behaviour's parameters + * + * @method reset + * @memberof Proton#Proton.Scale + * @instance + * + * @param {Number} a + * @param {String} b + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + */ Scale.prototype.reset = function(a, b, life, easing) { if (b == null || b == undefined) this.same = true; @@ -2069,6 +2856,15 @@ if (!Function.prototype.bind) { Scale._super_.prototype.reset.call(this, life, easing); } + /** + * Initialize the behaviour's parameters for all particles + * + * @method initialize + * @memberof Proton#Proton.Scale + * @instance + * + * @param {Proton.Particle} particle + */ Scale.prototype.initialize = function(particle) { particle.transform.scaleA = this.a.getValue(); particle.transform.oldRadius = particle.radius; @@ -2079,6 +2875,17 @@ if (!Function.prototype.bind) { }; + /** + * Apply this behaviour for all particles every time + * + * @method applyBehaviour + * @memberof Proton#Proton.Scale + * @instance + * + * @param {Proton.Particle} particle + * @param {Number} time the integrate time 1/ms + * @param {Int} index the particle index + */ Scale.prototype.applyBehaviour = function(particle, time, index) { Scale._super_.prototype.applyBehaviour.call(this, particle, time, index); particle.scale = particle.transform.scaleB + (particle.transform.scaleA - particle.transform.scaleB) * this.energy; @@ -2091,14 +2898,46 @@ if (!Function.prototype.bind) { + + /** + * @memberof! Proton# + * @augments Proton.Behaviour + * @constructor + * @alias Proton.Rotate + * + * @todo add description for 'a', 'b' and 'style' + * + * @param {Number} a + * @param {String} b + * @param {String} [style=to] + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + * + * @property {String} name The Behaviour name + */ function Rotate(a, b, style, life, easing) { Rotate._super_.call(this, life, easing); this.reset(a, b, style); this.name = "Rotate"; } - Proton.Util.inherits(Rotate, Proton.Behaviour); + + /** + * Reset this behaviour's parameters + * + * @method reset + * @memberof Proton#Proton.Rotate + * @instance + * + * @todo add description for 'a', 'b' and 'style' + * + * @param {Number} a + * @param {String} b + * @param {String} [style=to] + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + */ Rotate.prototype.reset = function(a, b, style, life, easing) { if (b == null || b == undefined) this.same = true; @@ -2111,6 +2950,15 @@ if (!Function.prototype.bind) { Rotate._super_.prototype.reset.call(this, life, easing); } + /** + * Initialize the behaviour's parameters for all particles + * + * @method initialize + * @memberof Proton#Proton.Rotate + * @instance + * + * @param {Proton.Particle} particle + */ Rotate.prototype.initialize = function(particle) { particle.rotation = this.a.getValue(); particle.transform.rotationA = this.a.getValue(); @@ -2118,6 +2966,17 @@ if (!Function.prototype.bind) { particle.transform.rotationB = this.b.getValue(); }; + /** + * Apply this behaviour for all particles every time + * + * @method applyBehaviour + * @memberof Proton#Proton.Rotate + * @instance + * + * @param {Proton.Particle} particle + * @param {Number} time the integrate time 1/ms + * @param {Int} index the particle index + */ Rotate.prototype.applyBehaviour = function(particle, time, index) { Rotate._super_.prototype.applyBehaviour.call(this, particle, time, index); if (!this.same) { @@ -2136,6 +2995,20 @@ if (!Function.prototype.bind) { + + /** + * @memberof! Proton# + * @augments Proton.Behaviour + * @constructor + * @alias Proton.Color + * + * @param {Proton.ColorSpan | String} color1 the string should be a hex e.g. #000000 for black + * @param {Proton.ColorSpan | String} color2 the string should be a hex e.g. #000000 for black + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=easeLinear] this behaviour's easing + * + * @property {String} name The Behaviour name + */ function Color(color1, color2, life, easing) { Color._super_.call(this, life, easing); this.reset(color1, color2); @@ -2144,6 +3017,19 @@ if (!Function.prototype.bind) { Proton.Util.inherits(Color, Proton.Behaviour); + + /** + * Reset this behaviour's parameters + * + * @method reset + * @memberof Proton#Proton.Color + * @instance + * + * @param {Proton.ColorSpan | String} color1 the string should be a hex e.g. #000000 for black + * @param {Proton.ColorSpan | String} color2 the string should be a hex e.g. #000000 for black + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=easeLinear] this behaviour's easing + */ Color.prototype.reset = function(color1, color2, life, easing) { this.color1 = this.setSpanValue(color1); this.color2 = this.setSpanValue(color2); @@ -2151,6 +3037,15 @@ if (!Function.prototype.bind) { Color._super_.prototype.reset.call(this, life, easing); } + /** + * Initialize the behaviour's parameters for all particles + * + * @method initialize + * @memberof Proton#Proton.Color + * @instance + * + * @param {Proton.Particle} particle + */ Color.prototype.initialize = function(particle) { particle.color = this.color1.getValue(); particle.transform.beginRGB = Proton.Util.hexToRGB(particle.color); @@ -2159,6 +3054,17 @@ if (!Function.prototype.bind) { particle.transform.endRGB = Proton.Util.hexToRGB(this.color2.getValue()); }; + /** + * Apply this behaviour for all particles every time + * + * @method applyBehaviour + * @memberof Proton#Proton.Color + * @instance + * + * @param {Proton.Particle} particle + * @param {Number} the integrate time 1/ms + * @param {Int} the particle index + */ Color.prototype.applyBehaviour = function(particle, time, index) { if (this.color2) { Color._super_.prototype.applyBehaviour.call(this, particle, time, index); @@ -2176,6 +3082,17 @@ if (!Function.prototype.bind) { } }; + /** + * Make sure that the color is an instance of Proton.ColorSpan, if not it makes a new instance + * + * @method setSpanValue + * @memberof Proton#Proton.Color + * @instance + * + * @param {Proton.Particle} particle + * @param {Number} the integrate time 1/ms + * @param {Int} the particle index + */ Color.prototype.setSpanValue = function(color) { if (color) { if ( color instanceof Proton.ColorSpan) { @@ -2192,6 +3109,20 @@ if (!Function.prototype.bind) { + + /** + * @memberof! Proton# + * @augments Proton.Behaviour + * @constructor + * @alias Proton.GravityWell + * + * @param {Proton.Vector2D} [centerPoint=new Proton.Vector2D] The point in the center + * @param {Number} [force=100] The force + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + * + * @property {String} name The Behaviour name + */ function GravityWell(centerPoint, force, life, easing) { GravityWell._super_.call(this, life, easing); this.distanceVec = new Proton.Vector2D(); @@ -2200,8 +3131,20 @@ if (!Function.prototype.bind) { this.name = "GravityWell"; } - Proton.Util.inherits(GravityWell, Proton.Behaviour); + + /** + * Reset this behaviour's parameters + * + * @method reset + * @memberof Proton#Proton.GravityWell + * @instance + * + * @param {Proton.Vector2D} [centerPoint=new Proton.Vector2D] The point in the center + * @param {Number} [force=100] The force + * @param {Number} [life=Infinity] this behaviour's life + * @param {String} [easing=Proton.easeLinear] this behaviour's easing + */ GravityWell.prototype.reset = function(centerPoint, force, life, easing) { this.distanceVec = new Proton.Vector2D(); this.centerPoint = Proton.Util.initValue(centerPoint, new Proton.Vector2D); @@ -2209,10 +3152,25 @@ if (!Function.prototype.bind) { if (life) GravityWell._super_.prototype.reset.call(this, life, easing); }; + + /** + * @inheritdoc + */ GravityWell.prototype.initialize = function(particle) { }; + /** + * Apply this behaviour for all particles every time + * + * @method applyBehaviour + * @memberof Proton#Proton.GravityWell + * @instance + * + * @param {Proton.Particle} particle + * @param {Number} the integrate time 1/ms + * @param {Int} the particle index + */ GravityWell.prototype.applyBehaviour = function(particle, time, index) { this.distanceVec.set(this.centerPoint.x - particle.p.x, this.centerPoint.y - particle.p.y); var distanceSq = this.distanceVec.lengthSq(); @@ -2273,7 +3231,7 @@ if (!Function.prototype.bind) { /** * The emitter's id; * @property id - * @type {String} id + * @type {string} */ this.id = 'emitter_' + Emitter.ID++; }; @@ -2743,133 +3701,19 @@ if (!Function.prototype.bind) { return 0.5 * ((value -= 2) * value * (((s *= (1.525)) + 1) * value + s) + 2); }, - setEasingByName : function(name) { - switch (name) { - case 'easeLinear': - return Proton.ease.easeLinear; - break; - - case 'easeInQuad': - return Proton.ease.easeInQuad; - break; - - case 'easeOutQuad': - return Proton.ease.easeOutQuad; - break; - - case 'easeInOutQuad': - return Proton.ease.easeInOutQuad; - break; - - case 'easeInCubic': - return Proton.ease.easeInCubic; - break; - - case 'easeOutCubic': - return Proton.ease.easeOutCubic; - break; - - case 'easeInOutCubic': - return Proton.ease.easeInOutCubic; - break; - - case 'easeInQuart': - return Proton.ease.easeInQuart; - break; - - case 'easeOutQuart': - return Proton.ease.easeOutQuart; - break; - - case 'easeInOutQuart': - return Proton.ease.easeInOutQuart; - break; - - case 'easeInSine': - return Proton.ease.easeInSine; - break; - - case 'easeOutSine': - return Proton.ease.easeOutSine; - break; - - case 'easeInOutSine': - return Proton.ease.easeInOutSine; - break; - - case 'easeInExpo': - return Proton.ease.easeInExpo; - break; - - case 'easeOutExpo': - return Proton.ease.easeOutExpo; - break; - - case 'easeInOutExpo': - return Proton.ease.easeInOutExpo; - break; - - case 'easeInCirc': - return Proton.ease.easeInCirc; - break; - - case 'easeOutCirc': - return Proton.ease.easeOutCirc; - break; - - case 'easeInOutCirc': - return Proton.ease.easeInOutCirc; - break; - - case 'easeInBack': - return Proton.ease.easeInBack; - break; - - case 'easeOutBack': - return Proton.ease.easeOutBack; - break; - - case 'easeInOutBack': - return Proton.ease.easeInOutBack; - break; - - default: - return Proton.ease.easeLinear; - break; - } - } + setEasingByName: function(easeName) { + if (!!ease[easeName]) + return ease[easeName]; + else + return ease.easeLinear; + } } - Proton.ease = ease; - Proton.easeLinear = 'easeLinear'; - - Proton.easeInQuad = 'easeInQuad'; - Proton.easeOutQuad = 'easeOutQuad'; - Proton.easeInOutQuad = 'easeInOutQuad'; - - Proton.easeInCubic = 'easeInCubic'; - Proton.easeOutCubic = 'easeOutCubic'; - Proton.easeInOutCubic = 'easeInOutCubic'; - - Proton.easeInQuart = 'easeInQuart'; - Proton.easeOutQuart = 'easeOutQuart'; - Proton.easeInOutQuart = 'easeInOutQuart'; - - Proton.easeInSine = 'easeInSine'; - Proton.easeOutSine = 'easeOutSine'; - Proton.easeInOutSine = 'easeInOutSine'; - - Proton.easeInExpo = 'easeInExpo'; - Proton.easeOutExpo = 'easeOutExpo'; - Proton.easeInOutExpo = 'easeInOutExpo'; - - Proton.easeInCirc = 'easeInCirc'; - Proton.easeOutCirc = 'easeOutCirc'; - Proton.easeInOutCirc = 'easeInOutCirc'; + for (var key in ease) { + if (key != "setEasingByName") Proton[key] = ease[key]; + } - Proton.easeInBack = 'easeInBack'; - Proton.easeOutBack = 'easeOutBack'; - Proton.easeInOutBack = 'easeInOutBack'; + Proton.ease = ease; @@ -4015,42 +4859,6 @@ if (!Function.prototype.bind) { Proton.ImageZone = ImageZone; -/** - * You can use this emit particles. - * - * This method will console.log the fixed number of your info in updata or requestAnimationFrame - * - * use like this Proton.log('+12',mc); log 12 times - * - * @class Proton.log - * @constructor - * @param {*} logInfo; - */ - - var log = function() { - if (window.console && window.console.log) { - var arg = arguments; - if ( typeof arguments[0] == 'string') { - if (arguments[0].indexOf('+') == 0) { - var n = parseInt(arguments[0]); - if (log.once < n) { - delete arg[0]; - console.log(arg); - log.once++; - } - } else { - console.log(arg); - } - } else { - console.log(arg); - } - } - } - - log.once = 0; - Proton.log = log; - - var Debug = Debug || { addEventListener : function(proton, fun) { @@ -4063,12 +4871,14 @@ if (!Function.prototype.bind) { var color = c || '#ff0000'; var rgb = Proton.Util.hexToRGB(color); var style = 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ',' + 0.5 + ')'; + return style; }, drawZone : function(proton, canvas, zone, clear) { var context = canvas.getContext('2d'); var style = this.setStyle(); + this.addEventListener(proton, function() { if (clear) context.clearRect(0, 0, canvas.width, canvas.height); @@ -4134,7 +4944,6 @@ if (!Function.prototype.bind) { Proton.Debug = Debug; -})(window); // http://paulirish.com/2011/requestanimationframe-for-smart-animating/ // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating @@ -4163,4 +4972,7 @@ if (!Function.prototype.bind) { window.cancelAnimationFrame = function(id) { clearTimeout(id); }; - }()); \ No newline at end of file + }()); + + return Proton; +})); \ No newline at end of file diff --git a/build/proton.min.js b/build/proton.min.js new file mode 100644 index 0000000..d769c64 --- /dev/null +++ b/build/proton.min.js @@ -0,0 +1,10 @@ +/*! + * Proton v2.2.1 + * https://github.com/a-jie/Proton + * + * Copyright 2011-2017, A-JIE + * Licensed under the MIT license + * http://www.opensource.org/licenses/mit-license + * + */ +(function(a,b){typeof define=="function"&&define.amd?define([],b):typeof module!="undefined"&&module.exports?module.exports=b():a.Proton=b()})(this,function(){function be(a,b,c,d){be._super_.call(this),this.reset(a,b,c,d)}function bd(a,b,c,d){bd._super_.call(this),this.x=a,this.y=b,this.width=c,this.height=d}function bc(a,b){bc._super_.call(this),this.x=a,this.y=b}function bb(a,b,c){bb._super_.call(this),this.x=a,this.y=b,this.radius=c,this.angle=0,this.center={x:this.x,y:this.y}}function ba(b,c,d,e,f){ba._super_.call(this),d-b>=0?(this.x1=b,this.y1=c,this.x2=d,this.y2=e):(this.x1=d,this.y1=e,this.x2=b,this.y2=c),this.dx=this.x2-this.x1,this.dy=this.y2-this.y1,this.minx=Math.min(this.x1,this.x2),this.miny=Math.min(this.y1,this.y2),this.maxx=Math.max(this.x1,this.x2),this.maxy=Math.max(this.y1,this.y2),this.dot=this.x2*this.y1-this.x1*this.y2,this.xxyy=this.dx*this.dx+this.dy*this.dy,this.gradient=this.getGradient(),this.length=this.getLength(),this.direction=a.Util.initValue(f,">")}function _(){this.vector=new a.Vector2D(0,0),this.random=0,this.crossType="dead",this.alert=!0}function $(a,b){$._super_.call(this,a,b),this.gl=this.element.getContext("experimental-webgl",{antialias:!0,stencil:!1,depth:!1}),this.gl||alert("Sorry your browser do not suppest WebGL!"),this.initVar(),this.setMaxRadius(),this.initShaders(),this.initBuffers(),this.gl.blendEquation(this.gl.FUNC_ADD),this.gl.blendFunc(this.gl.SRC_ALPHA,this.gl.ONE_MINUS_SRC_ALPHA),this.gl.enable(this.gl.BLEND)}function Z(a,b,c){Z._super_.call(this,a,b),this.context=this.element.getContext("2d"),this.imageData=null,this.rectangle=null,this.rectangle=c,this.createImageData(c)}function Y(a,b){Y._super_.call(this,a,b),this.stroke=null,this.context=this.element.getContext("2d"),this.bufferCache={}}function X(a,b,c){X._super_.call(this,a,b),this.stroke=c}function W(a,b){W._super_.call(this,a,b),this.stroke=null}function V(b,c,d){this.proton=b,this.element=c,this.stroke=d,this.pool=new a.Pool}function U(b,c,d){this.element=d,this.type=a.Util.initValue(b,"canvas"),this.proton=c,this.renderer=this.getRenderer()}function R(b,c,d){this.mouseTarget=a.Util.initValue(b,window),this.ease=a.Util.initValue(c,.7),this._allowEmitting=!1,this.initEventHandler(),R._super_.call(this,d)}function Q(a){this.selfBehaviours=[],Q._super_.call(this,a)}function P(b){this.initializes=[],this.particles=[],this.behaviours=[],this.emitTime=0,this.emitTotalTimes=-1,this.damping=.006,this.bindEmitter=!0,this.rate=new a.Rate(1,.1),P._super_.call(this,b),this.id="emitter_"+P.ID++}function O(b,c,d,e){O._super_.call(this,d,e),this.distanceVec=new a.Vector2D,this.centerPoint=a.Util.initValue(b,new a.Vector2D),this.force=a.Util.initValue(this.normalizeValue(c),100),this.name="GravityWell"}function N(a,b,c,d){N._super_.call(this,c,d),this.reset(a,b),this.name="Color"}function M(a,b,c,d,e){M._super_.call(this,d,e),this.reset(a,b,c),this.name="Rotate"}function L(a,b,c,d){L._super_.call(this,c,d),this.reset(a,b),this.name="Scale"}function K(a,b,c,d){K._super_.call(this,c,d),this.reset(a,b),this.name="Alpha"}function J(a,b,c,d){J._super_.call(this,c,d),this.reset(a,b),this.name="CrossZone"}function I(a,b,c,d,e){I._super_.call(this,d,e),this.reset(a,b,c),this.name="Collision"}function H(a,b,c){H._super_.call(this,0,a,b,c),this.name="Gravity"}function G(a,b,c,d,e){G._super_.call(this,a,b,c,d,e),this.force*=-1,this.name="Repulsion"}function F(a,b,c,d,e){F._super_.call(this,d,e),this.reset(a,b,c),this.time=0,this.name="RandomDrift"}function E(b,c,d,e,f){E._super_.call(this,e,f),this.targetPosition=a.Util.initValue(b,new a.Vector2D),this.radius=a.Util.initValue(d,1e3),this.force=a.Util.initValue(this.normalizeValue(c),100),this.radiusSq=this.radius*this.radius,this.attractionForce=new a.Vector2D,this.lengthSq=0,this.name="Attraction"}function D(b,c,d,e){D._super_.call(this,d,e),this.force=this.normalizeForce(new a.Vector2D(b,c)),this.name="Force"}function C(b,c,d){C._super_.call(this),this.image=this.setSpanValue(b),this.w=a.Util.initValue(c,20),this.h=a.Util.initValue(d,this.w)}function B(b,c,d){B._super_.call(this),this.radius=a.Util.setSpanValue(b,c,d)}function A(b,c,d){A._super_.call(this),this.massPan=a.Util.setSpanValue(b,c,d)}function z(b,c,d){z._super_.call(this),this.rPan=a.Util.setSpanValue(b),this.thaPan=a.Util.setSpanValue(c),this.type=a.Util.initValue(d,"vector")}function y(b){y._super_.call(this),this.zone=a.Util.initValue(b,new a.PointZone)}function x(b,c,d){x._super_.call(this),this.lifePan=a.Util.setSpanValue(b,c,d)}function v(){}function u(b,c){this.numPan=a.Util.initValue(b,1),this.timePan=a.Util.initValue(c,1),this.numPan=a.Util.setSpanValue(this.numPan),this.timePan=a.Util.setSpanValue(this.timePan),this.startTime=0,this.nextTime=0,this.init()}function t(b,c){this.id="Behaviour_"+t.id++,this.life=a.Util.initValue(b,Infinity),this.easing=a.ease.setEasingByName(c),this.age=0,this.energy=1,this.dead=!1,this.parents=[],this.name="Behaviour"}function r(a,b,c,d){this.x=a,this.y=b,this.width=c,this.height=d,this.bottom=this.y+this.height,this.right=this.x+this.width}function q(b){a.Util.isArray(b)?this.colorArr=b:this.colorArr=[b]}function p(b,c,d){this.isArray=!1,a.Util.isArray(b)?(this.isArray=!0,this.a=b):(this.a=a.Util.initValue(b,1),this.b=a.Util.initValue(c,this.a),this.center=a.Util.initValue(d,!1))}function i(){this.cID=0,this.list={}}function h(b){this.id="particle_"+h.ID++,this.reset(!0),a.Util.setPrototypeByObject(this,b)}function g(){this.mats=[],this.size=0;for(var b=0;b<20;b++)this.mats.push(a.Mat3.create([0,0,0,0,0,0,0,0,0]))}function b(){this.initialize()}function a(b,c){this.integrationType=a.Util.initValue(c,a.EULER),this.emitters=[],this.renderers=[],this.time=0,this.oldTime=0,a.pool=new a.Pool(100),a.integrator=new a.NumericalIntegration(this.integrationType)}a.POOL_MAX=1e3,a.TIME_STEP=60,a.USE_CLOCK=!1,a.MEASURE=100,a.EULER="euler",a.RK2="runge-kutta2",a.VERLET="verlet",a.PARTICLE_CREATED="partilcleCreated",a.PARTICLE_UPDATE="partilcleUpdate",a.PARTICLE_SLEEP="particleSleep",a.PARTICLE_DEAD="partilcleDead",a.PROTON_UPDATE="protonUpdate",a.PROTON_UPDATE_AFTER="protonUpdateAfter",a.EMITTER_ADDED="emitterAdded",a.EMITTER_REMOVED="emitterRemoved",a.amendChangeTabsBug=!0,a.TextureBuffer={},a.TextureCanvasBuffer={},a.prototype={addRender:function(a){a.proton=this,this.renderers.push(a.proton)},addEmitter:function(b){this.emitters.push(b),b.parent=this,this.dispatchEvent(a.EMITTER_ADDED,b)},removeEmitter:function(b){var c=this.emitters.indexOf(b);this.emitters.splice(c,1),b.parent=null,this.dispatchEvent(a.EMITTER_REMOVED,b)},update:function(){this.dispatchEvent(a.PROTON_UPDATE);if(a.USE_CLOCK){this.oldTime||(this.oldTime=(new Date).getTime());var b=(new Date).getTime();this.elapsed=(b-this.oldTime)/1e3,a.amendChangeTabsBug&&this.amendChangeTabsBug(),this.oldTime=b}else this.elapsed=.0167;if(this.elapsed>0)for(var c=0;c.5&&(this.oldTime=(new Date).getTime(),this.elapsed=0)},getCount:function(){var a=0,b=this.emitters.length;for(var c=0;c>b;return a+1},makeTranslation:function(a,b){return[1,0,0,0,1,0,a,b,1]},makeRotation:function(a){var b=Math.cos(a),c=Math.sin(a);return[b,-c,0,c,b,0,0,0,1]},makeScale:function(a,b){return[a,0,0,0,b,0,0,0,1]},matrixMultiply:function(a,b){var c=a[0],d=a[1],e=a[2],f=a[3],g=a[4],h=a[5],i=a[6],j=a[7],k=a[8],l=b[0],m=b[1],n=b[2],o=b[3],p=b[4],q=b[5],r=b[6],s=b[7],t=b[8];return[c*l+d*o+e*r,c*m+d*p+e*s,c*n+d*q+e*t,f*l+g*o+h*r,f*m+g*p+h*s,f*n+g*q+h*t,i*l+j*o+k*r,i*m+j*p+k*s,i*n+j*q+k*t]}};a.WebGLUtil=e;var f=f||{createCanvas:function(a,b,c,d){var e=document.createElement("canvas"),f=d?d:"absolute";e.id=a,e.width=b,e.height=c,e.style.position=f,e.style.opacity=0,this.transformDom(e,-500,-500,0,0);return e},transformDom:function(a,b,c,d,e){a.style.WebkitTransform="translate("+b+"px, "+c+"px) "+"scale("+d+") "+"rotate("+e+"deg)",a.style.MozTransform="translate("+b+"px, "+c+"px) "+"scale("+d+") "+"rotate("+e+"deg)",a.style.OTransform="translate("+b+"px, "+c+"px) "+"scale("+d+") "+"rotate("+e+"deg)",a.style.msTransform="translate("+b+"px, "+c+"px) "+"scale("+d+") "+"rotate("+e+"deg)",a.style.transform="translate("+b+"px, "+c+"px) "+"scale("+d+") "+"rotate("+e+"deg)"}};a.DomUtil=f,g.prototype.set=function(b,c){c==0?a.Mat3.set(b,this.mats[0]):a.Mat3.multiply(this.mats[c-1],b,this.mats[c]),this.size=Math.max(this.size,c+1)},g.prototype.push=function(b){this.size==0?a.Mat3.set(b,this.mats[0]):a.Mat3.multiply(this.mats[this.size-1],b,this.mats[this.size]),this.size++},g.prototype.pop=function(){this.size>0&&this.size--},g.prototype.top=function(){return this.mats[this.size-1]},a.MStack=g,h.ID=0,h.prototype={getDirection:function(){return Math.atan2(this.v.x,-this.v.y)*(180/Math.PI)},reset:function(b){this.life=Infinity,this.age=0,this.energy=1,this.dead=!1,this.sleep=!1,this.target=null,this.sprite=null,this.parent=null,this.mass=1,this.radius=10,this.alpha=1,this.scale=1,this.rotation=0,this.color=null,this.easing=a.ease.setEasingByName(a.easeLinear),b?(this.transform={},this.p=new a.Vector2D,this.v=new a.Vector2D,this.a=new a.Vector2D,this.old={p:new a.Vector2D,v:new a.Vector2D,a:new a.Vector2D},this.behaviours=[]):(a.Util.destroyObject(this.transform),this.p.set(0,0),this.v.set(0,0),this.a.set(0,0),this.old.p.set(0,0),this.old.v.set(0,0),this.old.a.set(0,0),this.removeAllBehaviours()),this.transform.rgb={r:255,g:255,b:255};return this},update:function(a,b){if(!this.sleep){this.age+=a;var c=this.behaviours.length,d;for(d=0;d=this.life)this.destroy();else{var e=this.easing(this.age/this.life);this.energy=Math.max(1-e,0)}},addBehaviour:function(a){this.behaviours.push(a),a.hasOwnProperty("parents")&&a.parents.push(this),a.initialize(this)},addBehaviours:function(a){var b=a.length,c;for(c=0;c-1){var a=this.behaviours.splice(b,1);a.parents=null}},removeAllBehaviours:function(){a.Util.destroyArray(this.behaviours)},destroy:function(){this.removeAllBehaviours(),this.energy=0,this.dead=!0,this.parent=null}},a.Particle=h,i.prototype={create:function(b,c){this.cID++;return typeof b=="function"?a.Util.classApply(b,c):b.clone()},getCount:function(){var a=0;for(var b in this.list)a+=this.list[b].length;return a++},get:function(a,b){var c,d=a.__puid||j.id(a);this.list[d]&&this.list[d].length>0?c=this.list[d].pop():c=this.create(a,b),c.__puid=a.__puid||d;return c},set:function(a){return this._getList(a.__puid).push(a)},destroy:function(){for(var a in this.list)this.list[a].length=0,delete this.list[a]},_getList:function(a){a=a||"default",this.list[a]||(this.list[a]=[]);return this.list[a]}},a.Pool=i;var j={_id:0,_uids:{},id:function(a){for(var b in this._uids)if(this._uids[b]==a)return b;var c="PUID_"+this._id++;this._uids[c]=a;return c},hash:function(a){return}},k={randomAToB:function(a,b,c){return c?Math.floor(Math.random()*(b-a))+a:a+Math.random()*(b-a)},randomFloating:function(a,b,c){return k.randomAToB(a-b,a+b,c)},randomZone:function(a){},degreeTransform:function(a){return a*Math.PI/180},toColor16:function(a){return"#"+a.toString(16)},randomColor:function(){return"#"+("00000"+(Math.random()*16777216<<0).toString(16)).slice(-6)}};a.MathUtils=k;var m=function(b){this.type=a.Util.initValue(b,a.EULER)};m.prototype={integrate:function(a,b,c){this.eulerIntegrate(a,b,c)},eulerIntegrate:function(a,b,c){a.sleep||(a.old.p.copy(a.p),a.old.v.copy(a.v),a.a.multiplyScalar(1/a.mass),a.v.add(a.a.multiplyScalar(b)),a.p.add(a.old.v.multiplyScalar(b)),c&&a.v.multiplyScalar(c),a.a.clear())}},a.NumericalIntegration=m;var n=function(a,b){this.x=a||0,this.y=b||0};n.prototype={set:function(a,b){this.x=a,this.y=b;return this},setX:function(a){this.x=a;return this},setY:function(a){this.y=a;return this},getGradient:function(){if(this.x!=0)return Math.atan2(this.y,this.x);if(this.y>0)return Math.PI/2;if(this.y<0)return-Math.PI/2},copy:function(a){this.x=a.x,this.y=a.y;return this},add:function(a,b){if(b!==undefined)return this.addVectors(a,b);this.x+=a.x,this.y+=a.y;return this},addXY:function(a,b){this.x+=a,this.y+=b;return this},addVectors:function(a,b){this.x=a.x+b.x,this.y=a.y+b.y;return this},addScalar:function(a){this.x+=a,this.y+=a;return this},sub:function(a,b){if(b!==undefined)return this.subVectors(a,b);this.x-=a.x,this.y-=a.y;return this},subVectors:function(a,b){this.x=a.x-b.x,this.y=a.y-b.y;return this},multiplyScalar:function(a){this.x*=a,this.y*=a;return this},divideScalar:function(a){a!==0?(this.x/=a,this.y/=a):this.set(0,0);return this},min:function(a){this.x>a.x&&(this.x=a.x),this.y>a.y&&(this.y=a.y);return this},max:function(a){this.x=this.x&&b<=this.bottom&&b>=this.y?!0:!1}},a.Rectangle=r;var s=s||{create:function(a){var b=new Float32Array(9);a&&this.set(a,b);return b},set:function(a,b){for(var c=0;c<9;c++)b[c]=a[c];return b},multiply:function(a,b,c){var d=a[0],e=a[1],f=a[2],g=a[3],h=a[4],i=a[6],j=a[7],k=b[0],l=b[1],m=b[2],n=b[3],o=b[4],p=b[6],q=b[7];c[0]=k*d+l*g,c[1]=k*e+l*h,c[2]=f*m,c[3]=n*d+o*g,c[4]=n*e+o*h,c[6]=p*d+q*g+i,c[7]=p*e+q*h+j;return c},inverse:function(a,b){var c=a[0],d=a[1],e=a[3],f=a[4],g=a[6],h=a[7],i=f,j=-e,k=h*e-f*g,l=c*i+d*j,m;m=1/l,b[0]=i*m,b[1]=-d*m,b[3]=j*m,b[4]=c*m,b[6]=k*m,b[7]=(-h*c+d*g)*m;return b},multiplyVec2:function(a,b,c){var d=b[0],e=b[1];c[0]=d*a[0]+e*a[3]+a[6],c[1]=d*a[1]+e*a[4]+a[7];return c}};a.Mat3=s,t.id=0,t.prototype={reset:function(b,c){this.life=a.Util.initValue(b,Infinity),this.easing=a.Util.initValue(c,a.ease.setEasingByName(a.easeLinear))},normalizeForce:function(b){return b.multiplyScalar(a.MEASURE)},normalizeValue:function(b){return b*a.MEASURE},initialize:function(a){},applyBehaviour:function(a,b,c){this.age+=b;if(this.age>=this.life||this.dead)this.energy=0,this.dead=!0,this.destroy();else{var d=this.easing(a.age/a.life);this.energy=Math.max(1-d,0)}},destroy:function(){var a,b=this.parents.length,c;for(c=0;c=this.nextTime){this.startTime=0,this.nextTime=this.timePan.getValue();return this.numPan.b==1?this.numPan.getValue(!1)>.5?1:0:this.numPan.getValue(!0)}return 0}},a.Rate=u,v.prototype.reset=function(){},v.prototype.init=function(a,b){b?this.initialize(b):this.initialize(a)},v.prototype.initialize=function(a){},a.Initialize=v;var w={initialize:function(b,c,d){var e=d.length,f;for(f=0;f4e-6&&this.lengthSq=this.delay&&(b.a.addXY(a.MathUtils.randomAToB(-this.panFoce.x,this.panFoce.x),a.MathUtils.randomAToB(-this.panFoce.y,this.panFoce.y)),this.time=0)},a.RandomDrift=F,a.Util.inherits(G,a.Attraction),G.prototype.reset=function(a,b,c,d,e){G._super_.prototype.reset.call(this,a,b,c,d,e),this.force*=-1},a.Repulsion=G,a.Util.inherits(H,a.Force),H.prototype.reset=function(a,b,c){H._super_.prototype.reset.call(this,0,a,b,c)},a.Gravity=H,a.G=H,a.Util.inherits(I,a.Behaviour),I.prototype.reset=function(b,c,d,e,f){this.emitter=a.Util.initValue(b,null),this.mass=a.Util.initValue(c,!0),this.callback=a.Util.initValue(d,null),this.collisionPool=[],this.delta=new a.Vector2D,e&&I._super_.prototype.reset.call(this,e,f)},I.prototype.applyBehaviour=function(a,b,c){var d=this.emitter?this.emitter.particles.slice(c):this.pool.slice(c),e,f,g,h,i,j=d.length;for(var k=0;k-1&&this.initializes.splice(b,1)},P.prototype.removeInitializers=function(){a.Util.destroyArray(this.initializes)},P.prototype.addBehaviour=function(){var a=arguments.length,b;for(b=0;b-1&&this.behaviours.splice(b,1)},P.prototype.removeAllBehaviours=function(){a.Util.destroyArray(this.behaviours)},P.prototype.integrate=function(b){var c=1-this.damping;a.integrator.integrate(this,b,c);var d=this.particles.length,e;for(e=0;e=this.life||this.dead)&&this.destroy(),this.emitting(b),this.integrate(b);var c,d=this.particles.length,e;for(e=d-1;e>=0;e--)c=this.particles[e],c.dead&&(this.dispatchEvent(a.PARTICLE_DEAD,c),a.pool.set(c),this.particles.splice(e,1))},P.prototype.setupParticle=function(b,c,d){var e=this.initializes,f=this.behaviours;c&&(c instanceof Array?e=c:e=[c]),d&&(d instanceof Array?f=d:f=[d]),b.reset(),a.InitializeUtil.initialize(this,b,e),b.addBehaviours(f),b.parent=this,this.particles.push(b)},P.prototype.destroy=function(){this.dead=!0,this.emitTotalTimes=-1,this.particles.length==0&&(this.removeInitializers(),this.removeAllBehaviours(),this.parent&&this.parent.removeEmitter(this))},a.Emitter=P,a.Util.inherits(Q,a.Emitter),Q.prototype.addSelfBehaviour=function(){var a=arguments.length,b;for(b=0;b-1&&this.selfBehaviours.splice(b,1)},Q.prototype.update=function(a){Q._super_.prototype.update.call(this,a);if(!this.sleep){var b=this.selfBehaviours.length,c;for(c=0;cthis.element.width||c<0||c>this.elementwidth)){var f=((c>>0)*a.width+(b>>0))*4;a.data[f]=e.r,a.data[f+1]=e.g,a.data[f+2]=e.b,a.data[f+3]=d.alpha*255}},Z.prototype.onParticleDead=function(a){},a.PixelRender=Z,a.Util.inherits($,a.BaseRender),$.prototype.resize=function(a,b){this.umat[4]=-2,this.umat[7]=1,this.smat[0]=1/a,this.smat[4]=1/b,this.mstack.set(this.umat,0),this.mstack.set(this.smat,1),this.gl.viewport(0,0,a,b),this.element.width=a,this.element.height=b},$.prototype.setMaxRadius=function(a){this.circleCanvasURL=this.createCircle(a)},$.prototype.getVertexShader=function(){var a=["uniform vec2 viewport;","attribute vec2 aVertexPosition;","attribute vec2 aTextureCoord;","uniform mat3 tMat;","varying vec2 vTextureCoord;","varying float alpha;","void main() {","vec3 v = tMat * vec3(aVertexPosition, 1.0);","gl_Position = vec4(v.x, v.y, 0, 1);","vTextureCoord = aTextureCoord;","alpha = tMat[0][2];","}"].join("\n");return a},$.prototype.getFragmentShader=function(){var a=["precision mediump float;","varying vec2 vTextureCoord;","varying float alpha;","uniform sampler2D uSampler;","uniform vec4 color;","uniform bool useTexture;","uniform vec3 uColor;","void main() {","vec4 textureColor = texture2D(uSampler, vTextureCoord);","gl_FragColor = textureColor * vec4(uColor, 1.0);","gl_FragColor.w *= alpha;","}"].join("\n");return a},$.prototype.initVar=function(){this.mstack=new a.MStack,this.umat=a.Mat3.create([2,0,1,0,-2,0,-1,1,1]),this.smat=a.Mat3.create([.01,0,1,0,.01,0,0,0,1]),this.texturebuffers={}},$.prototype.start=function(){$._super_.prototype.start.call(this),this.resize(this.element.width,this.element.height)},$.prototype.blendEquation=function(a){this.gl.blendEquation(this.gl[a])},$.prototype.blendFunc=function(a,b){this.gl.blendFunc(this.gl[a],this.gl[b])},$.prototype.getShader=function(a,b,c){var d;c?d=a.createShader(a.FRAGMENT_SHADER):d=a.createShader(a.VERTEX_SHADER),a.shaderSource(d,b),a.compileShader(d);if(!a.getShaderParameter(d,a.COMPILE_STATUS)){alert(a.getShaderInfoLog(d));return null}return d},$.prototype.initShaders=function(){var a=this.getShader(this.gl,this.getFragmentShader(),!0),b=this.getShader(this.gl,this.getVertexShader(),!1);this.sprogram=this.gl.createProgram(),this.gl.attachShader(this.sprogram,b),this.gl.attachShader(this.sprogram,a),this.gl.linkProgram(this.sprogram),this.gl.getProgramParameter(this.sprogram,this.gl.LINK_STATUS)||alert("Could not initialise shaders"),this.gl.useProgram(this.sprogram),this.sprogram.vpa=this.gl.getAttribLocation(this.sprogram,"aVertexPosition"),this.sprogram.tca=this.gl.getAttribLocation(this.sprogram,"aTextureCoord"),this.gl.enableVertexAttribArray(this.sprogram.tca),this.gl.enableVertexAttribArray(this.sprogram.vpa),this.sprogram.tMatUniform=this.gl.getUniformLocation(this.sprogram,"tMat"),this.sprogram.samplerUniform=this.gl.getUniformLocation(this.sprogram,"uSampler"),this.sprogram.useTex=this.gl.getUniformLocation(this.sprogram,"useTexture"),this.sprogram.color=this.gl.getUniformLocation(this.sprogram,"uColor"),this.gl.uniform1i(this.sprogram.useTex,1)},$.prototype.initBuffers=function(){this.unitIBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.unitIBuffer);var a=[0,3,1,0,2,3];this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,new Uint16Array(a),this.gl.STATIC_DRAW);var b=[];for(var c=0;c<100;c++)b.push(c);idx=new Uint16Array(b),this.unitI33=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.unitI33),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,idx,this.gl.STATIC_DRAW),b=[];for(c=0;c<100;c++)b.push(c,c+1,c+2);idx=new Uint16Array(b),this.stripBuffer=this.gl.createBuffer(),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.stripBuffer),this.gl.bufferData(this.gl.ELEMENT_ARRAY_BUFFER,idx,this.gl.STATIC_DRAW)},$.prototype.createCircle=function(b){this.circleCanvasRadius=a.WebGLUtil.nhpot(a.Util.initValue(b,32));var c=a.DomUtil.createCanvas("circle_canvas",this.circleCanvasRadius*2,this.circleCanvasRadius*2),d=c.getContext("2d");d.beginPath(),d.arc(this.circleCanvasRadius,this.circleCanvasRadius,this.circleCanvasRadius,0,Math.PI*2,!0),d.closePath(),d.fillStyle="#FFF",d.fill();return c.toDataURL()},$.prototype.setImgInCanvas=function(b){var c=b.target.width,d=b.target.height,e=a.WebGLUtil.nhpot(b.target.width),f=a.WebGLUtil.nhpot(b.target.height),g=b.target.width/e,h=b.target.height/f;this.texturebuffers[b.transform.src]||(this.texturebuffers[b.transform.src]=[this.gl.createTexture(),this.gl.createBuffer(),this.gl.createBuffer()]),b.transform.texture=this.texturebuffers[b.transform.src][0],b.transform.vcBuffer=this.texturebuffers[b.transform.src][1],b.transform.tcBuffer=this.texturebuffers[b.transform.src][2],this.gl.bindBuffer(this.gl.ARRAY_BUFFER,b.transform.tcBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,0,g,0,0,h,h,h]),this.gl.STATIC_DRAW),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,b.transform.vcBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,0,c,0,0,d,c,d]),this.gl.STATIC_DRAW);var i=b.transform.canvas.getContext("2d"),j=i.getImageData(0,0,e,f);this.gl.bindTexture(this.gl.TEXTURE_2D,b.transform.texture),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,j),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR_MIPMAP_NEAREST),this.gl.generateMipmap(this.gl.TEXTURE_2D),b.transform.textureLoaded=!0,b.transform.textureWidth=c,b.transform.textureHeight=d},$.prototype.setStroke=function(a,b){},$.prototype.onProtonUpdate=function(){},$.prototype.onParticleCreated=function(b){var c=this;b.transform.textureLoaded=!1,b.transform.tmat=a.Mat3.create(),b.transform.tmat[8]=1,b.transform.imat=a.Mat3.create(),b.transform.imat[8]=1,b.target?a.Util.getImage(b.target,b,!0,function(a){c.setImgInCanvas.call(c,a),a.transform.oldScale=1}):a.Util.getImage(this.circleCanvasURL,b,!0,function(a){c.setImgInCanvas.call(c,a),a.transform.oldScale=a.radius/c.circleCanvasRadius})},$.prototype.onParticleUpdate=function(a){a.transform.textureLoaded&&(this.updateMatrix(a),this.gl.uniform3f(this.sprogram.color,a.transform.rgb.r/255,a.transform.rgb.g/255,a.transform.rgb.b/255),this.gl.uniformMatrix3fv(this.sprogram.tMatUniform,!1,this.mstack.top()),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,a.transform.vcBuffer),this.gl.vertexAttribPointer(this.sprogram.vpa,2,this.gl.FLOAT,!1,0,0),this.gl.bindBuffer(this.gl.ARRAY_BUFFER,a.transform.tcBuffer),this.gl.vertexAttribPointer(this.sprogram.tca,2,this.gl.FLOAT,!1,0,0),this.gl.bindTexture(this.gl.TEXTURE_2D,a.transform.texture),this.gl.uniform1i(this.sprogram.samplerUniform,0),this.gl.bindBuffer(this.gl.ELEMENT_ARRAY_BUFFER,this.unitIBuffer),this.gl.drawElements(this.gl.TRIANGLES,6,this.gl.UNSIGNED_SHORT,0),this.mstack.pop())},$.prototype.onParticleDead=function(a){},$.prototype.updateMatrix=function(b){var c=a.WebGLUtil.makeTranslation(-b.transform.textureWidth/2,-b.transform.textureHeight/2),d=a.WebGLUtil.makeTranslation(b.p.x,b.p.y),e=b.rotation*(Math.PI/180),f=a.WebGLUtil.makeRotation(e),g=b.scale*b.transform.oldScale,h=a.WebGLUtil.makeScale(g,g),i=a.WebGLUtil.matrixMultiply(c,h);i=a.WebGLUtil.matrixMultiply(i,f),i=a.WebGLUtil.matrixMultiply(i,d),a.Mat3.inverse(i,b.transform.imat),i[2]=b.alpha,this.mstack.push(i)},a.WebGLRender=$,_.prototype={getPosition:function(){},crossing:function(a){}},a.Zone=_,a.Util.inherits(ba,a.Zone),ba.prototype.getPosition=function(){this.random=Math.random(),this.vector.x=this.x1+this.random*this.length*Math.cos(this.gradient),this.vector.y=this.y1+this.random*this.length*Math.sin(this.gradient);return this.vector},ba.prototype.getDirection=function(a,b){var c=this.dy,d=-this.dx,e=this.dot,f=d==0?1:d;return(c*a+d*b+e)*f>0?!0:!1},ba.prototype.getDistance=function(a,b){var c=this.dy,d=-this.dx,e=this.dot,f=c*a+d*b+e;return f/Math.sqrt(this.xxyy)},ba.prototype.getSymmetric=function(a){var b=a.getGradient(),c=this.getGradient(),d=2*(c-b),e=a.x,f=a.y;a.x=e*Math.cos(d)-f*Math.sin(d),a.y=e*Math.sin(d)+f*Math.cos(d);return a},ba.prototype.getGradient=function(){return Math.atan2(this.dy,this.dx)},ba.prototype.getRange=function(a,b){var c=Math.abs(this.getGradient());c<=Math.PI/4?a.p.xthis.minx&&b():a.p.ythis.miny&&b()},ba.prototype.getLength=function(){return Math.sqrt(this.dx*this.dx+this.dy*this.dy)},ba.prototype.crossing=function(a){var b=this;this.crossType=="dead"?this.direction==">"||this.direction=="R"||this.direction=="right"||this.direction=="down"?this.getRange(a,function(){b.getDirection(a.p.x,a.p.y)&&(a.dead=!0)}):this.getRange(a,function(){b.getDirection(a.p.x,a.p.y)||(a.dead=!0)}):this.crossType=="bound"?this.getRange(a,function(){b.getDistance(a.p.x,a.p.y)<=a.radius&&(b.dx==0?a.v.x*=-1:b.dy==0?a.v.y*=-1:b.getSymmetric(a.v))}):this.crossType=="cross"&&this.alert&&(alert("Sorry lineZone does not support cross method"),this.alert=!1)},a.LineZone=ba,a.Util.inherits(bb,a.Zone),bb.prototype.getPosition=function(){this.random=Math.random(),this.angle=Math.PI*2*Math.random(),this.vector.x=this.x+this.random*this.radius*Math.cos(this.angle),this.vector.y=this.y+this.random*this.radius*Math.sin(this.angle);return this.vector},bb.prototype.setCenter=function(a,b){this.center.x=a,this.center.y=b},bb.prototype.crossing=function(a){var b=a.p.distanceTo(this.center);this.crossType=="dead"?b-a.radius>this.radius&&(a.dead=!0):this.crossType=="bound"?b+a.radius>=this.radius&&this.getSymmetric(a):this.crossType=="cross"&&this.alert&&(alert("Sorry CircleZone does not support cross method"),this.alert=!1)},bb.prototype.getSymmetric=function(a){var b=a.v.getGradient(),c=this.getGradient(a),d=2*(c-b),e=a.v.x,f=a.v.y;a.v.x=e*Math.cos(d)-f*Math.sin(d),a.v.y=e*Math.sin(d)+f*Math.cos(d)},bb.prototype.getGradient=function(a){return-Math.PI/2+Math.atan2(a.p.y-this.center.y,a.p.x-this.center.x)},a.CircleZone=bb,a.Util.inherits(bc,a.Zone),bc.prototype.getPosition=function(){this.vector.x=this.x,this.vector.y=this.y;return this.vector},bc.prototype.crossing=function(a){this.alert&&(alert("Sorry PointZone does not support crossing method"),this.alert=!1)},a.PointZone=bc,a.Util.inherits(bd,a.Zone),bd.prototype.getPosition=function(){this.vector.x=this.x+Math.random()*this.width,this.vector.y=this.y+Math.random()*this.height;return this.vector},bd.prototype.crossing=function(a){this.crossType=="dead"?(a.p.x+a.radiusthis.x+this.width&&(a.dead=!0),a.p.y+a.radiusthis.y+this.height&&(a.dead=!0)):this.crossType=="bound"?(a.p.x-a.radiusthis.x+this.width&&(a.p.x=this.x+this.width-a.radius,a.v.x*=-1),a.p.y-a.radiusthis.y+this.height&&(a.p.y=this.y+this.height-a.radius,a.v.y*=-1)):this.crossType=="cross"&&(a.p.x+a.radiusthis.x+this.width&&a.v.x>=0&&(a.p.x=this.x-a.radius),a.p.y+a.radiusthis.y+this.height&&a.v.y>=0&&(a.p.y=this.y-a.radius))},a.RectZone=bd,a.Util.inherits(be,a.Zone),be.prototype.reset=function(b,c,d,e){this.imageData=b,this.x=a.Util.initValue(c,0),this.y=a.Util.initValue(d,0),this.d=a.Util.initValue(e,2),this.vectors=[],this.setVectors()},be.prototype.setVectors=function(){var a,b,c=this.imageData.width,d=this.imageData.height;for(a=0;a>0)*c+(a>>0))*4;this.imageData.data[e+3]>0&&this.vectors.push({x:a+this.x,y:b+this.y})}return this.vector},be.prototype.getBound=function(a,b){var c=((b>>0)*this.imageData.width+(a>>0))*4;return this.imageData.data[c+3]>0?!0:!1},be.prototype.getPosition=function(){return this.vector.copy(this.vectors[Math.floor(Math.random()*this.vectors.length)])},be.prototype.getColor=function(a,b){a-=this.x,b-=this.y;var c=((b>>0)*this.imageData.width+(a>>0))*4;return{r:this.imageData.data[c],g:this.imageData.data[c+1],b:this.imageData.data[c+2],a:this.imageData.data[c+3]}},be.prototype.crossing=function(a){this.crossType=="dead"?this.getBound(a.p.x-this.x,a.p.y-this.y)?a.dead=!0:a.dead=!1:this.crossType=="bound"&&(this.getBound(a.p.x-this.x,a.p.y-this.y)||a.v.negate())},a.ImageZone=be;var bf=bf||{addEventListener:function(b,c){b.addEventListener(a.PROTON_UPDATE,function(){c()})},setStyle:function(b){var c=b||"#ff0000",d=a.Util.hexToRGB(c),e="rgba("+d.r+","+d.g+","+d.b+","+.5+")";return e},drawZone:function(b,c,d,e){var f=c.getContext("2d"),g=this.setStyle();this.addEventListener(b,function(){e&&f.clearRect(0,0,c.width,c.height),d instanceof a.PointZone?(f.beginPath(),f.fillStyle=g,f.arc(d.x,d.y,10,0,Math.PI*2,!0),f.fill(),f.closePath()):d instanceof a.LineZone?(f.beginPath(),f.strokeStyle=g,f.moveTo(d.x1,d.y1),f.lineTo(d.x2,d.y2),f.stroke(),f.closePath()):d instanceof a.RectZone?(f.beginPath(),f.strokeStyle=g,f.drawRect(d.x,d.y,d.width,d.height),f.stroke(),f.closePath()):d instanceof a.CircleZone&&(f.beginPath(),f.strokeStyle=g,f.arc(d.x,d.y,d.radius,0,Math.PI*2,!0),f.stroke(),f.closePath())})},drawEmitter:function(a,b,c,d){var e=b.getContext("2d"),f=this.setStyle();this.addEventListener(a,function(){d&&e.clearRect(0,0,b.width,b.height),e.beginPath(),e.fillStyle=f,e.arc(c.p.x,c.p.y,10,0,Math.PI*2,!0),e.fill(),e.closePath()})},test:{},setTest:function(a,b){this.test[a]=b},getTest:function(a){return this.test.hasOwnProperty(a)?this.test[a]:!1}};a.Debug=bf,function(){var a=0,b=["ms","moz","webkit","o"];for(var c=0;c - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + + - + Crafty-Proton diff --git a/example/game/easeljs/easeljs.html b/example/game/easeljs/easeljs.html index 3bd1f1a..b299d34 100644 --- a/example/game/easeljs/easeljs.html +++ b/example/game/easeljs/easeljs.html @@ -21,7 +21,7 @@ background: #000000; } - + diff --git a/example/game/quarkjs/squirrel.html b/example/game/quarkjs/squirrel.html index f064f58..c356911 100644 --- a/example/game/quarkjs/squirrel.html +++ b/example/game/quarkjs/squirrel.html @@ -18,7 +18,7 @@ - + diff --git a/example/helloworld/emitter/emitter.html b/example/helloworld/emitter/emitter.html index b8fe5b2..6323e01 100644 --- a/example/helloworld/emitter/emitter.html +++ b/example/helloworld/emitter/emitter.html @@ -19,7 +19,7 @@ - + - + - + - + - + - + - + - + - + - + diff --git a/example/render/pixel/google.html b/example/render/pixel/google.html index a472fef..7fd7ad3 100644 --- a/example/render/pixel/google.html +++ b/example/render/pixel/google.html @@ -32,7 +32,7 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +