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.Shader;
	import flash.display.ShaderJob;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;

	public class ShaderJob_PointRotation extends Sprite{
		
		private var w:int;
		private var h:int;
		private var cx:Number;
		private var cy:Number;
		
		
		private var s:PointRotationShader;
		private var js:ShaderJob;
		
		
		private var vec:Vector.<RotationObject>;
		private var points:Vector.<Number>;
		private var res:Vector.<Number>;
		
		public function ShaderJob_PointRotation(){
			stage.frameRate = 30;
			
			w = this.stage.stageWidth;
			h = this.stage.stageHeight;
			cx = w/2;
			cy = h/2;
			
			var len:int = 1024;
			var color:Number = 0xFFFFFF;
			var size:int = 3;
			
			vec = new Vector.<RotationObject>();
			
			for(var i:int = 0; i<len; i++){
				var ro:RotationObject = new RotationObject( cx, cy, color * Math.random(), size, cx * Math.random(), 360 * Math.random());
				vec.push( ro );
				this.addChild( ro );
				ro.x = w * Math.random();
				ro.y = h * Math.random();
			}
			
			
			s = new PointRotationShader();

			Wonderfl.capture_delay( 1 );
			
			
			///////////////////////////////////////////////////////
			this.addEventListener( Event.ENTER_FRAME, onEnter );
		}
		
		private function onEnter(e:Event):void{
			
			var len:int = vec.length;
			points = new Vector.<Number>();
			res = new Vector.<Number>();
			for(var i:int = 0; i<len; i++){
				var o:RotationObject = vec[i] as RotationObject;
				points.push( o.cx );
				points.push( o.cy );
				points.push( o.radius );
				points.push( o.rotate );
			}
			
			s.data.src.input = points;
			s.data.src.width = points.length /4 ;
			s.data.src.height = 1;
			s.data.speed.value = [ 1 ];
			s.data.addRotate.value = [ 0.5 ];
			
			js = new ShaderJob(s, res, points.length /4, 1);
			
			js.start( true );
			for(i = 0; i<len; i++){
				var r:RotationObject= vec[i] as RotationObject;
				r.x = res[ i*3 ];
				r.y = res[ i*3 + 1];
				r.rotate = res[ i*3 +2 ];
			}
		}
	}
}

import flash.display.Shader;
import flash.utils.ByteArray;
import flash.display.Shape;
import flash.display.Graphics;

class RotationObject extends Shape
{
	private var g:Graphics;
	
	public var cx:Number;
	public var cy:Number;
	public var radius:Number;
	public var rotate:Number;
	
	public function RotationObject(_cx:Number, _cy:Number, color:Number, size:int, _radius:Number, _rotate:Number):void{
		cx = _cx;
		cy = _cy;
		radius = _radius;
		rotate = _rotate;
		
		g = this.graphics;
		g.beginFill( color );
		g.drawCircle( 0, 0, size );
		g.endFill();
	}
}


/*
<languageVersion : 1.0;>

kernel PointRotation
<   namespace : "PointRotation";
    vendor : "zahir";
    version : 1;
    description : "test";
>
{
    input image4 src;
    output pixel3 dst;

    void
    evaluatePixel(){
        float2 oc = outCoord();
        float4 tmp = sample(src, oc);
        float pi = 3.14;
        
        dst.x = cos(pi/180.0 * tmp.w) * tmp.z + tmp.x;
        dst.y = sin(pi/180.0 * tmp.w) * tmp.z + tmp.y;
    }
}
*/
class PointRotationShader extends Shader
{
	
	private var vec:Vector.<int> = Vector.<int>( [ 157,79,187,78,195,48,20,61,182,51,116,72,81,118,84,41,191,64,213,157,72,89,216,64,12,172,200,170,141,136,212,198,145,237,84,136,41,159,146,242,248,3,62,160,168,95,132,16,59,215,118,7,42,22,132,151,235,115,207,203,126,101,0,94,166,184,50,77,235,175,141,151,190,49,237,152,183,114,173,93,39,151,250,152,192,152,111,116,171,140,197,163,188,111,44,198,201,70,91,23,8,70,148,210,110,105,155,46,10,189,118,30,91,198,129,252,246,178,247,181,49,86,225,25,153,179,75,108,185,96,56,81,81,64,245,220,117,90,43,60,177,181,124,184,145,171,94,163,26,17,96,211,38,184,139,80,233,59,217,175,124,90,157,15,72,102,38,149,138,175,211,63,3,234,197,81,192,126,241,43,32,156,25,199,59,80,224,76,224,131,211,156,101,248,20,56,197,156,161,168,46,190,246,196,151,25,118,160,95,148,160,73,184,224,24,48,39,92,191,145,95,96,224,180,159,196,57,68,94,80,110,228,169,50,59,236,5,77,150,252,101,208,139,152,55,4,127,21,244,196,87,65,55,165,61,93,15,185,201,151,165,220,50,232,88,124,15,245,178,196,255,183,39,255,83,79,21,122,162,158,102,204,251,6 ] );
	private var byteArr:ByteArray;
	public function PointRotationShader():void
	{
		var len:int = vec.length;
		if(!byteArr)
		{
			byteArr = new ByteArray();
			for(var i:int=0; i<len; i++)
			{
				byteArr.writeByte( vec[i] );
			}
			byteArr.inflate();
			this.byteCode = byteArr;
		}
	}
}