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: Saqoosha challenge for amateurs (見える化 Between)

簡単な解説。http://aquioux.blog48.fc2.com/blog-entry-634.html
/**
 * Copyright Aquioux ( http://wonderfl.net/user/Aquioux )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/31IX
 */

// forked from checkmate's Saqoosha challenge for amateurs
// 簡単な解説。http://aquioux.blog48.fc2.com/blog-entry-634.html
package {
    
    import com.bit101.components.ColorChooser;
    import com.bit101.components.Label;
    import com.bit101.components.RadioButton;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.text.TextField;
    import flash.utils.getDefinitionByName;
    import org.libspark.betweenas3.core.easing.IEasing;
    import org.libspark.betweenas3.easing.*;
    
    [SWF(width=465, height=465, backgroundColor=0xffffff, frameRate=120)]

    public class GradationTest1 extends Sprite {
        
		private const easingVector:Vector.<IEasing> = Vector.<IEasing>([
			Linear.easeIn,
			Back.easeIn,
			Bounce.easeIn,
			Circ.easeIn,
			Cubic.easeIn,
			Elastic.easeIn,
			Expo.easeIn,
			Quad.easeIn,
			Quart.easeIn,
			Quint.easeIn,
			Sine.easeIn
		]);

        private const SEGMENT:uint    = 5;            // 画面分割数
        private const BASE_WIDTH:uint = 465 / SEGMENT;// 画面分割数に応じた幅サイズ
        private const COLOR_HEIGHT:uint = 400;        // グラデーション表示部の高さ
        
        private const labelVector:Vector.<String> = Vector.<String>([
            "Linear",
            "Sine",
            "Quad",
            "Cubic",
            "Quart",
            "Quint",
            "Expo",
            "Circ",
            "Elastic",
            "Back",
            "Bounce"
        ]);
        private const behaviourVector:Vector.<String> = Vector.<String>([
            "Linear.linear",
            "easeIn",
            "easeOut",
            "easeInOut",
            "easeOutIn"
        ]);
        
        private var colorVector:Vector.<uint> = Vector.<uint>([0xFF0000, 0x0000FF]);
        private var gradationLayer:Shape = new Shape();
        
        private var grad:Gradation;

        public function GradationTest1() {
            Wonderfl.capture_delay(15);
            createLayers();
            drawGradation();
        }
        
        private function createLayers():void{
            addChild(gradationLayer);
            addChild(createCompLayer());
            gradationLayer.y = stage.stageHeight - COLOR_HEIGHT;
        }
        
        private function drawGradation(path:String = "org.libspark.betweenas3.easing.Linear"):void {
            //trace(path);
            grad = new Gradation(colorVector[0], colorVector[1]);

            gradationLayer.graphics.clear();
            var n:uint = SEGMENT;
            var ClassReference:Class = getDefinitionByName(path) as Class;
            for (var i:uint = 0; i < n; i++) {
                if (i == 0) {
                    grad.setEasing(Linear.linear);
                } else {
                    grad.setEasing(ClassReference[behaviourVector[i]]);
                }
                for (var y:uint = 0; y < COLOR_HEIGHT; y++) {
                    gradationLayer.graphics.beginFill(grad.getColor(y / (COLOR_HEIGHT - 1)));
                    gradationLayer.graphics.drawRect(BASE_WIDTH*i, y, BASE_WIDTH*(i+1), 1);
                    gradationLayer.graphics.endFill();
                }
            }
        }
        
        private function createCompLayer():Sprite {
            var layer:Sprite = new Sprite();
            
            // other components
            n = Math.ceil(labelVector.length / 2);
            var cnt:uint = 0;
            var check:Boolean = true;
            for (i = 0; i < 2; i++) {
                n -= i;
                for (var j:int = 0; j < n; j++) {
                    if (cnt != 0)
                        check = false;
                    var radiobutton:RadioButton = 
                        new RadioButton(layer, 65 * j + 5, 15 * i + 5, labelVector[cnt++], check, radiobuttonChangeHandler);
                }
            }
            var colorChooser1:ColorChooser = new ColorChooser(layer, 395,  5, colorVector[0], colorChangeHandler1);
            var colorChooser2:ColorChooser = new ColorChooser(layer, 395, 25, colorVector[1], colorChangeHandler2);

            // label 
            var n:uint = SEGMENT;
            for (var i:uint=0; i<n; i++){
                var label:Label = new Label(layer, BASE_WIDTH * i + 5, 50, behaviourVector[i]);
            }
            return layer;
        }
        
        
        // ChangeHandler
        // RadioButton
        private function radiobuttonChangeHandler(event:Event):void {
            const basePath:String = "org.libspark.betweenas3.easing.";
            var radiobutton:RadioButton = RadioButton(event.currentTarget);
            var classname:String = radiobutton.label;
            var path:String = basePath + classname;
            drawGradation(path);
        }
        // ColorChooser
        private function colorChangeHandler1(event:Event):void {
            var colorCooser:ColorChooser = ColorChooser(event.currentTarget);
            colorVector[0] = colorCooser.value;
            drawGradation();
        }
        private function colorChangeHandler2(event:Event):void {
            var colorCooser:ColorChooser = ColorChooser(event.currentTarget);
            colorVector[1] = colorCooser.value;
            drawGradation();
        }
    }
}


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);
        }
    }
}