Last active
August 29, 2015 13:57
-
-
Save nola/9532274 to your computer and use it in GitHub Desktop.
Particle Engine - needs tweenmax and javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div | |
id="socket" | |
class="hero" | |
data-speed="3" | |
data-scale-range="0.2" | |
data-from-x="0" | |
data-to-x="940" | |
data-from-y="200" | |
data-to-y="-300" | |
data-from-z="-100" | |
data-to-z="100" | |
data-ease="Linear.easeNone" | |
data-class-name="$('.bitstatic')" | |
> | |
<h1 class="npm"></h1> | |
<div class="bitstatic_streak bitstatic"></div> | |
<div class="bitstatic_streak bitstatic"></div> | |
<div class="bitstatic_streak bitstatic"></div> | |
<div class="bitstatic_streak bitstatic"></div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
var particle = { | |
fromX: $('#socket').data('from-x'), | |
toX: $('#socket').data('to-x'), | |
fromY: $('#socket').data('from-y'), | |
toY: $('#socket').data('to-y'), | |
fromZ: $('#socket').data('from-z'), | |
toZ: $('#socket').data('to-z'), | |
_fromX:0, | |
_toX:0, | |
_fromY:0, | |
_toY:0, | |
_fromZ:0, | |
_toZ:0, | |
speed:0, | |
scale:0, | |
speedRange:$('#socket').data('speed'), | |
scaleRange:$('#socket').data('scale-range'), | |
easeing:Linear.easeNone, | |
grain:$('.bitstatic'), | |
ignition:function(){ | |
// console.log(this); | |
// var dataObj = $("#socket").data(); | |
// $.extend(this, dataObj); | |
// console.log(this); | |
particle.init(); | |
}, | |
init:function(){ | |
particle.grain.each(this.updateParticle); | |
}, | |
updateParticle:function ( i, ele ) { | |
if(particle.fromX === 0){ | |
particle._toX = (Math.random()*particle.toX); | |
particle._fromX = particle._toX; | |
} else if(particle.toX === 0){ | |
particle._fromX = (Math.random()*particle.fromX); | |
particle._toX = particle._fromX; | |
} else { | |
particle._fromX = particle.fromX+(Math.random()*particle.fromX); | |
particle._toX = particle.toX+(Math.random()*particle.toX); | |
} | |
if(particle.fromY === 0){ | |
particle._toY = (Math.random()*particle.toY); | |
particle._fromY = particle._toY; | |
} else if(particle.toY === 0){ | |
particle._fromY = (Math.random()*particle.fromY); | |
particle._toY = particle._fromY; | |
} else { | |
particle._fromY = particle.fromY+(Math.random()*particle.fromY); | |
particle._toY = particle.toY+(Math.random()*particle.toY); | |
} | |
if(particle.fromZ === 0){ | |
particle._toZ = (Math.random()*particle.toZ); | |
particle._fromZ = particle._toZ; | |
} else if(particle.toZ === 0){ | |
particle._fromZ = (Math.random()*particle.fromZ); | |
particle._toZ = particle._fromZ; | |
} else { | |
particle._fromZ = (Math.random()*particle.fromZ); | |
particle._toZ = (Math.random()*particle.toZ); | |
} | |
particle.speed = particle.speedRange+(Math.random()*particle.speedRange); | |
particle.scale = particle.scaleRange+(Math.random()*particle.scaleRange); | |
particle.animate(i, ele); | |
}, | |
animate:function( i, ele ){ | |
TweenMax.fromTo(ele, particle.speed, {x:particle._fromX, y:particle._fromY, z:particle._fromZ, scale:particle.scale}, {x:particle._toX, y:particle._toY, z:particle._toZ, scale:particle.scale, ease:particle.easeing, onComplete:particle.updateParticle, onCompleteParams:[i,ele] }, 0); | |
} | |
} | |
particle.ignition(); | |
}); | |
//0.3+(Math.random()*0.3) | |
//Math.floor(Math.random()*290) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment