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

              
                <!-- made with http://github.com/lume/lume -->
<script src="https://assets.codepen.io/191583/LUME.unversioned.2.js"></script>

<!-- Polyfill for Pointer Events (boo Safari) -->
<script src="https://code.jquery.com/pep/0.4.3/pep.js"></script>

<codepen-cube size="150"> </codepen-cube>
              
            
!

CSS

              
                html,
body {
	margin: 0;
	padding: 0;
	height: 100%;
	width: 100%;
	background: linear-gradient(
		315deg,
		rgb(154, 183, 230) 0%,
		rgb(238, 174, 174) 100%
	);
}
lume-scene {
	background: rgba(0, 0, 0, 0.1);
	touch-action: none;
}
lume-node {
	background: linear-gradient(
		152deg,
		rgb(154, 183, 230) 0%,
		rgb(238, 174, 174) 100%
	);
}

              
            
!

JS

              
                // Registers the LUME HTML elements with the browser.
LUME.useDefaultNames();

const { Element, element, html, reactive, numberAttribute } = LUME;

const size = 50;

@element("codepen-cube")
class CodepenCube extends Element {
	root = this;

	@reactive @numberAttribute(100) size = 100;

	@reactive rotation = 0;

	// prettier-ignore
	template = () =>  html`
		<div Xstyle=${() => ({width: this.size+'px', height: this.size + 'px'})}>
			<lume-scene ref=${s => this.scene = s} touch-action="none">
				<lume-node rotation=${() => [1, this.rotation, 1]} align="0.5 0.5" size="0 0 0">
					<lume-node id="cube-face1" class="front"  position=${() => [0, 0, this.size/2]}  rotation="0 0 0"   size=${() => [this.size, this.size, 0]} mount-point="0.5 0.5" align="0.5 0.5 0.5"></lume-node>
					<lume-node id="cube-face2" class="back"   position=${() => [0, 0, -this.size/2]} rotation="0 180 0" size=${() => [this.size, this.size, 0]} mount-point="0.5 0.5" align="0.5 0.5 0.5"></lume-node>
					<lume-node id="cube-face3" class="left"   position=${() => [-this.size/2, 0, 0]} rotation="0 -90 0" size=${() => [this.size, this.size, 0]} mount-point="0.5 0.5" align="0.5 0.5 0.5"></lume-node>
					<lume-node id="cube-face4" class="right"  position=${() => [this.size/2, 0, 0]}  rotation="0 90 0"  size=${() => [this.size, this.size, 0]} mount-point="0.5 0.5" align="0.5 0.5 0.5"></lume-node>
					<lume-node id="cube-face5" class="top"    position=${() => [0, -this.size/2, 0]} rotation="-90 0 0" size=${() => [this.size, this.size, 0]} mount-point="0.5 0.5" align="0.5 0.5 0.5"></lume-node>
					<lume-node id="cube-face6" class="bottom" position=${() => [0, this.size/2, 0]}  rotation="90 0 0"  size=${() => [this.size, this.size, 0]} mount-point="0.5 0.5" align="0.5 0.5 0.5"></lume-node>
				</lume-node>
			</lume-scene>
		</div>
	`

	css = /* css */ `
		div {width: 100%; height: 100%}
    `;

	task;

	connectedCallback() {
		super.connectedCallback();

		const { Motor } = LUME;

		// Keeps the last two pointermove clientX values
		let xStack = [0, 0];

		function addX(x) {
			xStack.shift();
			xStack.push(x);
		}

		let isDragging = false;

		this.scene.addEventListener("pointerdown", (event) => {
			isDragging = true;
			addX(event.clientX);
		});

		let scheduled = false;

		this.scene.addEventListener("pointermove", (event) => {
			if (!isDragging) return;

			console.log("move!", event.clientX, event.movementX);

			const lastX = xStack[1];
			const delta = event.clientX - lastX;
			addX(event.clientX);

			this.rotation += delta * 0.2;
		});

		this.scene.addEventListener("pointerup", (event) => {
			if (!isDragging) return;
			isDragging = false;

			const secondToLastX = xStack[0];
			let delta = event.clientX - secondToLastX;

			console.log(
				"stopped drag",
				event.clientX,
				event.movementX,
				secondToLastX,
				delta
			);

			if (delta !== 0) {
				console.log("keep spinning!");
				// if the mouse was dragged (not just a click)
				const direction = Math.abs(delta) / delta;
				const deceleration = 1.5;

				Motor.removeRenderTask(this.task);

				this.task = Motor.addRenderTask(() => {
					console.log("spin");
					if (delta > deceleration * 2) {
						delta -= deceleration;
					} else if (delta < -deceleration * 2) {
						delta += deceleration;
					} else {
						Motor.removeRenderTask(this.task);

						this.task = Motor.addRenderTask(() => {
							this.rotation += direction * Math.abs(delta) * 0.005;
						});
					}

					this.rotation += delta * 0.2;
				});
			}
		});
	}
}

              
            
!
999px

Console