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

Shaderを使ってパーティクルっぽいもの

処理はテキトウです・・・
Get Adobe Flash player
by zahir 12 May 2009
    Embed
/*

処理はテキトウです・・・

*/
package
{
	import __AS3__.vec.Vector;
	
	import flash.display.*;
	import flash.events.Event;
	import flash.geom.ColorTransform;
	import flash.geom.Rectangle;
	
	import net.hires.debug.Stats;

	public class Particle_test extends Sprite{
		
		private const l_w:int = 240;
		private const l_h:int = 240;
		private const len:int = l_w * l_h;
		private var s_w:int;
		private var fl:int;
		
		private var vec:Vector.<Number>;
		private var param:Vector.<Number>;
		private var fx:Vector.<Number>;
		private var fy:Vector.<Number>;
		
		
		private var s:Shader;
		private var sj:ShaderJob;
		
		private var bd:BitmapData;
		private var pn:BitmapData;
		private var ct:ColorTransform;
		private var rect:Rectangle;
		
		private var w:int;
		private var h:int;
		private var w_2:int;
		private var h_2:int;
		
		public function Particle_test(){
			this.stage.frameRate = 30;
			
			w = this.stage.stageWidth;
			h = this.stage.stageHeight;
			w_2 = w>>1;
			h_2 = h>>1;
			
			bd = new BitmapData( w, h, false, 0);
			ct = new ColorTransform(0, 0.7, 0.9, 0.9);
			rect = bd.rect;
			
			init();
			this.addChild( new Bitmap( bd ) );
			this.addChild( new Stats() );


//キャプチャのタイミングをずらすコマンド
Wonderfl.capture_delay( 1 );

			///////////////////////////////////////////////////
			this.addEventListener(Event.ENTER_FRAME, onEnter);
		}
		
		private function init():void{
			pn = new BitmapData( w, h, false, 0);
			pn.perlinNoise( w_2 >>1, h_2>>1, 4, 0xFF * Math.random(), false, true, 7 );
			var c:uint;
			vec = new Vector.<Number>();
			param = new Vector.<Number>(len*3);
			fx = new Vector.<Number>();
			fy = new Vector.<Number>();
			for(i=0; i<h; i++){
				for(var j:int=0; j<w; j++){
					c = pn.getPixel(j, i);
					fx.push((c >> 16 &0xFF) - 0x80 );
					fy.push((c >> 8 &0xFF) - 0x80 );
				}
			}
			fl = fx.length;
			
			var n:int;
			for(var i:int=0; i<len; i++){
				vec.push( w * Math.random());
				vec.push( h * Math.random());
				vec.push( 2 * Math.random() );
				vec.push( 2 * Math.random());
				
				n = i*3;
				var q:int = fl * Math.random(); 
				param[n] = fx[q]
				param[n+1] = fy[q]
				param[n+2] = (Math.random() * 0.2 + 0.9) * 0.003;
			}
			
			
			s_w = (vec.length / 4 )/l_h;
			s = new Particl_testShader();
			
			s_w = (vec.length / 4 )/l_h;
			s.data.src.width = s_w;
			s.data.src.height = l_h;
			
			s_w = (param.length / 3)/l_h;
			s.data.src2.input = param;
			s.data.src2.width = s_w;
			s.data.src2.height = l_h;
			
			s.data.world.value = [w,h];
			
			s_w = (vec.length / 4 )/l_h;
		}
		private function onEnter(e:Event):void{
			var n:int, _x:int, _y:int, q:int;
			
			s.data.src.input = vec;
			s.data.src2.input = param;
			sj = new ShaderJob( s, vec, s_w, l_h );
			sj.start( true );
			
			bd.lock(); bd.colorTransform( rect, ct);
			for(var i:int = 0; i<len; i++){n=i*4;_x=vec[n];_y=vec[n+1]; bd.setPixel( _x, _y, 0xFFFFFF ); n=i*3; q=(_x>>2)*(w_2-1)+(_y>>2); param[n] = fx[q]; param[n+1] = fy[q];}
			bd.unlock();
		}
	}
}

import flash.display.Shader;
import flash.utils.ByteArray;
class Particl_testShader extends Shader
{
	private var vec:Vector.<int> = Vector.<int>([165, 1, 0, 0, 0, 164, 12, 0, 80, 97, 114, 116, 105, 99, 108, 95, 116, 101, 115, 116, 160, 12, 110, 97, 109, 101, 115, 112, 97, 99, 101, 0, 116, 101, 115, 116, 0, 160, 12, 118, 101, 110, 100, 111, 114, 0, 120, 97, 104, 105, 114, 0, 160, 8, 118, 101, 114, 115, 105, 111, 110, 0, 1, 0, 160, 12, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 0, 121, 111, 117, 114, 32, 100, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 0, 161, 1, 2, 0, 0, 12, 95, 79, 117, 116, 67, 111, 111, 114, 100, 0, 163, 0, 4, 115, 114, 99, 0, 163, 1, 3, 115, 114, 99, 50, 0, 161, 2, 4, 1, 0, 15, 100, 115, 116, 0, 161, 1, 2, 0, 0, 3, 119, 111, 114, 108, 100, 0, 162, 2, 109, 97, 120, 86, 97, 108, 117, 101, 0, 69, 122, 0, 0, 69, 122, 0, 0, 162, 2, 109, 105, 110, 86, 97, 108, 117, 101, 0, 63, 128, 0, 0, 63, 128, 0, 0, 162, 2, 100, 101, 102, 97, 117, 108, 116, 86, 97, 108, 117, 101, 0, 67, 232, 128, 0, 67, 232, 128, 0, 29, 2, 0, 193, 0, 0, 16, 0, 50, 3, 0, 128, 63, 128, 0, 0, 50, 3, 0, 64, 63, 128, 0, 0, 50, 3, 0, 32, 63, 128, 0, 0, 50, 3, 0, 16, 63, 128, 0, 0, 50, 2, 0, 32, 63, 125, 112, 164, 49, 4, 0, 241, 2, 0, 16, 0, 29, 5, 0, 243, 4, 0, 27, 0, 29, 4, 0, 193, 5, 0, 16, 0, 29, 4, 0, 49, 5, 0, 176, 0, 49, 6, 0, 225, 2, 0, 16, 1, 29, 7, 0, 226, 6, 0, 24, 0, 29, 2, 0, 16, 4, 0, 128, 0, 3, 2, 0, 16, 2, 0, 128, 0, 29, 6, 0, 128, 7, 0, 0, 0, 3, 6, 0, 128, 7, 0, 128, 0, 29, 6, 0, 64, 2, 0, 192, 0, 1, 6, 0, 64, 6, 0, 0, 0, 29, 2, 0, 16, 6, 0, 64, 0, 29, 6, 0, 128, 4, 0, 192, 0, 3, 6, 0, 128, 2, 0, 128, 0, 29, 6, 0, 64, 7, 0, 64, 0, 3, 6, 0, 64, 7, 0, 128, 0, 29, 6, 0, 32, 6, 0, 0, 0, 1, 6, 0, 32, 6, 0, 64, 0, 29, 6, 0, 128, 6, 0, 128, 0, 29, 6, 0, 64, 4, 0, 0, 0, 1, 6, 0, 64, 2, 0, 192, 0, 29, 6, 0, 32, 6, 0, 64, 0, 29, 6, 0, 64, 4, 0, 64, 0, 1, 6, 0, 64, 6, 0, 0, 0, 29, 6, 0, 16, 6, 0, 64, 0, 50, 6, 0, 64, 0, 0, 0, 0, 42, 6, 0, 32, 6, 0, 64, 0, 29, 1, 128, 128, 0, 128, 0, 0, 52, 0, 0, 0, 1, 128, 0, 0, 1, 6, 0, 32, 0, 0, 128, 0, 53, 0, 0, 0, 0, 0, 0, 0, 43, 0, 0, 32, 6, 0, 128, 0, 29, 1, 128, 64, 0, 128, 0, 0, 52, 0, 0, 0, 1, 128, 64, 0, 2, 6, 0, 32, 0, 0, 128, 0, 54, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 0, 0, 0, 0, 50, 6, 0, 64, 0, 0, 0, 0, 42, 6, 0, 16, 6, 0, 64, 0, 29, 1, 128, 128, 0, 128, 0, 0, 52, 0, 0, 0, 1, 128, 0, 0, 1, 6, 0, 16, 0, 0, 192, 0, 53, 0, 0, 0, 0, 0, 0, 0, 43, 0, 0, 16, 6, 0, 192, 0, 29, 1, 128, 64, 0, 128, 0, 0, 52, 0, 0, 0, 1, 128, 64, 0, 2, 6, 0, 16, 0, 0, 192, 0, 54, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 0, 0, 0, 0, 29, 8, 0, 128, 6, 0, 128, 0, 29, 8, 0, 64, 6, 0, 192, 0, 29, 8, 0, 32, 2, 0, 192, 0, 29, 8, 0, 16, 6, 0, 0, 0, 29, 1, 0, 243, 8, 0, 27, 0 ]);
	private var byteArr:ByteArray;
	public function Particl_testShader():void
	{
		var len:int = vec.length;
		if(!byteArr)
		{
			byteArr = new ByteArray();
			for(var i:int=0; i<len; i++)
			{
				byteArr.writeByte( vec[i] );
			}
			this.byteCode = byteArr;
		}
	}
}