Perfect Shuffle Visualization

by nitoyon
------------------------------------------------------
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
♥15 | Line 39 | Modified 2010-01-09 01:43:27 | MIT License
play

ActionScript3 source code

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

//------------------------------------------------------
// 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 frocessing.color.ColorHSV;

[SWF(width="475",height="475",backgroundColor="0x000000")]
public class PerfectShuffle extends Sprite {
    private const SIZE:int = 30;
    private const W:int = 80;
    private const H:int = 10;
    
    public function PerfectShuffle() {
        stage.scaleMode = "noScale";

        graphics.beginFill(0x000000);
        graphics.drawRect(0, 0, 475, 475);
        graphics.endFill();
        
        var num:int;
        var s:Sprite = new Sprite();
        s.x = 40;
        s.y = 100;
        addChild(s);
        for (var i:int = 0; i < SIZE; i++) {
            num = i;

            s.graphics.lineStyle(4, new ColorHSV(i * 270 / SIZE, .7).value, .7);
            s.graphics.moveTo(0, num * H);
            for (var j:int = 0; j < 5; j++) {
                num = getNext(num);
                s.graphics.lineTo(j * W + W, num * H);
            }
        }

        s.filters = [new BlurFilter(2, 2)];
    }

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

Forked