Commits

Andres Vargas committed 27de4ac

se centra esperma con mouse

  • Participants
  • Parent commits 6c0cf31

Comments (0)

Files changed (2)

File js/esperm.js

 	var e = this;
 	e.timerId = null;
 	e.old_pos = null;
+	e.old_angle = 360;
+	e.is_lock = false;
 	var PATH = 10;
 	var IMG_PATH ="/images/sperm_loop/sperm_loop_000";
-	var HEIGHT = 138;
-	var WIDTH = 18;
+	e.HEIGHT = 18;
+	e.WIDTH = 138;
 	var TIMER = 50;
 	
 	this._get_esperm_image = function (position, canvas) {
-		var img = canvas.image( e._get_image(position), 0,0, 138,18).hide();
+		var img = canvas.image( e._get_image(position), 0,0, e.WIDTH,e.HEIGHT)
+		img.hide();
 		return img;
 	
 	}	
 			e.esperm = null;
 		}
 		e.pos = pos;
+		e.pos[y] = e.pos[y] - (e.HEIGHT);
+		e.pos[x] = e.pos[x] - 10;
+		console.log("pos",e.pos);
+
 		clearInterval(e.timerId);
 		if( e.old_pos == null ) {
 			e.old_pos = pos;
 		}
 	}
 	this.draw = function () {	
+		e.is_lock = true;
 		pos = e.pos;
 		old_pos = e.old_pos;
 		if( !e.esperm ) {
-       			// e.esperm = canvas.image(e._get_image(0),old_pos[x],old_pos[y],138,18);
 			e.esperm = e.get_esperm(0);
+			e._array_images.attr("x", old_pos[x]).attr("y", old_pos[y]);
 		}
+
 		var i = 0;	
 		e.timerId = setInterval(
 			function (){
 					
 				d = e._distancia( old_pos, pos);
 				if( d > PATH ) {
+					e.is_lock = true;
 					if( Math.abs( pos[x]- old_pos[x] ) > PATH ) {
 						if( old_pos[x] < pos[x]) {
 							old_pos[x] += PATH;
 							old_pos[y] -= PATH;
 						}
 					}
+
+					e._array_images.attr("x", old_pos[x]).attr("y", old_pos[y]);
 				}
-				console.log("avanza",old_pos);
+				if( d == 0 || d <=PATH + 10 ) {
+					e.is_lock = false;
+				}
+		//		console.log("avanza",old_pos);
 				e.esperm  = e.get_esperm(i);
-				e._array_images.attr("x", old_pos[x]).attr("y", old_pos[y]);
-				e.esperm.attr("x", old_pos[x]).attr("y", old_pos[y]);
 				i+=1;
 			 
 			}, TIMER);
 			e.old_pos = old_pos;
 	}
 	this.rotate = function ( pos ) {
-		if( e.pos ) {
+		if( e.pos &&  !e.is_lock) {
 			var 	pos_inicial = e.pos;
 			var	pos_mouse = pos;
-			var	pos_terc = [ pos_inicial[x]+100, pos_inicial[y]];
-			new Line(canvas, pos_terc, pos_inicial,"green");
-			new Line(canvas, pos_inicial, pos_terc,"blue");
-			console.log("pos_inicial", pos_inicial,"pos_mouse", pos_mouse,"pos_terc", pos_terc);
+			//var	pos_terc = [ pos_inicial[x]+100, pos_inicial[y]];
+			// show angle
+			//new Line(canvas, pos_inicial, pos_mouse,"green");
 			var angle = Raphael.angle( 
-						  pos_mouse[x], pos_mouse[y],
 						  pos_inicial[x], pos_inicial[y],
-						  pos_terc[x], pos_terc[y]
+						  pos_mouse[x], pos_mouse[y]
+						 // pos_terc[x], pos_terc[y]
 						 );
 			e.angle = angle;
-			console.log(angle);
-			e._array_images.rotate(e.angle);
+			e._array_images.rotate(e.angle - e.old_angle);
+			e.old_angle = angle;
 		}
 	}
 
 	for(var i=0; i< 15; i++) {
 		e._array_images.push( e._get_esperm_image(i, canvas) );
 	}
+	e._array_images.hide();
 }

File js/images.js

 	
 	esperm = new  Esperm(canvas);
 	window.onclick = function ( event ) {
+		console.log(event);
 		pos = [event.x, event.y];
-		console.log("esperm new pos",pos);
 		esperm.update(pos);
 		esperm.draw();
 	}
 	window.onmousemove = function ( e ) {
 		pos_ = [e.x,e.y];
-		//esperm.rotate(pos_);
+		esperm.rotate(pos_);
 	}
 }