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

きらきら、ちかちか

キラキラしたのができるはずだった
/**
 * Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/eVU8
 */

package {
	//キラキラしたのができるはずだった
	
	import flash.display.Sprite;
	public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            stage.addChild( new Paper() );
        }
    }
}

import flash.display.*;
import flash.text.*;
import flash.events.*;
import flash.geom.*;
import flash.filters.*;
import mx.utils.*;
	
class Paper extends Bitmap{
	public var dots:Vector.<Dot> = new Vector.<Dot>();
	public var w:uint = 425;
	public var h:uint = 425;
	public var interval:uint = 6;
	public var blur:BlurFilter = new BlurFilter();
	private var light:Boolean = false;
	private var lightSize:int = 100;
	
	public function Paper():void{
		addEventListener( Event.ADDED_TO_STAGE, init );
	}
	
	private function init(e:Event):void{
		removeEventListener( Event.ADDED_TO_STAGE, init );
			
		bitmapData = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0x000000 );
		


		addEventListener( Event.ENTER_FRAME, onFrame );
		parent.addEventListener( MouseEvent.MOUSE_DOWN, onDown );
		//parent.addEventListener( MouseEvent.MOUSE_MOVE, onMove );
		parent.addEventListener( MouseEvent.MOUSE_UP, onUp );
	
		dots = new Vector.<Dot>();
		bitmapData.lock();
		var count:uint = 0;
		for(var i:uint=0; i<width; i+=interval){
			for(var j:uint=0; j<height; j+=interval){
				dots[count] = new Dot(i,j);
				count++;
			}
		}
		bitmapData.unlock();
	}
	
	
	private function onFrame(e:Event):void{
		
		bitmapData.lock();
		
		var count:uint = 0;

		if(light){
			lightSize+=3;
		}else if(lightSize > 100){
			lightSize-=5;
		}else{
			lightSize = 100;
		}
		
		for(var i:uint=0; i<width; i+=interval){
			for(var j:uint=0; j<height; j+=interval){
				dots[count].color = 0xFFFFFF * Math.random();
				var black:Number = 90;
				
				var px:int = dots[count].x;
				var py:int = dots[count].y;
				
				var mx:int = mouseX;
				var my:int = mouseY;
				if( (px-mx)*(px-mx) + (py-my)*(py-my) <= lightSize*lightSize ){
					black = Math.sqrt((px-mx)*(px-mx) + (py-my)*(py-my)) / lightSize*100;
					if(light == false){black = (black+90)/2;}
				}
				
				if(black>90){ black = 90;}
				
				dots[count].color = ColorUtil.adjustBrightness2( dots[count].color, -black)	
				
				
				bitmapData.fillRect(new Rectangle(dots[count].x,dots[count].y,interval-1,interval-1),dots[count].color );
				count++;
			}
		}
		
		bitmapData.unlock();
	}
	
	private function onDown(e:Event):void{
		light = true;
	}
	
	private function onUp(e:Event):void{
		light = false;
	}
}


class Dot{
	public var x:int;
	public var y:int;
	public var px:int;
	public var py:int;
	public var color:uint;
	
	
	public function Dot( _x:int, _y:int ){
		x = _x; y = _y;
		px = x; py = y;
	}
	public function escape( mx:int , my:int , r:int ):void{
		var targetX:int;var targetY:int;
		if( (px-mx)*(px-mx) + (py-my)*(py-my) <= r*r ){
			var d:Number = Math.atan2( px-mx, py-my );
			targetX = px + Math.sin(d)*r;
			targetY = py + Math.cos(d)*r;
			x = (targetX+x)/2;
			y = (targetY+y)/2;
		}else{
			x = px;
			y = py;
		}
		
		
		
	}
	
}