flash on 2010-9-2
♥0 |
Line 80 |
Modified 2010-09-02 06:21:35 |
MIT License
archived:2017-03-20 12:09:21
ActionScript3 source code
/**
* Copyright Tamanegi_kenshi ( http://wonderfl.net/user/Tamanegi_kenshi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/dnhJ
*/
package {
import flash.display.Sprite;
import flash.events.Event;
[SWF(backgroundColor = 0x000000)]
public class FlashTest extends Sprite {
private var ballNum:int = 30;
private var ballArr:Array = [];
private var vx:Number;
private var vy:Number;
public function FlashTest() {
init();
}
private function init():void{
for(var i:int = 0; i < ballNum; i++){
var ball:Ball = new Ball();
addChild(ball);
ball.x = Math.random() * 465;
ball.y = Math.random() * 465;
ballArr.push(ball);
}
addEventListener(Event.ENTER_FRAME, onEn);
}
private function onEn(e:Event):void{
spring(ballArr[0], ballArr[1]);
}
private function spring(b1:Ball, b2:Ball):void{
var dx:Number = b2.x - b1.x;
var dy:Number = b2.y - b1.y;
var dist:Number = Math.sqrt(dx * dx + dy * dy);
if(dist < 300){
graphics.clear();
graphics.lineStyle(1, 0xffffff, 1);
graphics.moveTo(b1.x ,b1.y);
graphics.lineTo(b2.x, b2.y);
vx += (b2.x - b1.x) * 0.1;
vy += (b2.y - b1.y) * 0.1;
vx *= 0.9;
vy *= 0.9;
b1.x += vx;
b1.y += vy;
}else{
graphics.clear();
}
}
}
}
import flash.display.BlendMode;
import flash.filters.GlowFilter;
import flash.filters.BlurFilter;
import flash.events.Event;
import flash.display.AVM1Movie;
import flash.display.Sprite;
class Ball extends Sprite{
public var vx:int = Math.floor(Math.random() * 10 - 5);
public var vy:int = Math.floor(Math.random() * 10 - 5);
public function Ball(){
graphics.lineStyle(1, 0xffffff);
graphics.drawCircle(0, 0, Math.random() * 10 + 10);
graphics.endFill();
this.filters = [new BlurFilter(2,2), new GlowFilter(Math.random() * 0xffffff, 1, 16, 16, 6)]
this.blendMode = BlendMode.ADD;
addEventListener(Event.ENTER_FRAME, onEnter);
}
private function onEnter(e:Event):void{
this.x += vx;
if(this.x > 465){
this.x = 0;
}
if(this.x < 0){
this.x = 465
}
this.y += vy;
if(this.y > 465){
this.y = 0;
}
if(this.y < 0){
this.y = 465;
}
}
}