In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: forked from: forked from: 何となくふぉーく1-1::forked from: Triangle in triangle

なんとなくふぉーく1。
おえかきっぽく。
// forked from Gleb.Panteleew's forked from: forked from: 何となくふぉーく1-1::forked from: Triangle in triangle
// forked from begin's forked from: 何となくふぉーく1-1::forked from: Triangle in triangle
// forked from szktkhr's 何となくふぉーく1-1::forked from: Triangle in triangle
// forked from szktkhr's 何となくふぉーく1::forked from: Triangle in triangle
/*
    なんとなくふぉーく1。
    おえかきっぽく。
*/
// forked from cheesepie's Triangle in triangle
package {
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    import flash.display.*;
    import flash.events.Event;
    import flash.geom.Point;
    import flash.filters.*;
    [SWF(backgroundColor="0xffffff", frameRate="30")]
    public class Sketch extends Sprite {
        private var bitmap:Bitmap;
        private var bitmap2:Bitmap;
        private var bitmapData:BitmapData;
        private var p:Point;
        private var shape:Shape;
        private static const LEVEL_MAX:uint = 3;
        private var _color:uint = 0xffffff;
        public function Sketch() {
            addEventListener(Event.ADDED_TO_STAGE, _initialize);
        }
        private function _initialize(e:Event):void {
            bitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0xffffff);
            bitmap = addChild(new Bitmap(bitmapData)) as Bitmap;
            bitmap2 = addChild(new Bitmap(bitmapData.clone())) as Bitmap;
            bitmap2.blendMode = 'add';
            shape = new Shape();
            p = new Point(0, 0);
            initialize();
            var t:Timer = new Timer(1500);
            t.addEventListener(TimerEvent.TIMER, this.onTimer);
            t.start();
        }
        
        private function onTimer(e:TimerEvent):void
        {
            this._color = Math.random() * 0xFFFFFF;
        }

        
        public function initialize():void {
            addEventListener(Event.ENTER_FRAME, draw);
        }
        private function draw(e:Event):void {
            var s:Stage = stage;
            var sw:Number = s.stageWidth;
            var sh:Number = s.stageHeight;
            shape.graphics.clear();
            drawTriangle(0, 0, sw, 0, 0, sh, 0);
            drawTriangle(sw, sh, sw, 0, 0, sh, 0);
            bitmapData.draw(shape);
            bitmap.filters = [new BlurFilter(4, 4, 3)];
            bitmap2.bitmapData.copyPixels(bitmapData, bitmapData.rect, p);
        }
        private function drawTriangle(ax:Number, ay:Number, bx:Number, by:Number, cx:Number, cy:Number, level:int):void {
            var g:Graphics = shape.graphics;
            g.beginFill(this._color, 0.01);
            g.lineStyle(1, 0x000000);
            g.moveTo(ax, ay);
            g.lineTo(bx, by);
            g.lineTo(cx, cy);
            g.lineTo(ax, ay);
            g.endFill();
            if (level == LEVEL_MAX) return;
            var ab:Number = Util.getRandomRange(0.1, 0.9);
            var ac:Number = Util.getRandomRange(0.1, 0.9);
            var bc:Number = Util.getRandomRange(0.1, 0.9);
            var abax_ab:Number = ax + (bx - ax) * ab;
            var abay_ab:Number = ay + (by - ay) * ab;
            var acax_ac:Number = ax + (cx - ax) * ac;
            var acay_ac:Number = ay + (cy - ay) * ac;
            var bcbx_bc:Number = bx + (cx - bx) * bc;
            var bcby_bc:Number = by + (cy - by) * bc;
            level++;
            drawTriangle(
                ax, ay,
                abax_ab, abay_ab,
                acax_ac, acay_ac,
                level
            );
            drawTriangle(
                bx, by,
                abax_ab, abay_ab,
                bcbx_bc, bcby_bc,
                level
            );
            drawTriangle(
                cx, cy,
                acax_ac, acay_ac,
                bcbx_bc, bcby_bc,
                level
            );
        }
    }
}
internal class Util {
    public static function getRandomRange(min:Number, max:Number):Number {
        return (max - min) * Math.random() + min;
    }
}