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

めたぶらシグネチャ

Get Adobe Flash player
by mokehehe 11 May 2009
    Embed
package  {
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;

	[SWF(width="256", height="256", backgroundColor="0x000000", frameRate="60")] 

	public class Raster extends Sprite {
		public var g: JGraphics;
		public var bmp: Bitmap;

		private var img:BitmapData;
		private const W:int = 256;
		private const H:int = 256;

		private var raster_y:Array;
		private var theta:Number;
		private var freq:int;
		private var maxfreq:int;
		private var t:int;
		private var dt:int;
		private var dtt:int;
		private var mode:int;
		private var cnt:int;

		public function Raster() {
			g = new JGraphics(W, H);
			bmp = new Bitmap(g.getBitmapData());
			addChild(bmp);

			img = create_image();

			addEventListener(Event.ENTER_FRAME, enter_frame);

			raster_y = new Array(256);
			init();
		}

		private function init():void {
			for (var i:int = 0; i<256; ++i) {
				raster_y[i] = 0;
			}

			t = 0;
			dt = (Math.random() * 256) + 0x180;
			if (Math.random() < 0.5)	dt = -dt;
			freq = 0;
			maxfreq = (96 + (Math.random() * 192)) * 256;
			dtt = (0xd0 << 14) / maxfreq + (Math.random() * 0x7f);
			if (Math.random() < 0.5)	dtt = -dtt;
			mode = 0;	cnt = 0;
		}

		private function enter_frame(e:Event):void {
			var alpha:Number = 1;

			switch (mode) {
			case 0:
				++cnt;
				alpha = cnt / 30;
				if (cnt >= 90) {
					++mode;	cnt = 0;
				}
				break;

			case 1:
			case 2:
				freq += maxfreq / (5*60);
				if (freq > maxfreq)	freq = maxfreq;
					// ラスターバッファ作成
				t += dt;
				for (var tt:int = t, i:int = 0; i<H; i++, tt+=dtt) {
					raster_y[i] = freq * Math.sin(tt * (2*3.141592/65536)) / 256;
				}

				switch (mode) {
				case 1:
					++cnt;
					if (cnt >= 4 * 60) {
						++mode;	cnt = 0;
					}
					break;
				case 2:
					++cnt;
					alpha = (120 - cnt) / 120;
					if (cnt >= 120) {
						++mode;	cnt = 0;
					}
					break;
				}
				break;

			case 3:
				alpha = 0;
				++cnt;
				if (cnt >= 60) {
					init();
				}
				break;
			}

			if (alpha > 0) {
				render_raster(g, img, raster_y);
				if (alpha < 1)	g.fadeout(alpha);
			}
		}
	}
}


import flash.display.*;
import flash.geom.*
import flash.text.*;

function create_image():BitmapData {
	var img:BitmapData = new BitmapData(256, 256, false, 0x000000);

	drawPoly( img, [30,200, 128,30, 226,200, 120,200, 130,120, 170,40, 110,120, 90,200], 0x0000ff, 1 );
	drawCircle( img, 180, 20, 20, 0x0000ff, 1 );


	drawPoly( img, [ 30,210,  80,210,  80,220,  60,220,  60,240,  50,240,  50,220,  30,220], 0xc0c0c0, 1 );
	drawPoly( img, [ 80,240, 100,210, 110,210, 130,240, 110,240, 105,230, 100,240], 0xc0c0c0, 1 );
	drawPoly( img, [135,210, 145,210, 145,240, 135,240], 0xc0c0c0, 1 );
	drawPoly( img, [150,210, 200,210, 200,220, 180,220, 180,240, 170,240, 170,220, 150,220], 0xc0c0c0, 1 );
	drawCircle( img, 215, 225, 15, 0xc0c0c0, 1 );

	return img;
}

function drawPoly( canvas:BitmapData, points:Array, color:int, alpha:Number ):void{
	var shape:Shape = new Shape();
	shape.graphics.beginFill(color, alpha);
	shape.graphics.moveTo(points[0], points[1]);
	for(var i:int = 2; i < points.length; i+=2) {
		shape.graphics.lineTo(points[i], points[i+1]);
	}
	shape.graphics.endFill();

	var matTrans:Matrix = new Matrix();
	canvas.draw(shape, matTrans);
}

function drawCircle( canvas:BitmapData, x:Number, y:Number, r:Number, color:int, alpha:Number ):void {
	var shape:Shape = new Shape();
	shape.graphics.beginFill(color, alpha);
	shape.graphics.drawCircle(x, y, r);
	shape.graphics.endFill();

	var matTrans:Matrix = new Matrix();
	canvas.draw(shape, matTrans);
}

function render_raster( g:JGraphics, img:BitmapData, raster_y:Array ):void {
	for (var y:int = 0; y<256; ++y) {
		var v:int = (y + raster_y[y]) & 255;
		g.drawImageUV(img, 0, y, 0, v, 256, 1);
	}
}

//Java風グラフィックスラッパー
class JGraphics {
	//変数
	private var bd:BitmapData;			//BMPデータ
	private var color:uint;				//色
	private var label:TextField;		//ラベル
	private var format:TextFormat;		//フォーマット

	private var mtx:Matrix;

	private var rc:Rectangle;

	//コンストラクタ
	public function JGraphics( w:uint, h:uint ) {
		//BMPデータ
		bd = new BitmapData(w, h, false, 0xffffff);
		//色
		color = 0x000000;
		//ラベル
		label = new TextField();
		label.autoSize = TextFieldAutoSize.LEFT;
		//フォーマット
		format = new TextFormat();
		format.font = "_等幅";
		format.color = 0x000000;
		setFontSize(12);

		mtx = new Matrix();
		rc = new Rectangle(0, 0, 0, 0);
	}

	//フォントサイズの指定(ピクセル単位)
	public function setFontSize( size:int ) : void {
		var i : uint;
		label.text = "■";
		for (i = size+10; i>=1; i--) {
			format.size = i;
			label.setTextFormat(format);
			if (label.textWidth <= size) break;
		}
	}

	//文字列幅の取得
	public function stringWidth( text:String ) : int {
		label.text = text;
		label.setTextFormat(format);
		return label.textWidth;
	}

	//文字列高さの取得
	public function stringHeight( text:String ) : int {
		label.text = text;
		label.setTextFormat(format);
		return label.textHeight;
	}

	//BMPデータの取得
	public function getBitmapData():BitmapData {
		return bd;
	}

	//色の取得
	public function getColorOfRGB( r:uint, g:uint, b:uint ) : uint {
		return (r<<16)+(g<<8)+b;
	}

	//色の指定
	public function setColor( color : uint ) : void {
		this.color = color;
		format.color = color;
	}

	//ラインの描画
	public function drawLine( x0:int, y0:int, x1:int, y1:int ) : void {
		var line:Shape = new Shape();
		line.graphics.lineStyle( 0, color );
		line.graphics.moveTo( x0, y0 );
		line.graphics.lineTo( x1, y1 );
		bd.draw( line );
	}

	//矩形の描画
	public function drawRect( x:int, y:int, w:int, h:int ) : void {
		var line:Shape = new Shape();
		line.graphics.lineStyle( 0, color );
		line.graphics.moveTo( x, y );
		line.graphics.lineTo( x+w, y );
		line.graphics.lineTo( x+w, y+h );
		line.graphics.lineTo( x, y+h );
		line.graphics.lineTo( x, y );
		bd.draw( line );
	}

	//塗り潰し矩形の描画
	public function fillRect( x:int, y:int, w:uint, h:uint ) : void {
		rc.x = x;
		rc.y = y;
		rc.width = w;
		rc.height = h;
		bd.fillRect( rc, color );
	}

	//文字列の描画
	public function drawString( text:String, x:int, y:int) : void {
		if (text == null) return;
		label.text = text;
		label.setTextFormat(format);
		mtx.tx = x-(label.width -label.textWidth)/2;
		mtx.ty = y-(label.height-label.textHeight)/2-label.textHeight;
		bd.draw( label, mtx );
	}

	//イメージの描画
	public function drawImage( source:IBitmapDrawable, x:int, y:int ) : void {
		if (source == null) return;
		mtx.tx = x;
		mtx.ty = y;
		bd.draw( source, mtx );
	}
 
	//イメージの描画(幅指定)
	public function drawImageUV(source:BitmapData, x:int, y:int, tu:int, tv:int, tw:int, th:int): void {
		if (source == null) return;
		var src: BitmapData = source;
		var rc:Rectangle = new Rectangle(tu, tv, tw, th);
		var pt:Point = new Point(x, y);
		bd.copyPixels(src, rc, pt);
	}

	// フェードアウト
	public function fadeout(alpha:Number):void {
		var rect:Rectangle = new Rectangle(0, 0, bd.width, bd.height);
		var ctrfm:ColorTransform = new ColorTransform();
		ctrfm.alphaMultiplier = alpha;
		bd.colorTransform(rect, ctrfm);
	}
}