bugs life

just a bug roaming around

HTML

<script src="http://relumastudio.com/download/TweenMax.min.js"></script>
<script src="http://relumastudio.com/download/BezierPlugin.min.js"></script>
<script src="http://relumastudio.com/download/EasePack.min.js"></script>
<script src="http://relumastudio.com/download/jquery-1.9.1.min.js"></script>
<body>
<section id="wrap">
    <h3>Please wait for atleast 10 seconds to see the animation<h3>
    <section id="container">
        <div class="box1"></div>
        <div class="box2"></div>
        <div class="box3"></div>
    </section>
</section>
</body>

CSS

*{
	margin: 0;
	padding: 0;
}

.box1, .box2, .box3{
width: 33px;
height: 33px;
background: url(http://relumastudio.com/download/bug.png) no-repeat;
position: relative;
top:0;
left:0;
overflow: hidden;
}

#wrap{
	width: 600px;
	height: 600px;
	margin: 0 auto;
	border: 1px solid red;
}

JavaScript

// targeting the div element
var box1 = $(".box1");
var box2 = $(".box2");
var box3 = $(".box3");
var box4 = $(".box4");
var box5 = $(".box5");
var box6 = $(".box6");


//helper function to get random position
function getRanPos(min, max) {
  return Math.random() * (max - min) + min;
}

//this is the insect object blueprint
var Insect = function(target){
	this.target = target;
	this.getTarget = function(){
		return this.target;
	};
};

Insect.prototype.wander = function(d,t){
	
		var posX1 = Math.floor(getRanPos(1, 600));
		var posY1 = Math.floor(getRanPos(1, 600));
		var posX2 = Math.floor(getRanPos(1, 600));
		var posY2 = Math.floor(getRanPos(1, 600));
		var posX3 = Math.floor(getRanPos(1, 600));
		var posY3 = Math.floor(getRanPos(1, 600));
		var posX4 = Math.floor(getRanPos(1, 500));
		var posY4 = Math.floor(getRanPos(1, 500));
		var posX5 = Math.floor(getRanPos(1, 500));
		var posY5 = Math.floor(getRanPos(1, 500));
		var posX6 = Math.floor(getRanPos(1, 500));
		var posY6 = Math.floor(getRanPos(1, 500));
		var s = getRanPos(8, 16); // duration of tween
        
		
		var c = getRanPos(0, 1); // curviness
		//var setInVal = Math.floor(getRanPos(1000, 5000)); // set interval

		var moveto = new TweenMax(d, s, {css:{bezier:{type:"soft", 
		values:[
		{x:posX1, y:posY1}, 
		{x:posX2, y:posY2}, 
		{x:posX3, y:posY3}, 
		{x:posX4, y:posY4},
		{x:posX5, y:posY5},
		{x:posX6, y:posY6}
		], 
                                                      autoRotate:true}}, ease:SlowMo.ease.config(0.8, 0.3), delay:t});
   //When the tween reaches 70% duration call wander again
   //time, function, params, scope
   TweenLite.delayedCall(s*0.7, this.wander, [d, 0], this)

};

//creating new insect object
var b1 = new Insect();
b1.wander(box1, 0.5);
var b2 = new Insect();
b2.wander(box2, 1);
var b3 = new Insect();
b2.wander(box3, 3);