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: Saqoosha challenge for amateurs [Rainbow Star Painter]

/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/x3ku
 */

// forked from kimo0517's forked from: Saqoosha challenge for amateurs [Rainbow Star Painter]
// forked from checkmate's Saqoosha challenge for amateurs
package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.display.BlendMode;
    import flash.display.StageQuality;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import flash.geom.ColorTransform;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    
    [SWF(width=465, height=465, backgroundColor=0x000000, frameRate=60)]
    public class RainbowStarPainter extends Sprite { 
        private const BLUR_FILTER:BlurFilter = new BlurFilter(12, 12, 1);
        private const BLUR_FILTER2:BlurFilter = new BlurFilter(30, 30, 1);
        private const ZERO_POINT:Point = new Point(0, 0);
        private const DIM_COLOR:ColorTransform = new ColorTransform(0.2, 0.2, 0.2, 0.2);    
        
        private const rainbow:Gradation = new Gradation(0xff0000, 0xffff00, 0x00ff00, 0x00ffff, 0x0000ff, 0xff00ff, 0xff0000);
        private var color:Number;
        private var trend:Number;
        private var yCount:int;
        
        private var canvasCache:Bitmap;
        private var canvasBrush:Rectangle;
        private var canvas:Bitmap;
        private var tmpCache:Sprite;
        private var myMask:Sprite;
        private var stars:Array;
        
        public function RainbowStarPainter() {
            stage.quality = StageQuality.LOW;
            stars = new Array;
            color = Math.random();
            trend = Math.random()*0.005;
            yCount = 0;
            
            canvas = addChild(new Bitmap(new BitmapData(465, 465, true))) as Bitmap;
            tmpCache = new Sprite;
            canvasCache = tmpCache.addChild(new Bitmap(new BitmapData(465, 465, false))) as Bitmap;
            myMask = tmpCache.addChild(new Sprite) as Sprite;
            canvasCache.mask = myMask;
            canvasBrush = new Rectangle(0, 0, 30, 30);
            canvasCache.bitmapData.fillRect(canvas.bitmapData.rect, rainbow.getColor(color));
            addEventListener(Event.ENTER_FRAME, _updateScreen);
        }
        
        private function _updateScreen(e:Event):void {
            var y:int;
            color += trend;
            trend += (Math.random() * 0.001)-0.0005;
            trend = Math.max(0.001, Math.min(0.005, trend));

            if (color > 1) {
                color = 0;
            }

            for (var x:int = 0; x < 465; x += 30) {
                y = yCount - x;
                if (yCount - x > 465) {
                    y = 930 - y;
                } else if (y < 0) {
                    y = -y;
                }
                canvasBrush.x = x;
                canvasBrush.y = y;
                canvasCache.bitmapData.fillRect(canvasBrush, rainbow.getColor(color));
            }
            yCount += 5;
            yCount %= 930;
            canvasCache.bitmapData.applyFilter(canvasCache.bitmapData, canvasCache.bitmapData.rect, ZERO_POINT, BLUR_FILTER2);
            
            //update stars
            var i:int = stars.length;
            if (i<180) {
                stars.push(myMask.addChild(new Star()));
            }
            
            while (i--) {
                stars[i].x += stars[i].speedX;
                stars[i].y += stars[i].speedY;
                stars[i].rotation += stars[i].rotationSpeed;
                if (stars[i].y < -100) {
                    stars[i].resetStar();
                }
            }
            
            canvas.bitmapData.applyFilter(canvas.bitmapData, canvas.bitmapData.rect, ZERO_POINT, BLUR_FILTER);
            canvas.bitmapData.draw(canvas.bitmapData, null, DIM_COLOR, BlendMode.ADD);
            canvas.bitmapData.draw(tmpCache);
        }
    }
}

import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Matrix;
import flash.geom.Rectangle;

class Star extends Sprite {
    public var speedX:Number;
    public var speedY:Number;
    public var rotationSpeed:Number;

    public function Star() {
        graphics.beginFill(0xFF0000);
        graphics.moveTo( -90.5, -207.5);
        graphics.lineTo(29.5, -126.1);
        graphics.lineTo(171.9, -153.1);
        graphics.lineTo(131.6, -13.9);
        graphics.lineTo(201.3, 113.3);
        graphics.lineTo(56.4, 118.0);
        graphics.lineTo( -43.0, 223.5);
        graphics.lineTo( -92.3, 87.2);
        graphics.lineTo( -223.3, 25.3);
        graphics.lineTo( -108.8, -63.7);
        graphics.lineTo( -90.5, -207.5);
        graphics.endFill();

        var tmpRect:Rectangle = getRect(this);
        x = -tmpRect.left;
        y = -tmpRect.top;
        resetStar();
       
    }
    
    public function resetStar():void {
         scaleX = scaleY = Math.random() * 0.125;
        speedX = Math.random()*2 - 1;
        speedY = (-Math.random() * 4)-2;
        rotationSpeed = Math.random() * 14 - 7;
        rotationSpeed += rotationSpeed > 0?1: -1;
        y = 465;
        x = Math.random() * 465;
    }
}


import frocessing.color.ColorLerp;

import org.libspark.betweenas3.core.easing.IEasing;
import org.libspark.betweenas3.easing.Linear;

class Gradation {
    
    private var _colors:Array;
    private var _easing:IEasing;
    
    public function Gradation(...args) {
        _colors = args.concat();
        _easing = Linear.linear;
    }
    
    public function setEasing(easing:IEasing):void {
        _easing = easing;
    }
    
    public function getColor(position:Number):uint {
        position = (position < 0 ? 0 : position > 1 ? 1 : position) * (_colors.length - 1);
        var idx:int = position;
        var alpha:Number = _easing.calculate(position - idx, 0, 1, 1);
        if (alpha == 0) {
            return _colors[idx];
        } else {
            return ColorLerp.lerp(_colors[idx], _colors[idx + 1], alpha);
        }
    }
}