もじゃもじゃ (2)
いい感じ。
/**
* Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/eB79
*/
////////////////////////////////////////////////////////////////////////////////
// もじゃもじゃ (2)
////////////////////////////////////////////////////////////////////////////////
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 = 50;
private static var radius:uint = 5;
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 = 200;
private static var radian:Number = Math.PI/180;
private var x2:Number = 0;
private var y2:Number = 0;
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(4, color);
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 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, (x1 + x2)/2, (y1 + y2)/2);
}
private function shake(evt:TimerEvent):void {
var count:uint = evt.target.currentCount;
if (count%100 == 0) {
clear();
reset();
}
circle.x = xPos + int(Math.random()*radius*2 - radius);
circle.y = yPos + int(Math.random()*radius*2 - radius);
}
}
}