Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <!--
See the newer better demo!
https://codepen.io/trusktr/pen/LYgoeQo
-->

<a href="https://codepen.io/trusktr/pen/LYgoeQo" style="color: #444; text-decoration: none;" target="_blank">
    <h3 style="position: absolute; top: 10px; left: 10px; z-index: 1; background: white; border-radius: 6px; padding: 5px;">
        See the newer better demo!
    </h3>
</a>


<!-- Made with LUME: http://github.com/lume/lume -->
<script src="//unpkg.com/[email protected]/dist/global.js"></script>

<script src="//unpkg.com/[email protected]/dist/vue.js"></script>

<!-- Pointer Events Polyfill for old browsers like Safari. -->
<script src="https://code.jquery.com/pep/0.4.3/pep.js"></script>

<!-- Tween.js for animating the buttons up and down. -->
<script src="https://unpkg.com/[email protected]/src/Tween.js"></script>

<template vue>
    <!-- Lights and shadows are powered by WebGL, but written with HTML: -->
    <lume-scene
        webgl="true"
        id="scene"
        background-color="black"
        background-opacity="0"
        perspective="800"
        shadowmap-type="pcfsoft" NOTE="one of basic, pcf, pcfsoft"
    >
        <lume-ambient-light color="#ffffff" intensity="0"></lume-ambient-light>
        <lume-mixed-plane ref="plane" id="bg" size-mode="proportional proportional" size="1 1 0" color="#444">
            <lume-node
                id="button-container"
                :position="[0, 0, buttonHeight]"
                size="600 31 0"
                align-point="0.5 0.5 0"
                mount-point="0.5 0.5 0"
            >
                <lume-mixed-plane
                    v-for="n in [0,1,2,3,4]"
                    ref="btn"
                    :key="n"
                    size-mode="literal proportional"
                    size="100 1 0"
                    :align-point="`${n*0.25} 0 0`"
                    :mount-point="`${n*0.25} 0 0`"
                    color="#444"
                >
                    <button>button {{n+1}}</button>
                </lume-mixed-plane>
            </lume-node>
            <lume-node id="lightContainer" size="0 0 0" position="0 0 300">
                <lume-point-light
                    id="light"
                    color="white"
                    size="0 0 0"
                    cast-shadow="true"
                    intensity="0.8"
                >
                    <lume-mesh
                        has="sphere-geometry basic-material"
                        size="10 10 10"
                        color="white"
                        receive-shadow="false"
                        cast-shadow="false"
                        style="pointer-events: none"
                        mount-point="0.5 0.5 0.5"
                    >
                    </lume-mesh>
                </lume-point-light>
            </lume-node>
        </lume-mixed-plane>
    </lume-scene>
</template>

<div id="root"></div>

              
            
!

CSS

              
                    body, html {
        width: 100%;
        height: 100%;
        margin: 0;
        padding: 0;
        overflow: hidden;
        font-family: sans-serif;
        /* prevent default touch actions so we can move the light with touch without scrolling */
        touch-action: none;
    }
    lume-node {
        text-align: center;
    }
    #bg {
        background: #62b997;
    }
    button {
        width: 100%;
        height: 100%;
        white-space: nowrap;
        border-radius: 0px;
        border: 1px solid #494455;
        background: #e96699;
        color: #494455;
        outline: none;
    }
    button:focus,
    button:hover {
        background: #eb4b89;
        color: #0a3359;
        border-color: #0a3359;
    }

              
            
!

JS

              
                // Made with LUME
// http://github.com/lume/lume

// Defines the LUME elements with their default names.
LUME.useDefaultNames();

const buttonHeight = 10;

new Vue({
    el: "#root",
    template: document.querySelector("[vue]").innerHTML,
    data: () => ({
        buttonHeight
    }),
    mounted() {
        const { Motor, Events } = LUME;
        const scene = document.querySelector("#scene");
        const lightContainer = document.querySelector("#lightContainer");
        const light = document.querySelector("#light");

        light.on(Events.GL_LOAD, async () => {
            light.three.shadow.radius = 2;
            light.three.distance = 800;
            light.three.shadow.bias = -0.001;
            light.needsUpdate();
        });

        // TODO this stuff should be doable via the HTML. But when needed, Three.js
        // object can be manipulated directly.
        Array.from(document.querySelectorAll("lume-mixed-plane")).forEach((n) => {
            n.on(Events.GL_LOAD, async () => {
                n.three.material.opacity = 0.3;
                n.needsUpdate();
            });
        });

        const bg = document.querySelector("#bg");

        bg.on(Events.GL_LOAD, async () => {
            bg.three.material.opacity = 0.3;
            bg.three.material.dithering = true;
            bg.needsUpdate();
        });

        const targetPosition = {
            x: window.innerWidth / 2,
            y: window.innerHeight / 2
        };

        document.addEventListener("pointermove", (e) => {
            e.preventDefault();
            targetPosition.x = e.clientX;
            targetPosition.y = e.clientY;
        });

        Motor.addRenderTask((time) => {
            lightContainer.position.x +=
                (targetPosition.x - lightContainer.position.x) * 0.05;
            lightContainer.position.y +=
                (targetPosition.y - lightContainer.position.y) * 0.05;
            // light.position.x = 20 * Math.sin(time * 0.001);
            // light.position.y = 20 * Math.cos(time * 0.001);
        });

        let downTween, upTween, pressedButton;

        // On mouse down animate the button downward
        document.addEventListener("pointerdown", (e) => {
            if (is(e.target, "button")) {
                pressedButton = e.target;

                if (upTween) {
                    upTween.stop();
                    upTween = null;
                }

                downTween = new TWEEN.Tween(e.target.parentNode.position)
                    .to({ z: -this.buttonHeight }, 75)
                    .start()
                    .onComplete(() => {
                        downTween = null;
                    });

                Motor.addRenderTask((time) => {
                    if (!downTween) return false;
                    downTween.update(time);
                });
            }
        });

        // On mouse up animate the button upward
        document.addEventListener("pointerup", (e) => {
            if (pressedButton) {
                if (downTween) {
                    downTween.stop();
                    downTween = null;
                }

                upTween = new TWEEN.Tween(pressedButton.parentNode.position)
                    .to({ z: 0 }, 75)
                    .start()
                    .onComplete(() => {
                        upTween = null;
                    });

                Motor.addRenderTask((time) => {
                    if (!upTween) return false;
                    upTween.update(time);
                });
            }
        });
    }
});

function is(el, selector) {
    if ([].includes.call(document.querySelectorAll(selector), el)) return true;
    return false;
}

              
            
!
999px

Console