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

              
                
              
            
!

CSS

              
                canvas {
    display:block; width:100%; height:100vh; cursor: grab;
}
              
            
!

JS

              
                import * as $ from '//cdn.skypack.dev/three@0.126.0/build/three.module.js?min'
import { OrbitControls } from '//cdn.skypack.dev/three@0.126.0/examples/jsm/controls/OrbitControls.js?min'
import { EffectComposer } from '//cdn.skypack.dev/three@0.126.0/examples/jsm/postprocessing/EffectComposer.js?min'
import { RenderPass } from '//cdn.skypack.dev/three@0.126.0/examples/jsm/postprocessing/RenderPass.js?min'
import { SAOPass } from '//cdn.skypack.dev/three@0.126.0/examples/jsm/postprocessing/SAOPass.js?min'
import { BufferGeometryUtils } from '//cdn.skypack.dev/three@0.126.0/examples/jsm/utils/BufferGeometryUtils.js?min'
import { gsap } from '//cdn.skypack.dev/gsap@3.6.0?min'

// ---- boot

const renderer = new $.WebGLRenderer({});
const scene = new $.Scene();
const camera = new $.PerspectiveCamera(75, 2, .1, 1000);
const controls = new OrbitControls(camera, renderer.domElement);
const bufferSize = new $.Vector2();
addEventListener('resize', () => {
    const { clientWidth, clientHeight } = renderer.domElement;
    renderer.setPixelRatio(window.devicePixelRatio);
    renderer.setSize(clientWidth, clientHeight, false);
    camera.aspect = clientWidth / clientHeight;
    camera.updateProjectionMatrix();
    renderer.getDrawingBufferSize(bufferSize);
});
document.body.prepend(renderer.domElement);
dispatchEvent(new Event('resize'));

// ---- config

const patternRepeatX = 4;
const patternRepeatY = 2;

// ---- setup

camera.position.set(5, -5, 5);
controls.enableDamping = true;

// ---- build

const { mat } = (() => {
    // refs: https://unsplash.com/photos/GTTcwwZRdhg
    const pattern = [
        [3, 2, 2, 2, 1, 1, 1, 2, 2, 2],
        [1, 2, 2, 2, 2, 1, 2, 2, 2, 2],
        [3, 2, 2, 2, 3, 2, 2, 2],
        [1, 2, 2, 2, 2, 1, 2, 2, 2, 2],
        [3, 2, 2, 2, 3, 2, 2, 2],
        [1, 2, 2, 2, 2, 1, 2, 2, 2, 2],
        [3, 2, 2, 2, 3, 2, 2, 2],
        [1, 2, 2, 2, 2, 1, 2, 2, 2, 2],
        [1, 1, 1, 2, 2, 2, 3, 2, 2, 2],
        [1, 2, 2, 2, 2, 1, 2, 2, 2, 2],
    ]
    const bricksPerCol = pattern.map(col => col.length);
    const breadthsPerCol = pattern.map(col => col.reduce((o, nu) => o + nu));
    const bricksPerPattern = bricksPerCol.reduce((o, nu) => o + nu);
    const nInst = bricksPerPattern * patternRepeatX * patternRepeatY;

    const geom = (() => {
        const geom1 = new $.SphereBufferGeometry(0.5, 16, 12);
        const geom2 = new $.TorusBufferGeometry(0.5, 0.3, 16, 10);
        const geom = BufferGeometryUtils.mergeBufferGeometries([geom1, geom2]);
        geom1.dispose();
        geom2.dispose();
        return geom;
    })();
    const mat = (() => {
        // texture by Malena Gonzalez Serena - https://unsplash.com/photos/jWTvMpHhdJY
        const url = 'https://images.unsplash.com/photo-1589097486539-3093d77c5657?ixid=MXwxMjA3fDB8MHx0b3BpYy1mZWVkfDE4MnxHdHJCU2N2MWI1TXx8ZW58MHx8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=600&q=60';
        const tex = new $.TextureLoader().load(url);
        tex.repeat.set(8, 2);
        tex.wrapS = $.MirroredRepeatWrapping;
        tex.wrapT = $.MirroredRepeatWrapping;
        const mat0 = new $.MeshStandardMaterial({ map: tex, metalness: 0, roughnessMap: tex });
        return mat0;
    })();
    const mesh = new $.InstancedMesh(geom, mat, nInst);

    const $m0 = new $.Matrix4();
    const $m1 = new $.Matrix4();
    const $c = new $.Color();
    const palette = (() => {
        const pal = [];
        for (let i = 0; i < 12; ++i) {
            pal.push(new $.Color().setHSL(i / 12, 0.2, (i/ 12) * 0.5 + 0.2));
        }
        return pal;
    })();
    for (let i = 0, c = 0; i < patternRepeatY; ++i) {
        for (let j = 0; j < patternRepeatX; ++j) {
            for (const [k, col] of pattern.entries()) {
                let offset = k % 2;
                for (const [m, scale] of col.entries()) {
                    const x = (j / patternRepeatX - 0.5) * (patternRepeatX * pattern.length) + k;
                    const y = (i / patternRepeatY - 0.5) * (patternRepeatY * breadthsPerCol[0]) + offset + (scale / 2);
                    $m0.makeTranslation(x, y, 0);
                    $m1.makeScale(1, scale, 1);
                    mesh.setMatrixAt(c, $m0.multiply($m1));
                    mesh.setColorAt(c, (scale === 1 ? palette[0] : palette[c % (palette.length - 1) + 1]));
                    offset += scale;
                    ++c;
                }
            }
        }
    }
    scene.add(mesh);

    return { mat };
})();

// ---- lighting

const light0 = new $.AmbientLight('cornsilk', 1);
scene.add(light0);

const light1 = new $.DirectionalLight('cornsilk', 1);
light1.position.set(-5, 10, 15);
scene.add(light1);

const light2 = new $.DirectionalLight('gold', 1);
light2.position.set(5, -5, 15);
scene.add(light2);

// ---- pp

const composer = (() => {
    const composer = new EffectComposer(renderer);
    composer.addPass(new RenderPass(scene, camera));
    const sao = new SAOPass(scene, camera, true, true);
    sao.params.saoIntensity = 0.0115;
    sao.params.saoScale = 1;
    sao.params.saoBlurDepthCutoff = 0.001;
    composer.addPass(sao);
    addEventListener('resize', () => composer.setSize(bufferSize.x, bufferSize.y));
    return composer;
})();

// ---- render loop

{
    const cap = 1000 / 24;
    let t0 = 0;
    renderer.setAnimationLoop((t) => {
        if (t - t0 > cap) {
            composer.render();
            t0 = t;
        }
        mat.map.offset.y += 0.001;
        controls.update();
    });
}

gsap.to(camera.position, { y: 0, x: 0, z: 5, duration: 4 });

              
            
!
999px

Console