forked from: forked from: forked from: forked from: dot particle
...
* @author Default
* @version 0.1
// forked from fatmonk's forked from: forked from: forked from: dot particle
// forked from fatmonk's forked from: forked from: dot particle
// forked from hacker_cif_rxsb's forked from: dot particle
// forked from uranodai's dot particle
// write as3 code here..
/**
* ...
* @author Default
* @version 0.1
*/
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(width="400", height="400", frameRate="30", backgroundColor="0x000000")]
public class Sample2 extends Sprite{
private var _dotList:Array;
private var _flag:Boolean = true;
public function Sample2() {
var wNum:int = 12;
var hNum:int = 12
var array:int = 0;
var dotWidth:int = 6;
var dotHeight:int = 6;
var dotMargin:int = 2;
_dotList = [];
for(var j:int=0; j<hNum; j++){
for(var i:int=0; i<wNum; i++){
var tempX:int = i*(dotWidth+dotMargin)+stage.stageWidth/2-wNum*((dotWidth+dotMargin)/2);
var tempY:int = j*(dotHeight+dotMargin)+stage.stageHeight/2-hNum*((dotHeight+dotMargin)/2);
//var tempX:Number = (stage.stageWidth/2-20)*Math.sin(array*2*Math.PI/stage.stageWidth)+stage.stageWidth/2;
//var tempY:Number = (stage.stageHeight/2-20)*Math.cos(array*2*Math.PI/stage.stageHeight)+stage.stageHeight/2;
var dot:Dot = new Dot(dotWidth,dotHeight,tempX,tempY);
_dotList.push(dot);
array++
}
}
addEventListener(Event.ENTER_FRAME, draw);
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
}
private function draw(e:Event):void
{
graphics.clear();
for(var i:int=0; i<_dotList.length; i++){
_dotList[i].display(graphics);
_dotList[i].move();
_dotList[i].goOut();
}
}
private function onMouseDown(e:MouseEvent):void
{
_flag = !_flag;
for(var i:int=0; i<_dotList.length; i++){
_dotList[i].flag = _flag;
}
}
}
}
/**
* ...
* @author Default
* @version 0.1
*/
import flash.display.Graphics;
class Dot {
private var rectW:int;
private var rectH:int;
private var posX:Number;
private var posY:Number;
private var nextX:Number;
private var nextY:Number;
private var diffX:Number;
private var diffY:Number;
private var goalX:int;
private var goalY:int;
private var speed:Number;
public var flag:Boolean;
public function Dot(w:int, h:int, x:Number, y:Number) {
rectW = w;
rectH = h;
posX = x;
posY = y;
nextX = x;
nextY = y;
goalX = x;
goalY = y;
speed = 0.1;
flag = true;
}
public function display(graphic:Graphics):void
{
var color:int = Math.random()*0xFF33CC;
graphic.beginFill(color,.85);
graphic.drawCircle(posX-rectW/2, posY-rectH/2, rectW/2);
graphic.endFill();
}
public function move():void
{
if(flag){
nextX = goalX;
nextY = goalY;
speed = 0.1;
}else{
nextX += Math.random()*100-50;
nextY += Math.random()*100-50;
speed = 0.01;
}
diffX = (posX-nextX)*speed;
diffY = (posY-nextY)*speed;
posX -= diffX;
posY -= diffY;
}
public function goOut():void
{
if(posX>400+rectW){
posX = 0;
nextX = 0;
}
if(posY>400+rectH){
posY=0;
nextY=0;
}
if(posX<0-rectW){
posX = 400;
nextX = 400;
}
if(posY<0-rectH){
posY = 400;
nextY = 400;
}
}
}