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

              
                - var nf = 6; //- number of cube faces
- var fdata = ['rotateY', 'translateX'];
- var vdata = [90, 50, -90];
- var udata = ['deg', '%'];
- var nc = 3;
- var r = 400, d = 2*r, n = 3, rr = .1*r;
- var c = 2*Math.PI*r;

mixin roundpoly(n, r, rr)
	- var ba = 2*Math.PI/n;
	- var va = (n - 2)*Math.PI/n;
	- var oa = .5*(Math.PI - va);
	- var v = [];
	- var d = '';
	- for(var i = 0; i < n; i++) {
		- var ca = i*ba;
		- var x0 = r*Math.cos(ca);
		- var y0 = r*Math.sin(ca);
		- var sa = ca - oa;
		- var xs = x0 + rr*Math.cos(sa);
		- var ys = y0 + rr*Math.sin(sa);
		- v.push([xs, ys]);
		- d += (i?'L':'M') + [xs, ys];
		- var ea = ca + oa;
		- var xe = x0 + rr*Math.cos(ea);
		- var ye = y0 + rr*Math.sin(ea);
		- d += 'A' + [rr, rr, 0, 0, 1, xe, ye].join(' ');
		- v.push([xe, ye])
	- }
	- d += 'z';
	path(d=d)

input(type='checkbox' id='run')

svg(width='0' height='0')
	defs
		marker#arrow(viewBox='-50 -70 250 140' 
								 markerUnits='strokeWidth'
								 markerWidth='70' 
								 markerHeight='56'
								 orient='auto' refX='100')
			polygon(points='50,0 0,-50 150,0 0,50')
	symbol#s(viewBox='-450 -450 900 900')
		line(x2='47%')
		circle(r='1.75%')

section.scene
	.cube
		while nf--
			.square.cube__face
		.square.ini
			svg
				use(xlink:href='#s')
		.square.ani.basic
			svg
				use(xlink:href='#s')

pre
	while nc--
		- var i = nc%2;
		span.tf
			span.token--fnc #{fdata[i]}
			| (
			span.token--var #{vdata[nc]}
			span.token--uni #{udata[i]}
			| ) 

label(for='run')
	svg(viewBox=[-r, -r, d, d].join(' '))
		defs
			clipPath#cpc
				circle#c(r=r transform='rotate(-90)')
		use(xlink:href='#c' clip-path='url(#cpc)' 
				stroke-dasharray=c 
				stroke-dashoffset=c)
		+roundpoly(n, r - 3*rr, rr)
              
            
!

CSS

              
                @import 'compass/css3';

$chain: rotateY(-90deg) translate(50%) 
				rotateY(90deg);
$n-states: length($chain) + 2;
$perc: 100%/$n-states;
$d-play: 8em;

* {
	margin: 0;
	padding: 0;
	fill: currentColor;
	vector-effect: non-scaling-stroke;
}

html { overflow: hidden; }

body {
	display: flex;
	flex-direction: column;
	margin: 0;
	min-width: 10em; height: 100vh;

	> svg, > input, > label {
		position: absolute;
	}
	
	@media (min-aspect-ratio: 105/100) 
		 and (min-width: 50em) {
		flex-direction: row;

		pre {
			width: 10em;
			display: flex;
			flex-direction: column;
			justify-content: center;
		}
	}
}

line {
	stroke: currentColor;
	stroke-width: 2px;
	marker-end: url(#arrow);
	vector-effect: non-scaling-stroke;
}

div {
	position: absolute;
	transform-style: preserve-3d;
}

pre {
	order: 1;
	padding: .5em 1em;
	background: #111;
	color: #ccc;
	font: .875em/2 courier;
	white-space: pre-wrap;
	
	@media (min-width: 15em) {
		font-size: 1em;
	}
	
	@media (min-width: 20em) {
		font-size: 1.25em;
	}
	
	@media (min-width: 75em) {
		font-size: 1.5em;
	}
}

body > svg { position: absolute; }

.hidden { opacity: .001; }

.scene {
	flex: 1;
	order: 2;
	perspective: 32em;
	perspective-origin: calc(50% - 10em) 50%;
}

.cube {
	--inradius: 19%;
	
	top: 50%; left: 50%;
	margin: calc(-1*var(--inradius));
	padding: var(--inradius);
	
	&__face {
		box-shadow: inset 0 0 0 1px black;
		opacity: .5;
		background: whitesmoke;
		
		@for $i from 0 to 6 {
			$s: pow(-1, $i);
			
			&:nth-child(#{$i + 1}) {
				transform: if($i < 4, 
					rotateY($i*90deg), 
					rotate($s*90deg))
				translate(50%) rotateY(90deg);
			}
		}
	}
	
	@media (min-aspect-ratio: 1/1) 
		and (min-width: 50em) {
			--inradius: 15%;
	}
	
	@media (min-aspect-ratio: 13/10) {
		@media (min-width: 62.5em) {
			--inradius: 12.5%;
		}

		@media (min-width: 75em) {
			--inradius: 10%;
		}

		@media (min-width: 100em) {
			--inradius: 8%;
		}
	}
}

.square {
	top: 0; right: 0; bottom: 0; left: 0;
	
	&:not(.cube__face) {
		> svg { width: 100%; height: 100%; }
		
		@media (min-width: 20em) {
			&:after {
				position: absolute;
				right: .25em; bottom: 50%;
				font: italic 2em/1.5 times new roman, serif;
				content: 'x';
			}
		}
	}
}

.ini { background: rgba(silver, .65); }

.ani { background: rgba(#ee8c25, .75); }

.basic {
	animation: ani 5s linear infinite;
	animation-play-state: paused;
}

@keyframes ani {
	$curr-chain: ();
	
	@for $i from 1 to $n-states {
		$ks: $i*$perc;
		
		@if $i == 1 { $ks: 0%, $ks }
		@else {
			$curr-chain: $curr-chain 
									 nth($chain, $i - 1);
		}
		@if $i == $n-states - 1 { $ks: $ks, 100% }
		
		#{$ks} {
			transform: 
				if($i == 1, none, $curr-chain);
		}
	}
}

.token {
	&--fnc { color: mix(#fff, #1c9edc); }
	&--uni { color: mix(#fff, #a048b9); }
	
	&--var {
		color: mix(#fff, #d14730);
		font-weight: 900;
	}
}

[id='run'] {
	position: absolute;
	left: -100vw;
	
	&:checked {
		& ~ .scene .basic {
			animation-play-state: running;
		}
		
		& ~ [for='run'] { opacity: .001; }
	}
}

[for='run'] {
	display: flex;
	justify-content: center;
	position: absolute;
	z-index: 3;
	top: 0; left: 0;
	width: 100vw; height: 100vh;
	opacity: .999;
	transition: opacity .5s;
	cursor: pointer;
	
	svg {
		align-self: center;
		width: $d-play; height: $d-play;
		
		&:hover use {
			stroke-dashoffset: 0;
		}
	}
	
	* {
		fill: none;
		stroke: #4ca454;
	}
	
	use {
		transition: stroke-dashoffset 1s 
			ease-in-out;
		stroke-width: .5em;
	}
	
	path { stroke-width: .25em; }
}
              
            
!

JS

              
                const AF = 180/Math.PI, 
			_run = document.getElementById('run'), 
			_ani = document.querySelector('.ani'), 
			_tfs = document.querySelectorAll('.tf'), 
			vsel = '.token--var', 
			_v = document.querySelectorAll(vsel);

let pf, rID = null, hflag = null, 
		rfs = [null, null, null];

function update() {
	let m = getComputedStyle(_ani).transform;
	
	m = m.replace(/matrix|3d|\(|\)|\s/g, '')
			.split(',');
	
	if(m.length === 16) {
		let ba, ra, ca, p;
		
		m = m.map(c => { return parseFloat(c) });
		ba = Math.acos(m[0])*AF;
		ra = Math.round(ba);

		if(hflag && rfs[0]) {
			_tfs[0].classList.remove('hidden');
			rfs[0] = hflag = false;
		}

		switch(true) {
			case m[14] === 0:
				_v[0].textContent = -ra;
				break;
			case m[14] > 0 && ra === 90:
				if(rfs[1]) {
					_v[0].textContent = -90;
					_tfs[1].classList.remove('hidden')
					rfs[1] = false;
				}

				p = Math.round(m[14]*pf);
				_v[1].textContent = p;
				break;
			case m[14] > 0 && ra < 90:
				if(rfs[2]) {
					_v[1].textContent = 50;
					_tfs[2].classList.remove('hidden')
					rfs[2] = false;
				}

				ca = Math.round(90 - ba);
				_v[2].textContent = ca;
				break;
		}
	}
	else if(!hflag) resetChain();
	
	rID = requestAnimationFrame(update);
};

function size() {
	pf = 100/_ani.getBoundingClientRect().width;
};

function resetChain() {
	size();
	
	for(let i = 0; i < 3; i++) {
		_tfs[i].classList.add('hidden');
		_v[i].textContent = 0;
		rfs[i] = true;
	}
	
	hflag = true;
};

resetChain();

addEventListener('resize', size, false);

_run.addEventListener('change', e => {
	if(_run.checked) { update(); }
	else { cancelAnimationFrame(rID); }
}, false);
              
            
!
999px

Console