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 gbone 15 May 2010
/**
 * Copyright gbone ( http://wonderfl.net/user/gbone )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/7cWz
 */

//
// 使い方いまいちわからない。学習しながらつかう
//
package {
	//importってたぶんincludeみたいなもの
	import flash.display.Sprite;
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	
	//iroirosettei
	[SWF(width=465,height=465,backgroundColor=0xFFFFFF,frameRate=60)]

	//entry point兼ねてるらしい
	public class Main extends Sprite 
	{
		//画面大きさとか
		private const WIDTH:int = 465;
		private const HEIGHT:int = 465;
		
		//toriaezu
		private var canvas:BitmapData;
		private var time:Number = 12;
		
		//速くなる?わからない
		private var x1:Number;
		private var y1:Number;
		private var dx:Number;
		private var dy:Number;
		private var sn:Number;
		private var cn:Number; 
		private var t10:Number;
		private var col:Number;
		//ep
		public function Main():void 
		{
			//描画箇所作ってbitmap作成して割り当てるっぽい
			canvas = new BitmapData(WIDTH, HEIGHT, false, 0x0);
			addChild(new Bitmap(canvas)) as Bitmap;
			
			//CreateThreadみたいなかんじ?
			addEventListener(Event.ENTER_FRAME, update);
		}

		//こいつがなんどもコールされるらしい
		private function update(e:Event):void 
		{
			var x:int;
			var y:int;
			var scale:int = 2;
			t10 = time * 0.15;	
			sn = Math.sin(t10) * 0.5;
			cn = Math.cos(t10) * 0.5;
			time += 0.01666666 * 1.2;

			//inchiki
			dx = 2.0 / WIDTH;
			dy = 2.0 / HEIGHT;
			
			//draw
			canvas.lock();
			//canvas.fillRect(canvas.rect, 0x2F0F2F);

			//ラスタライザ遅いので何とかしないと
			y1 = -1.0;
			for(y = 0 ; y < HEIGHT; y += scale) {
				x1 = -1.0;
				for(x = 0 ; x < WIDTH; x += scale) {
					//shader
					shader(x1, y1)
					var col:int = (1-col) * 255;
					//yo
					canvas.setPixel(x, y, col << 8);
					x1 += dx * scale;
			 	}	
			 	y1 += dy * scale;
			}
			canvas.unlock();

		}
		
		//とりあえず実験。vectorがあればなあ
		private function shader(u:Number, v:Number):void
		{
	      var ret:Number = 1;
		  
		  //position
		  var ex:Number = 0.5;
		  var ey:Number = 0.5;// + u * v * 2.5;// + Math.cos(u * v);
		  var ez:Number = -time * 0.1;

		  
		  //direction ray
		  var rx:Number = u;
		  var ry:Number = v;
		  var rz:Number = 1;
		
		  var tx:Number = cn * rx + sn * rz;
		  var ty:Number = ry;
		  var tz:Number = cn * rz - sn * rx;
		  rx = tx;  ry = tz;  rz = ty;
		   
		  //もっかい
		  tx = cn * rx + sn * rz;
		  ty = ry;
		  tz = cn * rz - sn * rx;
		  rx = tx; ry = tz; rz = ty;
		  /* */
		  var i:Number = 0;
		  
		  //視点から適当に光線のばして衝突判定
		  for(i = 0.01; i < 0.2; i += 0.01) {
		    var px:Number = ex + rx * i;
		    var py:Number = ey + ry * i;
		    var pz:Number = ez + rz * i;
		    
		    var d:Number = Math.sin(px * 200) + Math.sin(pz * 200);
		    if(py < d) {
		    	  //大当たり。まあ遅い
		      ret = d * 0.3;
		      break;
		    }
		    
		    //当たらなかったので視点方向に目を移動
		    ex = px;
		    ey = py;
		    ez = pz;
		  }
	      col = (ret > 1.0) ? 1 : (ret < 0) ? 0 : ret;
		}
	}
}