Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <background>     
        <wheel>
            <controls>
                <game-title-A>Simon &reg;</game-title-A>
                <game-title-B>Simon &reg;</game-title-B>

                <game-start>Start</game-start>
                <screen></screen>
                <hard-mode>
                    <hard-button></hard-button>
                    <hard-text>easy mode</hard-text>
                </hard-mode>
            </controls>

            <circle class="top-left"></circle>
            <circle class="top-right"></circle>
            <circle class="bottom-left"></circle>
            <circle class="bottom-right"></circle>

            <wheel-shadow></wheel-shadow>
        </wheel>

        <switch>3D</switch>

    </background>
              
            
!

CSS

              
                html body {
    width: 100%;
    min-height: 100%;
    top: 0;
    left: 0;

    margin: 0;
    padding: 0;

    position: absolute;
    user-select: none;
    -webkit-user-select: none;

    font-size: 30px;
    font-family: fantasy;
    font-weight: 200;

    color: black;
}

background {
    display: block;
    position: absolute;
    top: 0;
    left: 0; 
    width: 100%; 
    min-height: 100%;

    box-sizing: border-box;
    text-align: center;


    background: -moz-radial-gradient(center, ellipse cover, rgba(0,0,125,1) 0%, rgba(0,0,0,1) 100%); /* ff3.6+ */
    background: -webkit-gradient(radial, center center, 0px, center center, 100%, color-stop(0%, rgba(0,0,125,1)), color-stop(100%, rgba(0,0,0,1))); /* safari4+,chrome */
    background:-webkit-radial-gradient(center, ellipse cover, rgba(0,0,125,1) 0%, rgba(0,0,0,1) 100%); /* safari5.1+,chrome10+ */
    background: -o-radial-gradient(center, ellipse cover, rgba(0,0,125,1) 0%, rgba(0,0,0,1) 100%); /* opera 11.10+ */
    background: -ms-radial-gradient(center, ellipse cover, rgba(0,0,125,1) 0%, rgba(0,0,0,1) 100%); /* ie10+ */
    background:radial-gradient(ellipse at center, rgba(0,0,125,1) 0%, rgba(0,0,0,1) 100%); /* w3c */
}


wheel {
    display: block;
    width: 500px;
    height: 500px;

    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;

    border-radius: 250px;

    background-color: rgb(50,50,50);
    z-index: 1;
}

wheel-shadow {
    display: block;
    width: 500px;
    height: 500px;

    position: absolute;
    top: 45px;
    right: 7px;
    margin: auto;

    border-radius: 250px;
    /*box-shadow: 0 0 100px 50px rgba(0,0,0,0.75);*/
    z-index: 0;
}

controls {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;

    width: 250px;
    height: 250px;
    border-radius: 125px;

    border: 10px solid rgb(50,50,50);
    box-sizing: border-box;

    background-color: white;
    z-index: 3;
}

game-title-A, game-title-B {
    display: block;
    position: absolute;
    top: 0;
    bottom: 0;
    margin: auto;

    height: 60px;
    font-size: 30px;
    line-height: 60px;

    cursor: default;
}

game-title-A {
    -webkit-transform: rotateZ(-90deg);
    left: -20px;
}

game-title-B {
    -webkit-transform: rotateZ(90deg);
    right: -20px;
}


game-start {
    display: block;
    width: 100px;
    height: 50px;

    position: absolute;
    top: 20px;
    left: 0;
    right: 0;
    text-align: center;
    

    margin: auto;
    line-height: 50px;

    border-radius: 10px;
    cursor: pointer;

    background-color: rgb(255, 50, 50);

}

game-start:hover {
    color: white
}

game-start:active {
    transform: scale(1,0.9);
    top: 24px;
}

screen {
    display: block;
    width: 50px;
    height: 30px;

    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    margin: auto;

    font-size: 20px;
    line-height: 40px;

    color: white;
    background: rgb(20,20,20);
    border-radius: 5px;

    border: 5px solid rgb(50,50,50);

    cursor: default;
}

screen.hard {
    color: red;
}

hard-mode {
    display: block;
    width: 80px;
    height: 60px;

    position: absolute;
    left: 0;
    right: 0;
    bottom: 10px;
    margin: auto;

    text-align: center
}

hard-button {
    display: block;

    width: 30px;
    height: 30px;
    margin: auto;

    border-radius: 15px;
    border: 5px solid rgb(50,50,50);
    box-sizing: border-box;
    background: lightgreen;

    cursor: pointer;
}

hard-button:hover {
    background: green;
}

hard-button.active {
    background: red;
}

hard-button.active:hover {
    background: darkred;
}

hard-button:active {
    transform: scale(1,0.95);
    margin-top: 1.5px;
}

hard-text {
    display: block;
    position: absolute;
    bottom: -10px;
    left: 0;
    right: 0;
    margin: auto;

    height: 40px;
    font-size: 12px;
    line-height: 40px;

    cursor: default;
}


circle {
    display: block;
    width: 250px;
    height: 250px;

    position: absolute;
    margin: auto;

    cursor: pointer;

    border: 10px solid rgb(50,50,50);

    box-sizing: border-box;
    z-index: 2;
}

circle.top-left {
    top: 0;
    left: 0;
    border-radius: 250px 0 0 0;
    background: rgba(228, 214, 190, 1)
}

circle.top-right {
    top: 0;
    right: 0;
    border-radius: 0 250px 0 0;
    background: rgba(174, 156, 222, 1)
}

circle.bottom-left {
    bottom: 0;
    left: 0;
    border-radius: 0 0 0 250px;
    background: rgba(180, 211, 187, 1)
}

circle.bottom-right {
    bottom: 0;
    right: 0;
    border-radius: 0 0 250px 0;
    background: rgba(208, 155, 182, 1)
}

circle.top-left:hover {
    background: rgba(169, 146, 107, 1)
}

circle.top-right:hover {
    background: rgba(81, 80, 144, 1)
}

circle.bottom-left:hover {
    background: rgba(61, 136, 78, 1)
}

circle.bottom-right:hover {
    background: rgba(128, 59, 59, 1)
}

circle.top-left:active, circle.top-left.light {
    background: rgba(255, 235, 0, 1)
}

circle.top-right:active, circle.top-right.light {
    background: rgba(36, 43, 255, 1)
}

circle.bottom-left:active, circle.bottom-left.light {
    background: rgba(25, 253, 77, 1)
}

circle.bottom-right:active, circle.bottom-right.light {
    background: rgba(245, 34, 43, 1)
}


switch {
    display: block;
    position: absolute;
    top: 20px;
    left: 20px;

    color: wheat;
    font-size: 30px;

    cursor: pointer;
}

switch:hover {
    transform: scale(1.1,1.1);
    color: white;
}

switch:active {
    transform: scale(0.95, 0.95);
}


              
            
!

JS

              
                /********* RENDERING LOGIC **********/
var render3D = true;

var _3dPrinter = {
    MAX_DEPTH: 30,
    ROTATE_CONSTANT: 0.25,
    ROTATE_X: 45,
    ROTATE_Z: -10,
}

_3dPrinter.print = function($element, color, shadowHeight, rotateDeg, inset, opt_extraRotate) {
    shadowHeight = shadowHeight || 0;
    rotateDeg = rotateDeg || 0;
    inset = inset ? 'inset' : '';

    var base = color;
    var shadow = inset + ' 0 0 0 0 black';
    for(var i = 0; i < _3dPrinter.MAX_DEPTH; i++) {
        var step = i / _3dPrinter.MAX_DEPTH;

        var posHeight = step * shadowHeight;
        var posRotate = step * rotateDeg * _3dPrinter.ROTATE_CONSTANT;
        shadow += ', ' + inset + ' ' + posRotate + 'px ' + posHeight + 'px 0px 0px ' + base.decrement().getCss();
    
        if(opt_extraRotate) {
            posRotate = step * opt_extraRotate * _3dPrinter.ROTATE_CONSTANT;
            shadow += ', ' + inset + ' ' + posRotate + 'px ' + posHeight + 'px 0px 0px ' + base.getCss();
        }
    }

    $element.css('box-shadow', shadow);
}

_3dPrinter.apply3d = function() {
    var rotation = 'rotateX(' + _3dPrinter.ROTATE_X + 'deg) rotateZ(' + _3dPrinter.ROTATE_Z + 'deg)';

    $('wheel').css('transform', rotation);
    $('wheel').css('-webkit-transform', rotation);
    $('wheel').css('-mz-transform', rotation);

    $('wheel-shadow').css('box-shadow', '0 0 100px 50px rgba(0,0,0,0.75)');

    _3dPrinter.print($('wheel'), new Rgb(50, 50, 50), 50, _3dPrinter.ROTATE_Z * 3);
    _3dPrinter.print($('game-start'), new Rgb(255, 50, 50), 10, _3dPrinter.ROTATE_Z);
    _3dPrinter.print($('controls'), new Rgb(50, 50, 50), 10, _3dPrinter.ROTATE_Z);
    _3dPrinter.print($('screen'), new Rgb(50, 50, 50), 7.5, _3dPrinter.ROTATE_Z, true);
    _3dPrinter.print($('hard-button'), new Rgb(50, 50, 50), 5, _3dPrinter.ROTATE_Z / 2);

    _3dPrinter.print($('circle.top-left'), new Rgb(50, 50, 50), 15, -1 * _3dPrinter.ROTATE_Z, true, _3dPrinter.ROTATE_Z * 3);
    _3dPrinter.print($('circle.top-right'), new Rgb(50, 50, 50), 15, _3dPrinter.ROTATE_Z * 3, true);
    _3dPrinter.print($('circle.bottom-left'), new Rgb(50, 50, 50), 15, _3dPrinter.ROTATE_Z * 3, true);
    _3dPrinter.print($('circle.bottom-right'), new Rgb(50, 50, 50), 15, _3dPrinter.ROTATE_Z * 3, true);
};

_3dPrinter.remove3d = function() {
    $('wheel').css('transform', '');
    $('wheel').css('-webkit-transform', '');
    $('wheel').css('-mz-transform', '');

    $('wheel-shadow').css('box-shadow', '');

    $('wheel').css('box-shadow', '');
    $('game-start').css('box-shadow', '');
    $('controls').css('box-shadow', '');
    $('screen').css('box-shadow', '');
    $('hard-button').css('box-shadow', '');

    $('circle.top-left').css('box-shadow', '');
    $('circle.top-right').css('box-shadow', '');
    $('circle.bottom-left').css('box-shadow', '');
    $('circle.bottom-right').css('box-shadow', '');
}

var Rgb = function(r,g,b) {
    this.r = r;
    this.g = g;
    this.b = b;

    this.rx = r / _3dPrinter.MAX_DEPTH;
    this.gx = g / _3dPrinter.MAX_DEPTH;
    this.bx = b / _3dPrinter.MAX_DEPTH;
}

Rgb.prototype.getCss = function() {
    return 'rgb(' + parseInt(this.r, 10) + ',' + parseInt(this.g, 10) + ',' + parseInt(this.b, 10) + ')';
}

Rgb.prototype.decrement = function() {
    this.r -= this.rx;
    this.g -= this.gx;
    this.b -= this.bx;

    return this;
};


/********* GAME LOGIC **********/

/**** Initialization ****/
var AudioCtx = window.AudioContext || window.webkitAudioContext;
var audioCtx = new AudioCtx();

var createAudioObject = function(hz) {
    return {
        play: function() {
            var osc = audioCtx.createOscillator();
            osc.type = 'sine';
            osc.frequency.value = hz; 
            osc.connect(audioCtx.destination);
            osc.start(0);
            setTimeout(function() {
                osc.stop();
                osc.disconnect();
                delete osc;
            }, 250);
        }
    };
};

var Sounds = {
    'top-left': createAudioObject(288.33),
    'top-right': createAudioObject(342.88),
    'bottom-left': createAudioObject(457.69),
    'bottom-right': createAudioObject(432.00)
};

var Game = function(){
    this.hardmode = false;
    this.hardmodeRatio = 0.66;
    this.waitFactor = 3;
    this.maxSpeed = 300;
    this.startSpeed = 1000;
    this.maxStep = 20;

    this.sequence = Array.apply(null, Array(5)).map(function(){
        return 'top-left'
    })
    .concat(Array.apply(null, Array(5)).map(function(){
        return 'top-right'
    }))
    .concat(Array.apply(null, Array(5)).map(function(){
        return 'bottom-left'
    }))
    .concat(Array.apply(null, Array(5)).map(function(){
        return 'bottom-right'
    }));
};

Game.prototype.start = function() {
    $('game-start').html('Stop');
    this.reset();
    this.takeStep();
}

Game.prototype.stop = function() {
    clearInterval(this.player);
    clearInterval(this.timeoutRejector);
    this.player == undefined;
    this.timeoutRejector == undefined;
    $('screen').html('');
    $('game-start').html('Start');
}


Game.prototype.reset = function() {
    this.sequence.sort(function(){ return Math.random() - 0.5;});
    this.step = 1;
    this.actualSpeed = this.startSpeed;
    this.ended = false;
};


Game.prototype.toggleMode = function() {
    this.hardmode = !this.hardmode;
}

Game.prototype.currentSpeed = function() {
    var ratio = this.hardmode ? this.hardmodeRatio : 1;
    return this.actualSpeed * ratio;
}

Game.prototype.takeStep = function() {
    var that = this;
    var playedAll = new Promise(function(resolve, reject){ that.played = resolve});

    var i = 0;
    this.player = setInterval(function(){
        if(i >= that.step) {
            that.played();
            clearInterval(that.player);
        } else {
            var $circle = $('circle.' + that.sequence[i++]);
            $circle.addClass('light');
            $circle.click();

            setTimeout(function(){
                $circle.removeClass('light')
            }, that.currentSpeed() / 2);
        }
        $('screen').html(that.step);
    }, this.currentSpeed());


    playedAll
        .then(function() {
            return new Promise(function(resolve, reject) {
                var hasResolved = false;

                that.timeoutRejector = setTimeout(function() {
                    !hasResolved && reject('Late');
                    hasResolved = true;       
                }, that.currentSpeed() * that.step * that.waitFactor);

                var playerSteps = 0;
                var clickHandler = function() {
                    var $circle = $(this);
                    var pressed = $circle.attr('class').split(' ')[0];

                    if (pressed == that.sequence[playerSteps]) {
                        playerSteps++;
                        if(playerSteps == that.step) {
                            hasResolved = true;
                            $('circle').unbind('click', clickHandler);
                            setTimeout(resolve, 1000);
                        } 
                    } else {
                        hasResolved = true;    
                        $('circle').unbind('click', clickHandler);
                        reject('Inv');
                    }
                }

                $('circle').bind('click', clickHandler);
            });
        })
        .then(function() {
            that.step++;

            if(that.step >= that.maxStep) {
                that.ended = true;

                Sounds['top-left'].play();
                Sounds['bottom-left'].play();
                Sounds['top-right'].play();

                setTimeout(function() {
                    Sounds['top-left'].play();
                    Sounds['bottom-left'].play();
                    Sounds['top-right'].play();
                }, 300);

                setTimeout(function() {
                    Sounds['top-left'].play();
                    Sounds['bottom-left'].play();
                    Sounds['top-right'].play();
                }, 600);

                $('screen').html('Win');
                setTimeout(that.stop.bind(that), 2000);
            } else {
                that.actualSpeed = that.maxSpeed + (that.startSpeed - that.maxSpeed) * (that.maxStep - that.step + 1) / that.maxStep;
                that.takeStep();
            }
        })
        .catch(function(reason) {
            $('screen').html(reason);

            Sounds['top-left'].play();
            Sounds['bottom-right'].play();
            setTimeout(function() {
                Sounds['top-left'].play();
                Sounds['bottom-right'].play();
            }, 300);

            if(that.hardmode) {
                that.ended = true;
                $('screen').html('End');
                setTimeout(that.stop.bind(that), 2000);
            } else {
                setTimeout(that.takeStep.bind(that), 1000);
            }
        });
};


$(function(){
    var game = new Game();

    render3D && _3dPrinter.apply3d();

    $('switch').click(function() {
        render3D = !render3D;
        if(render3D) {
            _3dPrinter.apply3d();
            $(this).html('3D');
        }
        else {
            _3dPrinter.remove3d();
            $(this).html('2D');
        }
    });
    
    $('hard-button').click(function(){
        game.toggleMode();
        if(game.hardmode) {
            $('screen').addClass('hard');
            $(this).addClass('active');
            $('hard-text').html('Hardcore');
        } else {
            $('screen').removeClass('hard');
            $(this).removeClass('active');
            $('hard-text').html('easy mode');
        }
    });

    $('circle').click(function(){
        Sounds[$(this).attr('class').split(' ')[0]].play();
    });

    $('circle.top-left').mousedown(function(){
        var $element = $(this);
        render3D && _3dPrinter.print($element, new Rgb(50, 50, 50), 25, -1 * _3dPrinter.ROTATE_Z * 3, true, _3dPrinter.ROTATE_Z * 4);  
        $('body').mouseup(function(){
            render3D && _3dPrinter.print($element, new Rgb(50, 50, 50), 15, -1 * _3dPrinter.ROTATE_Z, true, _3dPrinter.ROTATE_Z * 3);  
            $('body').unbind('mouseup');
        });
    });

    $('circle.top-right, circle.bottom-left, circle.bottom-right').mousedown(function(){
        var $element = $(this);
        render3D && _3dPrinter.print($element, new Rgb(50, 50, 50), 25, _3dPrinter.ROTATE_Z * 5, true);
        $('body').mouseup(function(){
            render3D && _3dPrinter.print($element, new Rgb(50, 50, 50), 15, _3dPrinter.ROTATE_Z * 3, true);
            $('body').unbind('mouseup');
        });
    });

    $('game-start').click(function(){
        if($(this).html() == 'Start') game.start();
        else game.stop();
    });
});
              
            
!
999px

Console