forked from: もじゃもじゃ (1)
もじゃもじゃ (1)
/**
* Copyright sekiryou ( http://wonderfl.net/user/sekiryou )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/iSpr
*/
// forked from ProjectNya's もじゃもじゃ (1)
////////////////////////////////////////////////////////////////////////////////
// もじゃもじゃ (1)
////////////////////////////////////////////////////////////////////////////////
package {
import flash.display.Sprite;
import flash.display.Shape;
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
[SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]
public class Main extends Sprite {
private var timer:Timer;
private static var interval:uint = 100;
private static var radius:uint = 2;
private var circle:Shape;
private static var color:uint = 0x000000;
private static var xPos:uint = 232;
private static var yPos:uint = 232;
private static var range:uint = 40;
private static var radian:Number = Math.PI/180;
public function Main() {
//Wonderfl.capture_delay(1);
init();
}
private function init():void {
circle = new Shape();
addChild(circle);
circle.x = xPos;
circle.y = yPos;
//
start();
}
private function reset():void {
circle.graphics.lineStyle(1, color);
//circle.graphics.drawCircle(0,0, range);
circle.graphics.moveTo(0, 0);
}
private function clear():void {
circle.graphics.clear();
}
public function start():void {
reset();
addEventListener(Event.ENTER_FRAME, draw, false, 0, true);
timer = new Timer(interval);
timer.addEventListener(TimerEvent.TIMER, shake, false, 0, true);
timer.start();
}
public function stop():void {
clear();
removeEventListener(Event.ENTER_FRAME, draw);
if (timer) {
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, shake);
}
}
private var x2:Number = 0;
private var y2:Number = 0;
private function draw(evt:Event):void {
var a1:Number = Math.random() * 360;
var r1:Number = Math.random();
r1 = 1 - r1 * r1 * r1 * r1 * r1 * r1;
var x1:Number = x2;
var y1:Number = y2;
var a2:Number = Math.random() * 360;
var r2:Number = Math.random();
r2 = 1 - r2 * r2 * r2 * r2 * r2 * r2;
x2 = Math.cos(a2) * range * r2;
y2 = Math.sin(a2) * range * r2;
circle.graphics.curveTo(x1, y1, (x2 + x1) / 2, (y2 + y1) / 2);
}
private function shake(evt:TimerEvent):void {
var count:uint = evt.target.currentCount;
if (count%40 == 0) {
clear();
reset();
}
circle.x = xPos + int(Math.random()*radius*2 - radius);
circle.y = yPos + int(Math.random()*radius*2 - radius);
}
}
}