forked from: リボン作ってみたよ
...
@author oreore
まだおかしな点はあるけどなんとなく思った形にちかづいた。
/**
* Copyright home ( http://wonderfl.net/user/home )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/A5RQ
*/
// forked from oreore's リボン作ってみたよ
package
{
import flash.display.*;
import flash.events.Event;
import flash.events.MouseEvent;
/**
* ...
* @author oreore
* まだおかしな点はあるけどなんとなく思った形にちかづいた。
*/
public class Main extends Sprite
{
private var a:Array;
private var vx:Number = 0;
private var vy:Number = 0;
private var spring:Number = 0.03;
private var furiction:Number = 0.83;
private const BALL_NUM:int = 20;
private const BALL_NUM2:int = 49;
private var _color:uint = 0x000000;
private var _w:int = 10;
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
var stageH:Number = stage.stageHeight;
var stageW:Number = stage.stageWidth;
var stageH2:Number = stage.stageHeight *.5;
var stageW2:Number = stage.stageWidth *.5;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
a = [];
for (var i:int = 0; i < BALL_NUM; i++)
{
a[i] = new Ball();
a[i].x = Math.random() * stageW;
a[i].y = Math.random() * stageH;
}
lineDraw();
addEventListener(Event.ENTER_FRAME, onLoop);
}
private function onLoop(e:Event):void
{
vx = mouseX;
vy = mouseY;
a[0].x = vx;
a[0].y = vy;
for (var i:int = 1; i < BALL_NUM; i++)
{
var dx:Number = a[i - 1].x - a[i].x;
var dy:Number = a[i - 1].y - a[i].y;
var ax:Number = dx * spring;
var ay:Number = dy * spring;
a[i].vx += ax;
a[i].vy += ay;
a[i].vx *= furiction;
a[i].vy *= furiction;
a[i].x += a[i].vx;
a[i].y += a[i].vy;
}
lineDraw();
if (Math.abs(ax) < 0.001) {
for (i = 1; i <BALL_NUM ; i++)
{
a[i].x = Math.random()*stage.stageWidth;
a[i].y = Math.random()*stage.stageHeight;
}
}
}
private function lineDraw():void
{
graphics.clear();
for (var i:int = 0; i < BALL_NUM2; i++)
{
if (i == 0) {
graphics.beginFill(_color);
graphics.moveTo(a[i].x, a[i].y);
var xc:Number = (a[i+1].x +a[i + 2].x) * .5;
var yc:Number = (a[i + 1].y +a[i + 2].y) * .5;
graphics.curveTo(a[i+1].x, a[i+1].y, xc, yc);
graphics.lineTo(xc + _w, yc + _w);
graphics.curveTo(a[i+1].x + _w, a[i+1].y + _w, a[i].x + _w, a[i].y + _w);
graphics.lineTo(a[i].x, a[i].y);
var oldxc:Number = xc;
var oldyc:Number = yc;
graphics.endFill();
}else if (i == 1) {
}else{
graphics.beginFill(_color);
graphics.moveTo(oldxc, oldyc);
xc = (a[i].x +a[i + 1].x) * .5;
yc = (a[i].y +a[i + 1].y) * .5;
graphics.curveTo(a[i].x, a[i].y, xc, yc);
graphics.lineTo(xc + _w, yc + _w);
graphics.curveTo(a[i].x + _w, a[i].y + _w, oldxc + _w, oldyc + _w);
graphics.lineTo(oldxc, oldyc);
graphics.endFill();
oldxc = xc;
oldyc = yc;
}
}
}
}
}
import flash.display.Sprite;
class Ball extends Sprite{
public var vx:Number = 0;
public var vy:Number = 0;
public function Ball(){
}
}