Pulse (Sine wave)
/**
* Copyright terravilor ( http://wonderfl.net/user/terravilor )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/4fSc
*/
// forked from terravilor's Sine wave
package {
import flash.events.Event;
import flash.display.Sprite;
public class Pulse extends Sprite {
private var ball:Ball;
private var angle:Number
private var centerScale:Number;
private var range:Number;
private var yspeed:Number;
public function Pulse() {
init();
}
public function init():void {
ball = new Ball();
ball.x = stage.stageWidth / 2;
ball.y = stage.stageHeight / 2;
addChild(ball);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
//set vars
angle = 0;
centerScale = 1;
range = .5;
yspeed = .1;
}
protected function onEnterFrame(event:Event):void {
ball.scaleX = ball.scaleY = centerScale + Math.sin(angle) * range;
angle += yspeed;
}
}
}
//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()
}
}