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

              
                <div id="app">
    <part v-for="part in parts" v-bind:val="part"></part>
</div>
<div></div>
<img id="im" src="https://upload.wikimedia.org/wikipedia/commons/3/31/Autumn_scenery.jpg" crossorigin='anonymous'/>
              
            
!

CSS

              
                xDivs = 10
yDivs = 8
html, body
    height: 100%
    margin: 0
    background-color: black
#app
    height: 100%
    overflow: auto
    flex-wrap: wrap
    overflow: hidden
img
    display: none
.part
    float: left
    box-sizing: border-box
    width: percentage(1 / xDivs)
    height: percentage(1 / yDivs)
    background-size: 100% 100%
    background-position: center
    background-repeat: no-repeat
    transition: transform .6s, border-width .2s  
    border: 1px solid white

body:active
    .part
        border-width: 0
        transform: scale(1)
        transition-delay: 0s


random(min,max)
  return floor(math(0, 'random')*(max - min + 1) + min)

for i in 1..(yDivs * xDivs)
    .part:nth-child({i})
        transform: skewY((random(-10, 10))deg) skewX((random(-10, 10))deg) scale(.9)
              
            
!

JS

              
                let parts = [];
let image = document.getElementById('im');
if(image.complete && image.naturalWidth !== 0){
    console.log('already loaded');
    go();
} else{
    console.log('waiting for load');
    image.onload = go;
    
}

function go(){
    parts = [];
    const xDivs = 10;
    const yDivs = 8;
    let dx = image.naturalWidth / xDivs;
    let dy = image.naturalHeight / yDivs;
    let ctx = document.createElement('canvas').getContext('2d');
    ctx.canvas.width = dx;
    ctx.canvas.height = dy;
    for(let y=0; y<yDivs; y++){
        for(let x=0; x<xDivs; x++){
            ctx.clearRect(0, 0, dx, dy);
            ctx.drawImage(image, x*dx, y*dy, dx, dy, 0, 0, dx, dy);
            parts.push(ctx.canvas.toDataURL("image/png"));
        }
    }
    console.log(parts.length);

    Vue.component('part', {
        props: ['val'],
        template: `<div class="part" v-bind:style="{backgroundImage: image}"></div>`,
        computed: {
            image: function(){
                return `url("${this.val}")`
            }
        }
    })
    new Vue({
        el: '#app',
        data: {
            parts: parts
        }
    });
}
              
            
!
999px

Console