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

Optical Illusion (2)

Optical Illusion (2)
Get Adobe Flash player
by ProjectNya 25 Oct 2015
    Embed
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/iWtO
 */

////////////////////////////////////////////////////////////////////////////////
// Optical Illusion (2)
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.display.StageAlign;
    import flash.events.Event;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.geom.Matrix;
    import flash.geom.ColorTransform;
    import frocessing.color.ColorHSV;

    [SWF(backgroundColor="#000000", width="465", height="465", frameRate="60")]

    public class Main extends Sprite {
        private static var max:uint = 16;
        private var container:Sprite;
        private var circles:Array;
        private static var center:uint = 125;
        private static var radius:uint = 95;
        private static var speed:Number = 3.2;
        private static var radian:Number = Math.PI/180;
        private var bitmapData:BitmapData;
        private var canvas:Bitmap;
        private var darkness:BitmapData;
        private var matrix:Matrix;
        private var colorTransform:ColorTransform;

        public function Main() {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            init();
        }

        private function init():void {
            graphics.beginFill(0x000000);
            graphics.drawRect(0, 0, 465, 465);
            graphics.endFill();
            //
            bitmapData = new BitmapData(465, 465, true, 0x00000000);
            canvas = new Bitmap(bitmapData);
            addChild(canvas);
            //
            darkness = new BitmapData(465, 465, true, 0x33000000);
            matrix = new Matrix();
            matrix.translate(232, 232);
            colorTransform = new ColorTransform(1, 1, 1, 0.6);
            //
            container = new Sprite();
            addChild(container);
            container.x = 232;
            container.y = 232;
            //
            circles = [];
            var color:ColorHSV = new ColorHSV();
            for (var n:uint = 0; n < max; n ++) {
                var line:Sprite = new Sprite();
                container.addChild(line);
                var angle:Number = (360/max)*n;
                line.rotation = angle;
                color.h = angle;
                var circle:Circle = new Circle(color.value);
                circle.angle = angle*3;
                circle.x = center + radius*Math.sin(circle.angle*radian);
                line.addChild(circle);
                circles.push(circle);
            }
            //
            addEventListener(Event.ENTER_FRAME, update, false, 0, true);
        }
        private function update(evt:Event):void {
            for (var n:uint = 0; n < max; n ++) {
                var circle:Circle = circles[n];
                circle.angle += speed;
                circle.x = center + radius*Math.sin(circle.angle*radian);
            }
            //
            bitmapData.lock();
            bitmapData.draw(darkness);
            bitmapData.draw(container, matrix, colorTransform);
            bitmapData.unlock();
        }
    }

}


//////////////////////////////////////////////////
// Circle
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.display.Shape;

class Circle extends Sprite {
    public var id:uint;
    private var color:uint;
    private var _angle:Number = 0;
    private static var radius:uint = 6;

    public function Circle(c:uint) {
        color = c;
        init();
    }

    private function init():void {
        var circle:Shape = new Shape();
        circle.graphics.beginFill(color);
        circle.graphics.drawCircle(0, 0, radius);
        circle.graphics.endFill();
        addChild(circle);
    }
    public function get angle():Number {
        return _angle;
    }
    public function set angle(value:Number):void {
        _angle = (value + 360)%360;
    }

}