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

flash on 2011-2-27

Get Adobe Flash player
by h_sakurai 27 Feb 2011
    Embed
/**
 * Copyright h_sakurai ( http://wonderfl.net/user/h_sakurai )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/dBcy
 */

package {
    import flash.display.Bitmap;
    import flash.display.Sprite;
    import flash.events.Event;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            sp = this;
            bitmap = new Bitmap(bitmapData);
            addChild(bitmap);
            addChild(tf);
            tf.text = "init";
            initialize();
            addEventListener("enterFrame", enterFrame);
        }
        private function enterFrame(e:Event):void {
            loop();
        }
    }

}
import flash.text.TextField;

import flash.display.*;
const SIZE:int = 200; // 一辺の格子サイズ
const SIZE2:int = SIZE+2; // 一辺の格子サイズ
const HEIGHT:int = 20; // 初期の最大の砂の高さ
const DIF:Number = 0.8; // 格子点一つの転がる砂の割合
const Q:Number = 4.0; // 跳躍で飛ぶ砂の量
const L0:Number = 8.0; // 跳躍する基本の距離 (風の強さに相当)
const B0:Number = 0.1; // 砂の高さに比例する砂の飛ぶ距離を表わす定数

var sp:Sprite;
var bitmapData:BitmapData = new BitmapData(SIZE,SIZE);
var bitmap:Bitmap;
var tf:TextField = new TextField();

var h:Array = new Array(SIZE2*SIZE2);
function initialize():void {
  tf.text = "set";
  var i:int;
  initial_set(h);
  periodic(h);
  graphics(h);
}

function loop():void {
  iterate(h);
  periodic(h);
  graphics(h);
}

function initial_set(h:Array):void {
  var i:int, j:int;
  for(i=1;i<=SIZE;i++)
    for(j=1;j<=SIZE;j++)
      h[i*SIZE2+j]=HEIGHT*rnd();
}

function periodic(h:Array):void {
  var i:int;
  for(i=1;i<=SIZE;i++){
    h[i*SIZE2+0]=h[i*SIZE2+SIZE];
    h[i*SIZE2+SIZE+1]=h[i*SIZE2+1];
    h[0*SIZE2+i]=h[SIZE*SIZE2+i];
    h[(SIZE+1)*SIZE2+i]=h[1*SIZE2+i];
  }
  h[0*SIZE2+0]=h[SIZE*SIZE2+SIZE];
  h[0*SIZE2+SIZE+1]=h[SIZE*SIZE2+1];
  h[(SIZE+1)*SIZE2+0]=h[1*SIZE2+SIZE];
  h[(SIZE+1)*SIZE2+SIZE+1]=h[1*SIZE2+1];
}

var temp:Array = new Array(SIZE2*SIZE2);
function iterate(h:Array):void{
  var i:int,j:int,k:int,l:int;
  /*転がり*/
  for(i=1;i<=SIZE;i++){
    for(j=1;j<=SIZE;j++){
      temp[i*SIZE2+j]=(1.0-DIF)*h[i*SIZE2+j];  /*転がり出る砂*/
      temp[i*SIZE2+j]+=DIF/6.0*(h[(i+1)*SIZE2+j]+h[(i-1)*SIZE2+j]+h[i*SIZE2+j+1]+h[i*SIZE2+j-1]); /*最隣接からの砂*/
      temp[i*SIZE2+j]+=DIF/12.0*(h[(i+1)*SIZE2+j+1]+h[(i+1)*SIZE2+j-1]+h[(i-1)*SIZE2+j+1]+h[(i-1)*SIZE2+j-1]); /*次の隣接からの砂*/
    }
  }
  /*跳躍*/
  for(i=1;i<=SIZE;i++){
    for(j=1;j<=SIZE;j++){
      temp[i*SIZE2+j]-=Q; /*砂が飛ぶ*/
      l=(int)(L0+B0*h[i*SIZE2+j]);
      k=(i+l)%SIZE+1; /*周期的境界条件*/
      temp[k*SIZE2+j]+=Q; /*砂が着地*/
    }
  }
  for(i=1;i<=SIZE;i++)
    for(j=1;j<=SIZE;j++)
      h[i*SIZE2+j]=temp[i*SIZE2+j];
}

function graphics(h:Array):void{
  var i:int,j:int,color:int,icolor:int;
  var max:Number=0.0,min:Number=1.0;
  for(i=1;i<=SIZE;i++){
    for(j=1;j<=SIZE;j++){
      if(h[i*SIZE2+j]>max)max=h[i*SIZE2+j];
      if(h[i*SIZE2+j]<min)min=h[i*SIZE2+j];
    }
  }
  for(i=1;i<=SIZE;i++){
    for(j=1;j<=SIZE;j++){
      icolor=(int)((0.6*(h[i*SIZE2+j]-min)/(max-min)+0.4)*255);
      color=icolor * 0x010100; /*赤と緑の値の割合で黄の濃淡を作る*/
      bitmapData.setPixel(i,j,color);
    }
  }
  tf.text =  "a";
}

var r:int=12345678;
function rnd():Number {
  var c:int=656329,k:int=163;
  r=(k*r+c)%12518383;
  return(r/12518383.0);
}