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: Wavelet

[AS3.0] Waveletクラスに挑戦! (1)
http://www.project-nya.jp/modules/weblog/details.php?blog_id=1138
Get Adobe Flash player
by nsos 13 Feb 2012
/**
 * Copyright nsos ( http://wonderfl.net/user/nsos )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mcv5
 */

// forked from ProjectNya's Wavelet
////////////////////////////////////////////////////////////////////////////////
// [AS3.0] Waveletクラスに挑戦! (1)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1138
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.geom.Rectangle;
    import frocessing.color.ColorHSV;

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

    public class Main extends Sprite {
        private var wavelet:Wavelet;

        public function Main() {
            Wonderfl.capture_delay(1);
            init();
        }

        private function init():void {
            var rect:Rectangle = new Rectangle(0, 0, 465, 465);
            wavelet = new Wavelet(rect);
            addChild(wavelet);
            var color:ColorHSV = new ColorHSV();
            color.hsv(10, 0.3, 0.9);
            var color1:uint = color.value;
            color.hsv(220, 0.7, 1);
            var color2:uint = color.value;
            wavelet.color(color1, color2);
        }

    }

}


import flash.display.Sprite;
import flash.display.Shape;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Matrix;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.InterpolationMethod;
import flash.filters.BlurFilter;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.display.BlendMode;
import flash.filters.ColorMatrixFilter;
//import com.quasimondo.geom.ColorMatrix;

class Wavelet extends Sprite {
    private var rect:Rectangle;
    private var wavelet:BitmapData;
    private var noise:BitmapData;
    private var overlay:Shape;
    private static var scale:Number = 1.2;
    private var color1:uint;
    private var color2:uint;

    public function Wavelet(r:Rectangle) {
        rect = r;
    }

    public function color(c1:uint, c2:uint):void {
        color1 = c1;
        color2 = c2;
        draw();
    }
    private function draw():void {
        wavelet = new BitmapData(rect.width, rect.height, false);
        noise = new BitmapData(rect.width/scale, rect.height/scale, false);
        noise.noise(20, 0, 255, 7,true);
        var blur:BlurFilter = new BlurFilter(40, 2, 100);
        noise.applyFilter(noise, noise.rect, new Point(), blur);
        var matrix:Matrix = new Matrix();
        matrix.scale(scale, scale);
        var colorMatrixFilter:ColorMatrixFilter = new ColorMatrixFilter();
        //var colorMatrix:ColorMatrix = new ColorMatrix();
        //colorMatrix.adjustContrast(0.6);
        //colorMatrixFilter.matrix = colorMatrix.matrix;
        colorMatrixFilter.matrix = adjustContrast(0.6);
        noise.applyFilter(noise, noise.rect, new Point(), colorMatrixFilter);
        wavelet.draw(noise, matrix, null, BlendMode.DIFFERENCE);
        drawOverlay();
        addChild(new Bitmap(wavelet));
    }
    private function adjustContrast(s:Number):Array {
        var r:Number;
        var g:Number;
        var b:Number;
        r = g = b = s + 1;
        return [r, 0, 0, 0, (128 * (1 - r)), 0, g, 0, 0, (128 * (1 - g)), 0, 0, b, 0, (128 * (1 - b)), 0, 0, 0, 1, 0];
    }
    private function drawOverlay():void {
        overlay = new Shape();
        var colors:Array = [color1, color2]
        var alphas:Array = [1, 1];
        var ratios:Array = [0, 255];
        var matrix:Matrix = new Matrix();
        matrix.createGradientBox(rect.width, rect.height, 0.8*Math.PI, 0, 0);
        overlay.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix, SpreadMethod.REFLECT, InterpolationMethod.RGB, 0);
        overlay.graphics.drawRect(0, 0, rect.width, rect.height);
        overlay.graphics.endFill();
        wavelet.draw(overlay, null, null, BlendMode.HARDLIGHT);
        wavelet.draw(overlay, null, null, BlendMode.OVERLAY);
    }

}