Inverse Sierpinski Triangle
click to toggle horizontal scroll
( to get results from screen shot continue to toggle furiously )
♥0 |
Line 55 |
Modified 2016-03-26 05:03:26 |
MIT License
archived:2017-03-20 02:37:17
ActionScript3 source code
/**
* Copyright WLAD ( http://wonderfl.net/user/WLAD )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/84DZ
*/
package {
import flash.text.*;
import flash.geom.Point;
import flash.geom.Rectangle;
//import net.hires.debug.Stats;
import flash.display.*;
public class Doc extends Sprite {
public function Doc() {
stage.align = 'topLeft';
stage.scaleMode = 'noScale';
stage.quality = 'low';
stage.frameRate = 60;
// color empty
var ce:uint = 0x0;
// color full
var cf:Function = function():uint { return 0xFF0000 + 0x00FFFF * Math.random() };
var bd:BitmapData = new BitmapData( stage.stageWidth, stage.stageWidth, false, ce );
var bitmap:Bitmap = new Bitmap( bd );
addChild( bitmap );
bitmap.scaleY =
bitmap.scaleX = stage.stageWidth / bd.width;
var j:int = - 1;
var j_max:int = bd.height - 2;
var j_overflow:int = 0;
// always fill first pixel
bd.setPixel( 0, 0, cf() );
var scrollH:Boolean = true;
stage.addEventListener('click', function(e:*):void {
scrollH = !scrollH;
});
function step():void
{
if( ++j > j_max )
{
bd.scroll( scrollH ? -1 : 0, -1 );
bd.fillRect( new Rectangle( 0, bd.height - 1, bd.width, 1 ), ce );
j_overflow ++;
}
for( var i:int = 0; i < bd.width - 1; ++i )
{
var jj:int = j - j_overflow;
// left pixel
var pl:uint = i > 0 ? bd.getPixel( i - 1, jj ) : ce;
// current pixel
var px:uint = bd.getPixel( i, jj );
// right pixel
var pr:uint = bd.getPixel( i + 1, jj );
if( px != ce && pl == ce )
bd.setPixel( i, jj + 1, cf() );
if( px != ce && pr == ce )
bd.setPixel( i + 1, jj + 1, cf() );
}
}
addEventListener('enterFrame', function(e:*):void {
bd.lock();
//var k:int =10;
var k:int = 2;
while ( k-- > 0 ) step();
bd.unlock();
});
}
}
}