forked from: forked from: forked from: flash on 2009-6-2
/**
* Copyright set0 ( http://wonderfl.net/user/set0 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/fTJK
*/
// forked from set0's forked from: flash on 2009-6-2
package {
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.geom.*;
import flash.text.*;
[SWF(width=465, height=465, frameRate=60, backgroundColor=0x000000)]
public class FlashTest extends Sprite
{
private var max_line:uint = 8
private var color_array:Array = [0xff0000, 0x0000ff];
private var ball_array:Array = [];
private var plate:Sprite = new Sprite();
private var plate_target:Array =[];
private var sp_array:Array = [];
private var flag:uint = 0;
public function FlashTest()
{
addChild(plate);
var d:Number = 360 / max_line;
var init_x:int;
var init_y:int;
var center_x:Number = stage.stageWidth / 2;
var center_y:Number = stage.stageHeight / 2;
for(var i:int=0;i<max_line;i++) {
init_x = Math.cos(d * i * Math.PI / 180) * 500 + center_x;
init_y = Math.sin(d * i * Math.PI / 180) * 500 + center_y;
sp_array[i] = new Sprite();
addChild(sp_array[i]);
ball_array[i] = new Ball(color_array[i % 2], init_x, init_y, sp_array[i]);
plate_target[i] = new Sprite();
plate.addChild(plate_target[i]);
plate_target[i].x = Math.cos(d * i * Math.PI / 180) * 10;
plate_target[i].y = Math.sin(d * i * Math.PI / 180) * 10;
}
stage.addEventListener(MouseEvent.MOUSE_DOWN, init);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(event:Event):void
{
var sp:Sprite = event.target as Sprite;
var global_point:Point;
var target_x:Number;
var target_y:Number;
plate.x = stage.mouseX;
plate.y = stage.mouseY;
plate.rotation += 15;
for(var i:int=0;i<max_line;i++) {
ball_array[i].moveBall(i, plate_target[i]);
setChildIndex(ball_array[i].sp, this.numChildren-1);
drawLines(ball_array[i].sp.x, ball_array[i].sp.y, i);
}
}
private function drawLines(now_x:Number, now_y:Number, i:int):void
{
var line_sp:Sprite = new Sprite();
var color_number:uint = i % 2;
addChild(line_sp);
line_sp.graphics.lineStyle(1, 0xffffff, 0.8, false, "none");
line_sp.graphics.moveTo (ball_array[i].old_x, ball_array[i].old_y);
line_sp.graphics.lineTo(now_x, now_y);
line_sp.filters = [new GlowFilter(ball_array[i].color)];
ball_array[i].old_x = now_x;
ball_array[i].old_y = now_y;
line_sp.addEventListener(Event.ENTER_FRAME, onEnterFrameLine);
}
private function onEnterFrameLine(event:Event):void
{
var line_sp:Sprite = event.target as Sprite;
if(line_sp.alpha >= 0) {
line_sp.alpha -= 0.02;
} else {
line_sp.graphics.clear();
line_sp.removeEventListener(Event.ENTER_FRAME, onEnterFrameLine);
removeChild(line_sp);
line_sp = null;
}
}
private function init(event:Event):void
{
for (var i:int = 0; i < max_line; i++) {
ball_array[i].flag = 1;
}
}
}
}
import flash.display.*;
import flash.geom.*;
import flash.events.*;
import flash.filters.*;
class Ball
{
public var color:uint;
public var x:Number;
public var y:Number;
public var old_x:Number;
public var old_y:Number;
public var tmp_x:Number;
public var tmp_y:Number;
public var init_x:Number;
public var init_y:Number;
public var sp:Sprite;
public var flag:uint = 0;
public function Ball(color:uint, x:int, y:int, sp:Sprite)
{
this.sp = sp;
this.sp.x = x;
this.sp.y = y;
this.old_x = x;
this.old_y = y;
this.tmp_x = x;
this.tmp_y = y;
this.init_x = x;
this.init_y = y;
this.color = color;
this.sp.graphics.lineStyle(1, 0xffffff, 0.8, false, "none");
this.sp.graphics.beginFill(0xffffff, 1.0);
this.sp.graphics.drawCircle(0, 0, 1);
this.sp.filters = [new GlowFilter(color)];
}
public function moveBall(i:int, plate_sp:Sprite):void
{
var global_point:Point;
if(this.flag == 0) {
global_point = plate_sp.localToGlobal(new Point(plate_sp.x, plate_sp.y));
} else {
global_point = new Point(this.init_x, this.init_y);
}
this.tmp_x += (global_point.x - this.sp.x)/20;
this.tmp_y += (global_point.y - this.sp.y)/20;
this.tmp_x *= (0.92);
this.tmp_y *= (0.92);
this.sp.x += this.tmp_x;
this.sp.y += this.tmp_y;
if (global_point.x >= this.sp.x - 10 && global_point.x <= this.sp.x + 10&& global_point.y >= this.sp.y - 10 && global_point.y <= this.sp.y + 10) {
this.flag = 0;
}
}
}