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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                
              
            
!

CSS

              
                html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--color-dark);
}
body {
    display: grid;
    place-items: center;
    background-image: radial-gradient(circle farthest-side, rgba(255, 255, 255, .15), rgba(255, 255, 255, 0));
}
*, *:before, *:after { box-sizing: content-box; }

main {
    display: block;
    overflow: hidden;
    box-shadow: 0 0 0 10px var(--color-light), 0 10px 5px 5px rgba(0, 0, 0, .35), 0 0 80px -10px rgba(0, 0, 0, .25);
    position: relative;
}

.grid {
    background: var(--color-light);
    overflow: hidden;
    display: grid;
    grid-column-gap: 0;
    grid-row-gap: 0;
    position: absolute;
    top: 0;
    left: 0;

    > .box { position: relative; }
}

.token, .auxToken {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
}

.tokenDark {    background: var(--color-dark); }
.tokenLight {   background: var(--color-light); }

.tokenTop {     animation: var(--animation-duration) top forwards var(--animation-function); }
.tokenBottom {  animation: var(--animation-duration) bottom forwards var(--animation-function); }
.tokenLeft {    animation: var(--animation-duration) left forwards var(--animation-function); }
.tokenRight {   animation: var(--animation-duration) right forwards var(--animation-function); }

.tokenKeyframes( @name, @top, @left ) {
    @keyframes @name {

        0%, 25% {
            border-radius: 0;
            top: 0;
            left: 0;
            transform: scale(1);
        }
        50% {
            border-radius: var(--max-border-radius);
            top: 0;
            left: 0;
            transform: scale(var(--scale-down));
        }
        75% {
            border-radius: var(--max-border-radius);
            top: @top;
            left: @left;
            transform: scale(var(--scale-down));
        }
        100% {
            border-radius: 0;
            top: @top;
            left: @left;
            transform: scale(1);
        }
    }
}
.tokenKeyframes(top, -100%, 0);
.tokenKeyframes(bottom, 100%, 0);
.tokenKeyframes(left, 0, -100%);
.tokenKeyframes(right, 0, 100%);


.auxToken {
    opacity: 0;
    animation: var(--animation-duration) aux forwards var(--animation-function);
    border-radius: var(--max-border-radius);
}
@keyframes aux {
    0%, 25% {
        opacity: 0;
        border-radius: var(--max-border-radius);
        transform: scale(var(--scale-down));
    }
    50% {
        opacity: 0;
        border-radius: var(--max-border-radius);
    }
    75% {
        opacity: .15;
        border-radius: var(--max-border-radius);
        transform: scale(var(--scale-down));
    }
    100% {
        opacity: 1;
        border-radius: 0;
        transform: scale(1);
    }
}
              
            
!

JS

              
                const app = (function() {

    let config = {
        bgColor     : '#eee',
        fgColor     : '#333',
        size        : 48,
        columns     : 16,
        rows        : 9,
        animRepetitions     : 40,
        animDuration        : 1300,
        animFunction        : 'cubic-bezier(0.6, 0, 0.4, 1)',
        animBoxRadius       : '25%',
        animScaleDown       : .82,
        counter     : 0,
    };
    config.width = config.size * config.columns;
    config.height = config.size * config.rows;
    config.directions = ['Left', 'Right', 'Top', 'Bottom'];
    return config;

})();

const fn = {
    rdm : function(from, to) { // Random Inclusive
        return Math.floor((Math.random()*((to+1)-from)) + from);
    }
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

const sketch = (function() {

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Container
    let _sketch = document.createElement('main');
        _sketch.style.width = `${app.width}px`;
        _sketch.style.height = `${app.height}px`;

    document.body.appendChild(_sketch);
    return _sketch;

})();

const board = function(positive) {

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Generate grid
    let _grid = document.createElement('div');
        _grid.classList.add('grid');
        _grid.style.width = `${app.width}px`;
        _grid.style.height = `${app.height}px`;
        _grid.style.gridTemplateColumns = `repeat(${app.columns}, 1fr)`;
        _grid.style.gridTemplateRows = `repeat(${app.rows}, 1fr)`;
        _grid.style.backgroundColor = (positive) ? app.bgColor : app.fgColor;

        sketch.appendChild(_grid);

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Generate board
    let i = 0;
    for (let h=0; h<app.rows; h++ ) {
        for(let v=0; v<app.columns; v++) {

            let _box = document.createElement('div');
                _box.classList.add('box');

            _grid.appendChild(_box);

            if (i%2) {

                let _tokenDirection = `token${app.directions[fn.rdm(0,3)]}`;
                let _token = document.createElement('div');
                    _token.classList.add( 'token' );
                    _token.classList.add( (positive) ? 'tokenDark' : 'tokenLight' );
                    _token.classList.add( _tokenDirection );

                _box.appendChild(_token);

            } else {

                let _auxToken = document.createElement('div')
                    _auxToken.classList.add( 'auxToken' );
                    _auxToken.classList.add( (positive) ? 'tokenDark' : 'tokenLight' );

                _box.appendChild(_auxToken);
            }
            i++;
        }

        if ( app.columns%2 == 0 ) { i++; }
    }

    // ~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Remove current board and iterate
    if ( app.counter < app.animRepetitions ) {

        window.setTimeout(() => {

            while (sketch.firstChild) { sketch.removeChild(sketch.lastChild) }
            board(!positive);
            app.counter++;

        }, app.animDuration);
    }

}

const init = (function() {

    document.documentElement.style.setProperty('--color-light', app.bgColor);
    document.documentElement.style.setProperty('--color-dark', app.fgColor);
    document.documentElement.style.setProperty('--animation-duration', `${(app.animDuration/1000).toFixed(1)}s` );
    document.documentElement.style.setProperty('--animation-function', app.animFunction );
    document.documentElement.style.setProperty('--max-border-radius', app.animBoxRadius );
    document.documentElement.style.setProperty('--scale-down', app.animScaleDown );
    board(false);

})();
              
            
!
999px

Console