flash-on-2010-5-27
/**
* Copyright applicott ( http://wonderfl.net/user/applicott )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/oBBp
*/
// forked from applicott's blur tester
package {
import flash.display.BlendMode;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.BlurFilter;
import flash.utils.flash_proxy;
import frocessing.color.ColorHSV;
import flash.display.Graphics;
public class Main extends Sprite
{
private static var NUM:int=39;
private static var T:int=100;
private var sp:Vector.<Circle> = new Vector.<Circle>(NUM*NUM);
private var i:int;
private var j:int;
private var cx:int;
private var cy:int;
private var r:int=3;
private var _circle:Circle;
public function Main():void{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.quality = StageQuality.LOW;
graphics.beginFill(0x000000);
graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
graphics.endFill();
for(i=0;i<NUM;i++){
cx=i*T;
for(j=0;j<NUM;j++){
var hsv:ColorHSV = new ColorHSV(i*4+j*3,1,1);
_circle = new Circle(r,hsv.toRGB().value);
_circle.alpha=0.8;
_circle.x = _circle.vx = (50+j*i)*Math.cos(i*NUM+j)+stage.stageWidth/2;
_circle.y = _circle.vy = (50+j*i)*Math.sin(i*NUM+j)+stage.stageHeight/2;
_circle.z = _circle.vz = i*i;
_circle.vy=2;
_circle.vx=1;
_circle.vz=3;
_circle.filters = [new BlurFilter(3, 3, 1)];
_circle.blendMode = BlendMode.SCREEN;
sp[i*NUM+j] = _circle;
addChild(_circle);
}
}
stage.addEventListener(MouseEvent.CLICK,onMouseClick);
addEventListener(Event.ENTER_FRAME,onFrame);
}
private function onFrame(e:Event):void{
for(i=0;i<NUM;i++){
for(j=0;j<NUM;j++){
sp[i*NUM+j].move();
if(sp[i*NUM+j].x < 1){
sp[i*NUM+j].x = 10;
sp[i*NUM+j].vx = 0;
}
if(sp[i*NUM+j].x > stage.stageWidth-20 ){
sp[i*NUM+j].x = 10;
sp[i*NUM+j].vx = 0;
}
if(sp[i*NUM+j].y < 1){
sp[i*NUM+j].y = stage.stageHeight-30;
sp[i*NUM+j].vy = 2;
}
if(sp[i*NUM+j].y > stage.stageHeight-20 ){
sp[i*NUM+j].y = 10;
sp[i*NUM+j].vy = 10;
}
if(sp[i*NUM+j].z < 2){
sp[i*NUM+j].z = stage.stageHeight-30;
sp[i*NUM+j].vz = 15;
}
if(sp[i*NUM+j].y > stage.stageHeight-20 ){
sp[i*NUM+j].z = 10;
sp[i*NUM+j].vz = 5;
}
}
}
}
private function onMouseClick(e:MouseEvent):void{
for(var i:int=0;i<sp.length;i++){
sp[i].x = sp[i].vx = (50)*Math.cos(i*NUM);
sp[i].y = sp[i].vy = (50)*Math.sin(i*NUM);
sp[i].flag*=-1;
}
}
}
}
import flash.display.Sprite;
import flash.filters.BlurFilter;
import flash.geom.Point;
class Circle extends Sprite {
public var vx:Number;
public var vy:Number;
public var vz:Number;
private var a_x:Number = 0.01;
private var a_y:Number = 0.5; // 重力y
private var a_z:Number = 0.0;
private var rub:Number = 1.3;
private var ela:Number = 1.80;
public var radius:Number;
public var flag:int=1;
public function Circle(_radius:Number, _fillColor:uint = 0x000000) {
graphics.beginFill(_fillColor);
graphics.drawCircle(0, 0, _radius);
graphics.endFill();
radius = _radius
}
public function move():void {
vx /= rub;
vy /= rub;
vz /= rub;
if((x + vx) < 0 || (x + vx) > stage.stageWidth) {
vx = -vx/ela;
}
if((y + vy) < 0 || (y + vy) > stage.stageHeight) {
vy = -vy/ela;
}
if((z + vz) < 0 || (z + vz) > stage.stageWidth) {
vz = -vz/ela;
}
x += vx;
y += vy;
z += vz;
if(flag==1&&(Math.abs(vx) < 0.01 || Math.abs(vx) >90)) vx = 20;
if(flag==1&&(Math.abs(vy) < 0.01 || Math.abs(vy) >90)) vy = 20;
if(flag==-1&&(Math.abs(vz) < 0.05 || Math.abs(vz) >90)){
vz = 20; vx=25; vy=15;
}
if((Math.abs(vz) < 0.05 || Math.abs(vz) >90)) vz = 20;
}
}