forked from: copy of useless website
/**
* Copyright Albert ( http://wonderfl.net/user/Albert )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/uTxD
*/
// forked from pullinear's copy of useless website
package {
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
import flash.display.Shape;
import flash.geom.Point;
import flash.display.Sprite;
import flash.system.LoaderContext
import flash.display.Bitmap
import flash.display.BitmapData
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
var startPoints:Array = new Array();
var endPoints:Array = new Array()
var backGround:Shape = new Shape();
var speedControl:int = 0;
var index:int = -1;
var blackAdd:Shape = new Shape();
blackAdd.graphics.beginFill(0x0);
blackAdd.graphics.drawRect(0,0,512,512);
blackAdd.graphics.endFill();
addChild(blackAdd);
//this is codewort's code and image~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//the original code is in here : http://wonderfl.net/c/r49o
var loader:Loader = new Loader();
var url:URLRequest = new URLRequest("http://assets.wonderfl.net/images/related_images/d/d9/d9b9/d9b9e27367920f3ef42cc14e1155ec0f18908b3b");
loader.load(url, new LoaderContext(true));
loader.contentLoaderInfo.addEventListener("complete", load_complete)
var src:BitmapData = new BitmapData(512, 512, false);
function load_complete(e:Event):void {
src.draw(e.target.content);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
startPoints[0] = new Point(0,0);
endPoints[0] = new Point(512,512);
drawDividedRect(backGround, startPoints, endPoints,src);
addChild(backGround);
// addChild(new Bitmap(src));
addEventListener("enterFrame", ente);
}
function ente(e:Event):void {
speedControl++;
if(speedControl % 1 == 0) {
speedControl = 0;
index = indexOfinIt(startPoints, endPoints, stage.mouseX, stage.mouseY);
if(index != -1) {
divide(startPoints, endPoints, index);
backGround.graphics.clear();
drawDividedRect(backGround, startPoints, endPoints,src);
}
}
}
}
// find index of rects which include the point
public function indexOfinIt(starts:Array, ends:Array, nowX:int , nowY:int):int
{
for(var i:int = 0; i < starts.length; i++) {
if(inIt(starts[i], ends[i], nowX, nowY) ) {
return i;
}
}
return -1;
}
// test that point is in the rect
public function inIt(start:Point, end:Point, nowX:int, nowY:int):Boolean
{
if(nowX > start.x && nowX < end.x && nowY > start.y && nowY < end.y) {
return true;
}
return false;
}
// drawRect
public function drawRect(s:Shape, start:Point, end:Point, col:uint = 0x0):void
{
s.graphics.beginFill(col);
//s.graphics.drawCircle( (start.x+ end.x )/2, (start.y + end.y) /2 , (end.x - start.x) /2);
s.graphics.drawRect( start.x, start.y, end.x-start.x, end.y-start.y );
}
// drawRects
public function drawDividedRect(s:Shape, starts:Array, ends:Array, src:BitmapData):void
{
for(var i:int = 0; i < starts.length; i++) {
drawRect(s, starts[i], ends[i], src.getPixel( (starts[i].x+ends[i].x)/2, (starts[i].y + ends[i].y )/2 ) );
}
}
//divide rect into 4 rects.
// divided rects saved last index of the Array
public function divide(start:Array, end:Array, Index:int):void
{
var tSP:Point = start[Index];
var tEP:Point =end[Index];
if( tEP.x - tSP.x > 2) {
var mX:int = (tEP.x + tSP.x) / 2;
var mY:int = (tEP.y + tSP.y) / 2;
start.push(new Point(tSP.x, tSP.y));
start.push(new Point(mX,tSP.y));
start.push(new Point(tSP.x , mY));
start.push(new Point(mX,mY));
end.push(new Point(mX,mY));
end.push(new Point(tEP.x, mY));
end.push(new Point(mX,tEP.y));
end.push(new Point(tEP.x, tEP.y));
start.splice(Index, 1);
end.splice(Index, 1);
}
}
}
}