In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

big bang

MOUSE to create stars
any KEY to hult the stars
Get Adobe Flash player
by yAKIr 07 Jul 2011
/**
 * Copyright yAKIr ( http://wonderfl.net/user/yAKIr )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/p23L
 */

package {
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.display.StageQuality;
	import flash.events.TimerEvent;
	import flash.events.MouseEvent;
	import flash.utils.Timer;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Rectangle;
	[SWF(width = "465", height = "465", backgroundColor = "0x000000", frameRate = "60")]
	public class FlashTest extends Sprite {
		public function FlashTest() {
var bmd:BitmapData=new BitmapData(465,465,false,0x000000);
var rect:Rectangle=new Rectangle(0,0,465,465);
var bm:Bitmap=new Bitmap(bmd);
var screen:Shape=new Shape();
var dotX:Array=new Array();
var dotY:Array=new Array();
var dotSpeedX:Array=new Array();
var dotSpeedY:Array=new Array();
var NumOfStars:int=100;
var myTimer:Timer=new Timer(20);
var mouse:Boolean=false;
var currentStar:Number=0;
var lastMouseX:int=0;
var lastMouseY:int=0;
var gravX:Number=0;
var gravY:Number=0;
var pull:Number=1;
this.addChild(bm);
//stage.quality=StageQuality.LOW;
for (var i:int=0; i<NumOfStars; i++) {

	dotX.push(Math.random()*465);  
	dotY.push(Math.random()*465);
	dotSpeedX.push(Math.random()*2-1);
	dotSpeedY.push(Math.random()*2-1);
}
myTimer.addEventListener(TimerEvent.TIMER,repeate);
myTimer.start();
function repeate(event:TimerEvent):void {
	for (var a:int=0; a<NumOfStars+1; a++) {
		for (var b:int=0; b<NumOfStars; b++) {
                        if (a==NumOfStars){
                            if (!mouse){
                                gravX=mouseX;
                                 gravY=mouseY;
                                 pull=10;
                            }
                        }else{
                            gravX=dotX[a];
                              gravY=dotY[a];
                            pull=1;
                        }
                        var dis:Number = Math.sqrt((gravX-dotX[b])*(gravX-dotX[b])+(gravY-dotY[b])*(gravY-dotY[b]));
			var ang:Number=Math.atan2((dotY[b]-gravY),(dotX[b]-gravX))*(180/Math.PI);
			var spdx:Number=pull*(Math.cos(ang*Math.PI/180)/(dis*dis));
			var spdy:Number=pull*(Math.sin(ang*Math.PI/180)/(dis*dis));
			
			if (!isNaN(spdx)&& !isNaN(spdy)) {
				
				dotSpeedX[b]-=spdx;
                    dotSpeedY[b]-=spdy;	
                    			
			}
			
		}
		
	}
	
	for (var i:int=0; i<NumOfStars; i++) {
		dotX[i]+=dotSpeedX[i];
		dotY[i]+=dotSpeedY[i];

	}
	bmd.fillRect(rect,0x000000);
	for (i=0; i<NumOfStars; i++) {
		bmd.setPixel(Math.round(dotX[i]),Math.round(dotY[i]),0x00ffffff);
	}
	lastMouseX=mouseX;
	lastMouseY=mouseY;
}

stage.addEventListener(MouseEvent.MOUSE_DOWN,mouse_down);
function mouse_down(Event:MouseEvent):void {
        mouse=true;
	if (++currentStar>NumOfStars) {
		currentStar=0;
	}
	dotX[currentStar]=mouseX;
	dotY[currentStar]=mouseY;
	dotSpeedX[currentStar]=mouseX-lastMouseX;
	dotSpeedY[currentStar]=mouseY-lastMouseY;
}
stage.addEventListener(MouseEvent.MOUSE_UP,mouse_up);
function mouse_up(Event:MouseEvent):void {
        mouse=false
}
		}
	}
}