package { import flash.display.*; import flash.geom.*; import flash.events.*; import flash.utils.*; [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="10")] /* Sierpinski triangle using BitmapData draw method * Mateusz Malczak (http://segfaultlabs.com) **/ public class Main extends MovieClip { private var _bd : BitmapData; private var _bdclone : BitmapData; private var _fmtx : Matrix; private var _mp : Point = new Point( 465/2, 465/(6*Math.random()+4) ); private var _rct : ColorTransform = new ColorTransform(1,1,1,1,40,-20,-20); private var _gct : ColorTransform = new ColorTransform(1,1,1,1,-20,40,-20); private var _bct : ColorTransform = new ColorTransform(1,1,1,1,-20,-20,40); private var tmr:Timer; public function Main():void { _bd = new BitmapData(465,465,true,0xffffff); var b:Bitmap = new Bitmap(_bd); addChild(b); _fmtx = new Matrix(0.5,0,0,0.5); _bdclone = _bd.clone(); tmr = new Timer(300,10); tmr.addEventListener( TimerEvent.TIMER, ef ); tmr.addEventListener( TimerEvent.TIMER_COMPLETE, restart ); restart(); } private function restart( evt:Event=null ):void { _bd.noise( Math.random() ); /* load some picture instead of noise */ _mp = new Point( 465/2, 465/(20*Math.random()) ); tmr.reset(); tmr.start(); }; private function ef( evt:Event ):void { _bdclone.fillRect( _bdclone.rect, 0xffffff ); _bdclone.draw( _bd ); _bd.fillRect( _bd.rect, 0xffffff ); _fmtx.tx = 0; _fmtx.ty = _mp.x; _bd.draw( _bdclone, _fmtx, _rct ); _fmtx.tx = _mp.x; _fmtx.ty = _mp.x; _bd.draw( _bdclone, _fmtx, _gct ); _fmtx.tx = _mp.y; _fmtx.ty = 0; _bd.draw( _bdclone, _fmtx, _bct ); }; } } sierpinski triangle