spring03
研究室内勉強会: バネその3
パラメータはランダムよ。クリックで再描写。
/**
* Copyright sakef ( http://wonderfl.net/user/sakef )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/lIme
*/
/*
研究室内勉強会: バネその3
パラメータはランダムよ。クリックで再描写。
*/
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BlendMode;
import flash.display.Graphics;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]
public class bane03 extends Sprite
{
private var ary:Array;
private var container:Sprite;
private var bmpd:BitmapData;
public function bane03()
{
ary=[];
container=new Sprite;
bmpd=new BitmapData(465, 465, true, 0x000000);
addChild(new Bitmap(bmpd));
create();
addEventListener(Event.ENTER_FRAME, onFrame);
stage.addEventListener(MouseEvent.CLICK, create);
}
private function create(e:MouseEvent=null):void
{
bmpd.fillRect(bmpd.rect, 0x000000);
for(var i:int=0; i < 30; i++)
{
var ball:BaneBall=new BaneBall(this);
ary[i]=ball;
}
}
private function onFrame(e:Event):void
{
var g:Graphics=container.graphics;
for(var i:int=0; i < 30; i++)
{
var ball:BaneBall=ary[i]as BaneBall;
ball.update();
g.lineStyle(0.5, ball.color, 0.4);
g.moveTo(ball.oldx, ball.oldy);
g.lineTo(ball.x, ball.y);
g.endFill();
}
bmpd.draw(container, null, null, BlendMode.ADD, null, true);
g.clear();
}
}
}
import flash.display.Sprite;
class BaneBall
{
private var vx:Number;
private var vy:Number;
private var f:Number;
private var parent:Sprite;
public var x:Number;
public var y:Number;
public var oldx:Number;
public var oldy:Number;
public var color:uint;
public function BaneBall(parent:Sprite)
{
this.parent=parent;
f=0.8 + 0.15 * Math.random();
vx=vy=x=y=oldx=oldy=0;
color=0x00ffff * Math.random();
}
public function update():void
{
oldx=x;
oldy=y;
vx+=(parent.mouseX - x) * 0.04;
vy+=(parent.mouseY - y) * 0.04;
x+=vx;
y+=vy;
vx*=f;
vy*=f;
}
}