/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/SMsV
*/
package {
import flash.display.StageQuality;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
stage.quality = StageQuality.MEDIUM;
stage.quality = StageQuality.LOW;
mw= 32;
mh = 32;
cw=16;ch=16;
vecVert = new Vector.<Number>(mw*mh, false);
vecNext = new Vector.<Number>(mw*mh, false);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var ang:Number =0;
public function onEnter(e:Event):void
{
graphics.clear();
graphics.lineStyle(2, 0);
drawBox2(0,0,0, mw*cw,4,mh*ch);
if (Math.random()<0.015)
{ setDrop(Math.random()*(mw-2)+1, Math.random()*(mh-2)+1, 200); }
var vec:Vector.<Number>;
vec = vecVert;
vecVert = vecNext;
vecNext = vec;
var ax:Number; var ay:Number; var az:Number;
var h:Number;
var i:int; var k:int;
var yt:int;
var t:Number;
ang+=0.1;
t = ang;
for (i=1;i<mh-1;i+=1)
{ yt = i*mw;
for (k=1;k<mw-1;k+=1)
{
//h = ( vecVert[yt+k-1]+ vecVert[yt+k+1] )*0.95 - vecNext[yt+k];
h = ( vecVert[yt+k+mw]+vecVert[yt+k-mw]+vecVert[yt+k-1]+ vecVert[yt+k+1] )*0.45 - vecNext[yt+k];
// h -= h * 0.15;
h -= h * 0.08;
vecNext[yt+k] = h;
//drawCirc(ax,ay,az, 4);
}//nextk
}//nexti
for (i=0;i<mh;i+=1)
{ yt = i*mw; az = i*cw;
for (k=0;k<mw;k+=1)
{
ax = k*cw;
ay = h + Math.sin(t)*8;
t+=0.38;
h = vecNext[yt+k];
if (k==0) { startLine(ax,ay,az); }
contLine(ax,ay,az);
}//nextk
}//nexti
for (k=0;k<mw;k+=1)
{
for (i=0;i<mh;i+=1)
{ yt = i*mw; az = i*cw;
ax = k*cw;
ay = h + Math.sin(t)*8;
t+=0.38;
h = vecNext[yt+k];
if (i==0) { startLine(ax,ay,az); }
contLine(ax,ay,az);
}//nexti
}//nextk
}//onenter
public var vecVert:Vector.<Number>;
public var vecNext:Vector.<Number>;
public var mw:int = 0;
public var mh:int = 0;
public var cw:Number=32;
public var ch:Number=32;
public function setDrop(ax:int, ay:int, h:Number):void
{ if (ax<0||ax>=mw||ay<0||ay>=mh){return;} vecVert[ax+(ay*mw)]=h; vecNext[ax+(ay*mw)]=h; }
public var camx:Number = 0; public var camy:Number = 0; public var camz:Number = 0;
public var rendw:Number = 465 * 0.5; public var rendh:Number = 465 * 0.5;
public function drawCirc(ax:Number, ay:Number, az:Number, r:Number):void
{
var sx:Number; var sy:Number;
ax -= camx; ay -= camy; az -= camz;
sx = ax - az + rendw; sy = (ax * 0.5) + (az * 0.5) - ay;
graphics.drawCircle(sx,sy,r);
}//drawcirc
public function startLine(ax:Number, ay:Number, az:Number):void
{
var sx:Number; var sy:Number;
ax -= camx; ay -= camy; az -= camz;
sx = ax - az + rendw; sy = (ax * 0.5) + (az * 0.5) - ay;
graphics.moveTo(sx,sy);
}//startline
public function contLine(ax:Number, ay:Number, az:Number):void
{
var sx:Number; var sy:Number;
ax -= camx; ay -= camy; az -= camz;
sx = ax - az + rendw; sy = (ax * 0.5) + (az * 0.5) - ay;
graphics.lineTo(sx,sy);
}//contline
public function drawLine(ax:Number, ay:Number, az:Number,
bx:Number, by:Number, bz:Number):void
{
var sx:Number; var sy:Number;
ax -= camx; ay -= camy; az -= camz;
bx -= camx; by -= camy; bz -= camz;
sx = ax - az + rendw; sy = (ax * 0.5) + (az * 0.5) - ay;
graphics.moveTo(sx, sy);
sx = bx - bz + rendw; sy = (bx * 0.5) + (bz * 0.5) - by;
graphics.lineTo(sx, sy);
}//drawline
public function drawBox3(ax:Number,ay:Number,az:Number,
rx:Number,ry:Number,rz:Number):void
{ drawBox(ax-rx,ay-ry,az-rz,ax+rx,ay+ry,az+rz); }
public function drawBox2(ax:Number,ay:Number,az:Number,
aw:Number,ah:Number,ad:Number):void
{ drawBox(ax,ay,az, ax+aw,ay+ah,az+ad); }
public function drawBox(ax:Number, ay:Number, az:Number,
bx:Number, by:Number, bz:Number):void
{
drawLine(ax, ay, az, bx, ay, az);
drawLine(ax, by, az, bx, by, az);
drawLine(ax, ay, bz, bx, ay, bz);
drawLine(ax, by, bz, bx, by, bz);
drawLine(ax, ay, az, ax, by, az);
drawLine(bx, ay, az, bx, by, az);
drawLine(ax, ay, bz, ax, by, bz);
drawLine(bx, ay, bz, bx, by, bz);
drawLine(ax, ay, az, ax, ay, bz);
drawLine(bx, ay, az, bx, ay, bz);
drawLine(ax, by, az, ax, by, bz);
drawLine(bx, by, az, bx, by, bz);
}//drawbox
}//classend
}