Lab: curveTo

Trabajando con la API de dibujo de AS3 y algo de física.

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

var elasticidad:Number = .98;
var aceleracion:Number = .01;
var gravedad:Number = .9;
var color:Number = 0x9EA3A3;
var conteLinea:Shape;
var newx:Number=0;
var newy:Number=0;
 
function fDraw():void{
	conteLinea.graphics.clear();
	conteLinea.graphics.lineStyle(0, color);
	conteLinea.graphics.moveTo(pointA.x, pointA.y);
	conteLinea.graphics.curveTo(anchor.x, anchor.y, pointB.x, pointB.y);
}
 
function fInercia(event:Event):void {
	var targetx:Number = ((pointB.x-pointA.x)/2+pointA.x);
	var targety:Number = ((pointB.y-pointA.y)/2+pointA.y);
	newx = newx*elasticidad+(targetx-anchor.x)*aceleracion;
	newy = newy*elasticidad+(targety-anchor.y)*aceleracion+gravedad;
	anchor.x += newx;
	anchor.y += newy;
	fDraw();
	if (Math.abs(newx)<.01 && Math.abs(newy)<.01) {
		anchor.removeEventListener(Event.ENTER_FRAME, fInercia);
	}
 
}
 
function fPress(event:MouseEvent):void {
	stage.addEventListener(MouseEvent.MOUSE_UP,fRelease);
	color = 0xff0179;
	event.target.startDrag();
	anchor.addEventListener(Event.ENTER_FRAME, fInercia);
}
 
function fRelease(event:MouseEvent):void {
	stage.removeEventListener(MouseEvent.MOUSE_UP,fRelease);
	color = 0x9EA3A3;
	stopDrag();
}
 
function setListeners():void{
	pointA.addEventListener(MouseEvent.MOUSE_DOWN,fPress, false, 0, true);
	pointB.addEventListener(MouseEvent.MOUSE_DOWN,fPress, false, 0, true);
	pointA.addEventListener(MouseEvent.MOUSE_UP,fRelease, false, 0, true);
	pointB.addEventListener(MouseEvent.MOUSE_UP,fRelease, false, 0, true);
	anchor.addEventListener(Event.ENTER_FRAME, fInercia);
}
 
function fInit():void {
	conteLinea=new Shape();
	addChild(conteLinea);
	setListeners();
}
 
fInit();

Descarga los fuentes

¿Tienes algo que comentar?

Leave a Reply

CAPTCHA image