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

LightFolium (2)

//////////////////////////////////////////////////////////////////////////////
[AS3.0] LightFoliumクラスだ! (2)
http://www.project-nya.jp/modules/weblog/details.php?blog_id=1123
//////////////////////////////////////////////////////////////////////////////
Get Adobe Flash player
by ProjectNya 25 May 2010
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pZeC
 */

////////////////////////////////////////////////////////////////////////////////
// [AS3.0] LightFoliumクラスだ! (2)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1123
////////////////////////////////////////////////////////////////////////////////

package {

	import flash.display.Sprite;
	import flash.display.Shape;
	import flash.geom.Rectangle;
	import flash.geom.Point;
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	import flash.filters.BlurFilter;
	import flash.geom.ColorTransform;
	import flash.events.Event;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;

	[SWF(backgroundColor="#000000", width="465", height="465", frameRate="30")]

	public class Main extends Sprite {
		private var rect:Rectangle;
		private var point:Point;
		private var canvas:BitmapData;
		private var bitmapData:BitmapData;
		private var bitmap:Bitmap;
		private var blur:BlurFilter;
		private var colorTrans:ColorTransform;
		private var board:Sprite;
		private static var max:uint = 30;
		private static var cx:int = 232;
		private static var cy:int = 232;
		private var lights:Array;
		private var nx:uint = 1;
		private var ny:uint = 1;
		private static var interval:uint = 1500;
		private var txt:TextField;

		public function Main() {
			Wonderfl.capture_delay(10);
			init();
		}

		private function init():void {
			graphics.beginFill(0x000000);
			graphics.drawRect(0, 0, 465, 465);
			graphics.endFill();
			board = new Sprite();
			addChild(board);
			rect = new Rectangle(0, 0, 465, 465);
			point = new Point(0, 0);
			canvas = new BitmapData(rect.width, rect.height, true, 0xFF000000);
			bitmapData = new BitmapData(rect.width, rect.height, true, 0xFF000000);
			bitmap = new Bitmap(bitmapData);
			board.addChild(bitmap);
			blur = new BlurFilter(8, 8, 3);
			colorTrans = new ColorTransform(0.98, 0.98, 0.98, 1, 0, 0, 0, 0);
			lights = new Array();
			for (var n:uint = 0; n < max; n++) {
				var light:LightFolium = new LightFolium();
				var angle:Number = 360/max*n;
				light.init(cx, cy, angle);
				board.addChild(light);
				light.fly(150, 1, nx, ny);
				lights.push(light);
			}
			var timer:Timer = new Timer(interval);
			timer.addEventListener(TimerEvent.TIMER, exhchange, false, 0, true);
			timer.start();
			addEventListener(Event.ENTER_FRAME, draw, false, 0, true);
			txt = new TextField();
			addChild(txt);
			txt.x = 425;
			txt.width = 40;
			txt.type = TextFieldType.DYNAMIC;
			txt.selectable = false;
			var tf:TextFormat = new TextFormat();
			tf.size = 10;
			tf.font = "_ゴシック";
			tf.align = TextFormatAlign.LEFT;
			txt.defaultTextFormat = tf;
			txt.textColor = 0xFFFFFF;
			txt.text = "nx: 1" + String.fromCharCode(13) + "ny: 1";
		}
		private function exhchange(evt:TimerEvent):void {
			var count:uint = evt.target.currentCount;
			nx = uint(count/10)%10 + 1;
			ny = count%10 + 1;
			apply();
			txt.text = "nx: " + String(nx) + String.fromCharCode(13) + "ny: " + String(ny);
		}
		private function apply():void {
			for (var n:Number = 0; n < max; n++) {
				var light:LightFolium = lights[n];
				light.fly(150, 1, nx, ny);
			}
		}
		private function draw(evt:Event):void {
			canvas.lock();
			canvas.draw(board);
			canvas.applyFilter(canvas, rect, point, blur);
			canvas.unlock();
			bitmapData.lock();
			bitmapData.draw(canvas, null, colorTrans, null, rect, true);
			bitmapData.unlock();
		}

	}

}


//////////////////////////////////////////////////
// LightFoliumクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.geom.ColorTransform;
import flash.events.Event;

class LightFolium extends Sprite {
	private var light:Light;
	private var blink:Number;
	private var b:Number;
	private static var color1:uint = 0xFFFFFF;
	private static var color2:uint = 0x3399FF;
	private var trans:ColorTransform;
	private var tx:Number;
	private var ty:Number;
	private var cx:Number;
	private var cy:Number;
	private var r:Number;
	private var angle:Number;
	private var a:Number;
	private var nx:Number;
	private var ny:Number;
	private static var radian:Number = Math.PI/180;
	private static var deceleration:Number = 0.2;

	public function LightFolium() {
		light = new Light();
		addChild(light);
		trans = new ColorTransform(0, 0, 0, 1, 0, 0, 0, 0);
	}

	public function init(x:int, y:int, a:Number):void {
		this.x = cx = x;
		this.y = cy = y;
		angle = a;
		_blink(angle, 10);
	}
	private function _blink(blink:Number, b:Number):void {
		this.blink = blink;
		this.b = b;
	}
	private function blinking():void {
		blink += b;
		setRGB(Math.sin(blink*radian));
		light.transform.colorTransform = trans;
	}
	private function setRGB(percent:Number):void {
		var r1:int = (color1 >> 16 & 0xFF);
		var g1:int = (color1 >> 8 & 0xFF);
		var b1:int = (color1 & 0xFF);
		var r2:int = (color2 >> 16 & 0xFF);
		var g2:int = (color2 >> 8 & 0xFF);
		var b2:int = (color2 & 0xFF);
		trans.alphaMultiplier = 0.75 + 0.5*percent;
		trans.redOffset = (r1 + r2)*0.5 + (r2 - r1)*0.5*percent;
		trans.greenOffset = (g1 + g2)*0.5 + (g2 - g1)*0.5*percent;
		trans.blueOffset = (b1 + b2)*0.5 + (b2 - b1)*0.5*percent;
	}
	public function fly(r:Number, a:Number, nx:Number, ny:Number, dec:Number = 0.2):void {
		this.r = r;
		this.a = a;
		this.nx = nx;
		this.ny = ny;
		deceleration = dec;
		addEventListener(Event.ENTER_FRAME, flying, false, 0, true);
	}
	private function flying(evt:Event):void {
		blinking();
		angle += a;
		tx = cx + r*Math.sin(angle*nx*radian)*Math.cos(angle*radian);
		ty = cy + r*Math.sin(angle*ny*radian)*Math.sin(angle*radian);
		x += (tx - x)*deceleration;
		y += (ty - y)*deceleration;
	}

}


//////////////////////////////////////////////////
// Lightクラス
//////////////////////////////////////////////////

import flash.display.Shape;
import flash.geom.Matrix;
import flash.display.GradientType;

class Light extends Shape {
	private static var center:uint = 3;
	private static var light:uint = 15;
	private static var color:uint = 0xFFFFFF;

	public function Light() {
		draw();
	}

	private function draw():void {
		graphics.beginFill(color);
		graphics.drawCircle(0, 0, center);
		graphics.endFill();
		var colors:Array = [color, color];
		var alphas:Array = [0.6, 0];
		var ratios:Array = [0, 255];
		var matrix:Matrix = new Matrix();
		matrix.createGradientBox(light*2, light*2, 0, -light, -light);
		graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, matrix);
		graphics.drawCircle(0, 0, light);
		graphics.endFill();
	}

}