/**
* Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/hs5Z
*/
package {
import flash.geom.Matrix;
import flash.display.BitmapData;
import flash.events.Event;
import flash.display.Sprite;
public class FlashTest extends Sprite {
public function FlashTest() {
stage.quality = "LOW";
graphics.beginFill(0,1);
graphics.drawCircle(60,60, 32);
graphics.endFill();
pic.fillRect(pic.rect, 0x808080); //0xFFffFF);
pic.draw(this);
graphics.clear();
canvas.fillRect(canvas.rect,0x808080);
canvas.draw(pic);
graphics.beginBitmapFill(canvas, cmat,false,false);
graphics.drawRect(0,0,canvas.width*cmat.a, canvas.height*cmat.d);
graphics.endFill();
myPlot = new xPlot();
myPlot.cx = 60;
myPlot.cy = 28;
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}//ctor
public var pic:BitmapData = new BitmapData(120,120,false,0);
public var canvas:BitmapData = new BitmapData(120,120, false,0);
public var cmat:Matrix = new Matrix(4,0,0,4);
public var myPlot:xPlot = new xPlot();
public var futPlot:xPlot = new xPlot();
public var gt:int = 0;
public function onEnter(e:Event):void
{
gt += 1;
if (gt % 4 != 0) { return; }
var mx:Number; var my:Number;
mx = stage.mouseX / cmat.a;
my = stage.mouseY / cmat.d;
updatePlot(myPlot);
var i:int;
futPlot.copyVal(myPlot);
for (i =0; i<16;i++)
{ updatePlot(futPlot); }
canvas.lock();
canvas.fillRect(canvas.rect,0x808080);
canvas.draw(pic);
canvas.setPixel(myPlot.cx,myPlot.cy,0xFFffFF);
canvas.setPixel(futPlot.cx,futPlot.cy,0xFF);
canvas.setPixel(mx,my,isWall(mx,my)?0xFF0000:0xFF);
var ax:Number; var ay:Number;
var ang:Number;
ang = Math.atan2(futPlot.cy-myPlot.cy, futPlot.cx-myPlot.cx);
ax = Math.cos(ang); ay = Math.sin(ang);
//canvas.setPixel(myPlot.cx+ay,myPlot.cy-ax,0xFFffFF);
//canvas.setPixel(futPlot.cx+ay,futPlot.cy-ax,0xFFffFF);
var kx:Number; var ky:Number;
kx = (myPlot.cx + futPlot.cx)*0.5; ky = (myPlot.cy+futPlot.cy) *0.5;
for (i = 0; i < 32;i++)
{
kx+=ay; ky+=-ax;
canvas.setPixel(kx,ky,0xFFffFF);
}//nexti
//actually pastPlot this one
futPlot.copyVal(myPlot);
futPlot.wx *=-1; futPlot.wy*=-1;
futPlot.cx+=futPlot.wx; futPlot.cy+=futPlot.wy;
for (i =0; i<16;i++)
{ updatePlot2(futPlot);
canvas.setPixel(futPlot.cx,futPlot.cy,0xFF);
}
canvas.unlock();
}//onenter
public function isWall(ax:Number, ay:Number):Boolean
{
return pic.getPixel(ax,ay) < 0xFF;
}//iswall
public function updatePlot(a:xPlot):void
{
var t:int;
if (isWall(a.cx+a.wx,a.cy+a.wy)) { t = a.wx; a.wx = a.wy; a.wy = -t; }
if (isWall(a.cx-a.wy,a.cy+a.wx) ==false) { t = a.wx; a.wx = -a.wy; a.wy = t; }
a.cx += a.wx; a.cy += a.wy;
}//update
public function updatePlot2(a:xPlot):void
{
var t:int;
if (isWall(a.cx+a.wx,a.cy+a.wy)) { t = a.wx; a.wx = -a.wy; a.wy = t; }
if (isWall(a.cx+a.wy,a.cy-a.wx) ==false) { t = a.wx; a.wx = a.wy; a.wy = -t; }
a.cx += a.wx; a.cy += a.wy;
}//update
}//classend
}
internal class xPlot
{
public var cx:int = 0;
public var cy:int = 0;
public var wx:int = 1;
public var wy:int = 0;
public function copyVal(a:xPlot):void
{ cx=a.cx; cy=a.cy; wx =a.wx; wy =a.wy;}
}//xplot