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: Perfect Shuffle Visualization

------------------------------------------------------
Perfect Shuffle Visualization
------------------------------------------------------
How many times does it requires for 15 cards to 
go back to where one started?
inspired by:
http://d.hatena.ne.jp/nishiohirokazu/20100107/1262835414
/**
 * Copyright sugyan ( http://wonderfl.net/user/sugyan )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jdUr
 */

// forked from nitoyon's Perfect Shuffle Visualization
//------------------------------------------------------
// Perfect Shuffle Visualization
//------------------------------------------------------
// How many times does it requires for 15 cards to 
// go back to where one started?
//
// inspired by:
// http://d.hatena.ne.jp/nishiohirokazu/20100107/1262835414

package {
    import flash.display.Sprite;
    import flash.filters.BlurFilter;
    import flash.events.Event;

    [SWF(width="465",height="465",backgroundColor="0x000000")]
    public class PerfectShuffle extends Sprite {
        private var lines:Array = new Array();

        public function PerfectShuffle() {
            stage.scaleMode = "noScale";
            graphics.beginFill(0x000000);
            graphics.drawRect(0, 0, 465, 465);
            graphics.endFill();

            for (var i:int = 0; i < NUM; i++) {
                lines[i] = new Line(i);
                lines[i].y = 5;
                lines[i].filters = [new BlurFilter(2, 2)];
                addChild(lines[i]);
            }

            stage.addEventListener(Event.ENTER_FRAME, function ():void {
                    for (var i:int = 0; i < NUM; i++) {
                        lines[i].move();
                    }
                }
            );
        }
    }
}


const NUM:int = 30;
const WIDTH:Number = 465;

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

class Line extends Sprite {
    private const H:Number = WIDTH / NUM;
    private var lines:Array = new Array();
    private var color:uint;
    private var index:int;

    public function Line(n:int) {
        index = n;
        color = new ColorHSV(index * 270.0 / NUM, .7).value;
        for (var i:int = 0; i < 2; i++) {
            lines[i] = new Sprite();
            lines[i].graphics.lineStyle(4, color, .7);
            lines[i].x = WIDTH * i;

            addChild(lines[i]);
        }

        lines[0].graphics.moveTo(0.0, index * H);
        lines[0].graphics.lineTo(WIDTH, getNext(index) * H);

        index = getNext(index);
        lines[1].graphics.moveTo(0.0, index * H);
        lines[1].graphics.lineTo(WIDTH, getNext(index) * H);
    }

    public function move():void {
        x -= 10;

        var leftLine:Sprite = lines[0];
        if (leftLine.localToGlobal(new Point()).x < -WIDTH) {
            removeChild(lines[0]);
            lines.shift();
            lines.push(new Sprite());

            index = getNext(index);
            lines[1].graphics.lineStyle(4, color, .7);
            lines[1].graphics.moveTo(0.0, index * H);
            lines[1].graphics.lineTo(WIDTH, getNext(index) * H);
            lines[1].x = lines[0].x + WIDTH;

            addChild(lines[1]);
        }
    }

    private function getNext(num:int):int {
        if (num < NUM / 2) {
            return num * 2 + 1;
        } else {
            return (num - NUM / 2) * 2;
        }
    }
}