Carousel with trig
/**
* Copyright terravilor ( http://wonderfl.net/user/terravilor )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/fBFJ
*/
package {
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.events.Event;
import flash.display.Sprite;
public class CircularMov extends Sprite {
private var ball:Ball;
private var txt:TextField;
private var angle:Number
private var centerX:Number;
private var centerY:Number;
private var radiusX:Number;
private var radiusY:Number;
private var speed:Number;
public function CircularMov() {
init();
}
public function init():void {
ball = new Ball();
ball.x = stage.stageWidth / 2;
addChild(ball);
txt = new TextField();
txt.autoSize = TextFieldAutoSize.LEFT;
addChild(txt);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
//set vars
angle = 0;
centerY = 200;
centerX = 200;
radiusX = 200;
radiusY = 100;
speed = .1;
}
protected function onEnterFrame(event:Event):void {
ball.x = centerX + Math.sin(angle) * radiusX;
ball.y = centerY + Math.cos(angle) * radiusY;
angle += speed;
var scale:Number = ball.y / (centerY + radiusY);
ball.scaleX = ball.scaleY = scale * 1;
txt.text = String(ball.y);
}
}
}
//ball class
import flash.display.Sprite;
class Ball extends Sprite {
private var radius:Number;
private var color:uint;
public function Ball(radius:Number = 40, color:uint = 0xff0000) {
this.radius = radius;
this.color = color;
init();
}
public function init():void {
graphics.beginFill(color);
graphics.drawCircle(0,0,radius);
graphics.endFill()
}
}