flash on 2016-1-11
/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/oL0g
*/
package {
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.display.BitmapData;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
vecDrop = new Vector.<xDrop>(0, false);
var i:int; var a:xDrop;
for (i=0;i<32;i+=1)
{
a = new xDrop();
a.cx = Math.random()*430+30;
a.cy = Math.random()*430+30;
a.rad = 8+Math.random()*32;
vecDrop.push(a);
}//nexti
canvas = new BitmapData(128, 128, false, 0);
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var vecDrop:Vector.<xDrop>;
public var ix:Number = 1/4;
public var iy:Number = 1/4;
public var canvas:BitmapData;
public var canMat:Matrix = new Matrix(4,0,0,4);
public var tempRect:Rectangle = new Rectangle(0,0,0,0);
public function fillRect(to:BitmapData, ax:Number, ay:Number, aw:Number, ah:Number, c:uint):void
{ tempRect.x = ax|0; tempRect.y = ay|0; tempRect.width = aw; tempRect.height = ah;
to.fillRect(tempRect, c);
}//fillrect
public function onEnter(e:Event):void
{
graphics.clear();
graphics.lineStyle(2, 0);
canvas.fillRect(canvas.rect, 0xFFffFFff);
var i:int; var num:int; var a:xDrop;
num = vecDrop.length;
for(i=0;i<num;i+=1)
{
a = vecDrop[i];
fillRect(canvas, a.cx*ix-a.rad*ix, a.cy*iy-a.rad*iy, a.rad*2*ix, a.rad*2*iy, 0x808080);
}//nexti
fillRect(canvas, 0,0, 512, 4, 0xffFFffFF);
fillRect(canvas, 0,0, 4, 512, 0xffFFffFF);
for(i=0;i<num;i+=1)
{ a = vecDrop[i]; outLine(a.cx*ix, a.cy*iy); }
graphics.beginBitmapFill(canvas, canMat, false, false);
graphics.drawRect(0,0, 465,465);
graphics.endFill();
num = vecDrop.length;
for(i=0;i<num;i+=1)
{
a = vecDrop[i];
// graphics.drawCircle(a.cx,a.cy, 4);
//graphics.drawRect(a.cx-a.rad, a.cy-a.rad, a.rad*2, a.rad*2);
}//nexti
}//onenter
public function isWall(ax:int, ay:int):Boolean
{
if (ay < 0) { return true;}
if (canvas.getPixel(ax,ay)==0xFF) {return false; }
return canvas.getPixel(ax,ay) < 0xF8f8F8;
}//iswall
public var cx:int = 0;
public var cy:int = 0;
public var wx:int = 1;
public var wy:int = 0;
public var dir:int = 0;
public function outLine(ax:int, ay:int):void
{
var i:int;
cx = ax; cy = ay; for (i=0;i<1024;i+=1)
{ if (isWall(cx,cy)) { canvas.setPixel(cx,cy,0x404040); cy+=1; } else { break;} }
wx=-1; wy=0; drawWall();
cx = ax; cy = ay; for (i=0;i<1024;i+=1)
{ if (isWall(cx,cy)) { canvas.setPixel(cx,cy,0x404040); cy-=1; } else { break;} }
wx=1; wy=0; drawWall();
cx = ax; cy = ay; for (i=0;i<1024;i+=1)
{ if (isWall(cx,cy)) { canvas.setPixel(cx,cy,0x404040); cx+=1; } else { break;} }
wx=0; wy=1; drawWall();
cx = ax; cy = ay; for (i=0;i<1024;i+=1)
{ if (isWall(cx,cy)) { canvas.setPixel(cx,cy,0x404040); cx-=1; } else { break;} }
wx=0; wy=-1; drawWall();
}//outline
public function drawWall():void
{
var i:int; var t:int;
var k:int; k = 0;
for (i=0;i<4096;i+=1)
{
//if (dir != 0) { dir = 0; wx *= -1; wy *= -1; }
if (isWall(cx+wx,cy+wy)) { t = wx; wx = wy; wy = -t; }
if (isWall(cx-wy-wx,cy+wx-wy) )
if (isWall(cx-wy,cy+wx) ==false) { t = wx; wx = -wy; wy = t; }
if (canvas.getPixel(cx,cy) == 0xFF) { k+=1; if (k>=4) {break;}}
canvas.setPixel(cx,cy, 0xFF);
cx += wx; cy += wy;
}//nexti
// canvas.setPixel(cx,cy, 0xFFff);
}//outline
}//classend
}
internal class xDrop
{
public var cx:Number = 0;
public var cy:Number = 0;
public var rad:Number = 0;
}//xdrop