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

              
                - @nfaces = 6;

.prism.wireframe
	- (1..@nfaces).each do |i|
		.prism__face
			- if i%4 == 2
				%svg{:viewBox => '-500 -500 1000 1000', :class => ('hidden' if i == 2)}
					%circle{:r => 385}
					%path#arc
.prism.ini
	.prism__face{:'data-type' => 'lat'}
.prism.builder
	.prism__face{:'data-type' => 'lat', :'data-f' => 1}

%form#opts
	- (1..@nfaces).each do |i|
		%input{:type => 'radio', :name => 'f', :id => "f#{i}", :checked => ('checked' if i == 1)}
		%label{:for => "f#{i}"} #{i}

%form#player
	%button#play.paused.replaced{:title => 'play'}
		play/pause
	%input{:type => 'range', :id => 'progress', :value => '0'}
	%section
		%button#sped{:title => 'speed'} 1x
		.popup.hidden
			- @vf = [2, 1.5, 1.25, 1, 0.75, 0.5, 0.25];
			- @vf.each do |factor|
				- @txt = "#{factor}x".gsub('0', '');
				%button{:class => ('active' if factor == 1), :'data-f' => "#{factor}"} #{@txt}
			%input{:type => 'range', :id => 'factor', :min => '.1', :max => '2.1', :value => '1', :step => '.05'}
			
	%button#loop.replaced{:title => 'loop'} loop

#inf
              
            
!

CSS

              
                @import 'compass/css3';

/* =============== UTILITY =============== */
$theme-base: #000;
$theme-hl: #e18728;

.hidden { opacity: .001; pointer-events: none; }

.replaced { overflow: hidden; text-indent: -100vw; }


/* =============== GEOMETRY =============== */
$height: 6.25em; // height of a bar
$base: 1em; // base of a bar
$base-c: #69f #7e4b4c; // base shades
$lat-c: #542252 #7e301a; // lateral shades
$alpha: .4;

@mixin sp($w, $h: $w) {
	margin: -.5*$h if($w != $h, -.5*$w, ());
	width: $w; height: $h;
	line-height: $h;
}

@mixin shade($side: 1, $type: $lat-c) {
	background: rgba(nth($type, $side), $alpha);
}

body {
	margin: 0;
	height: 100vh;
	perspective: 40em;
	perspective-origin: calc(50% + 20em) calc(50% - 25em);
	font: 1em/2 verdana, sans-serif;
	text-align: center;
}

[class*='prism'], svg {
	transform-style: preserve-3d;
	position: absolute;
	top: 50%; left: 50%;
}

.prism {
	color: $theme-base;
	font-size: 10vmin;
	
	&__face {
		@include sp($base, $height);
		
		&:nth-child(n + 5), &[data-type='base'] {
			margin-top: -.5*$base;
			height: $base;
			line-height: $base;
		}
		
		.wireframe & {
			box-shadow: 0 0 1px currentColor, 
				inset 0 0 0 1px currentColor;
			
			@for $i from 0 to 6 {
				&:nth-child(#{$i + 1}) {
					transform: 
						if($i < 4, rotateY($i*90deg), rotateX(pow(-1, $i)*90deg)) 
						translateZ(.5*if($i < 4, $base, $height));
				}
			}
		}
		
		.ini & {
			box-sizing: border-box;
			border: dashed 1px $theme-base;
		}
		
		.builder & {
			backface-visibility: hidden;
			
			&:before, &:after {
				position: absolute;
				top: 0; right: 0; bottom: 0; left: 0;
				backface-visibility: hidden;
				content: attr(data-f);
			}
			
			&:before { @include shade(); }
			
			&:after {
				transform: rotateY(180deg);
				@include shade(2);
			}
			
			&[data-type='base'] {
				&:before { @include shade(1, $base-c); }

				&:after {
					transform: rotateX(180deg);
					@include shade(2, $base-c);
				}
			}
		}
	}
}

svg {
	overflow: visible;
	@include sp(1.25*$base);
	
	.prism__face:nth-child(2) & {
		transform: rotate(-90deg);
	}
}

circle {
	fill: transparent;
	stroke: #4472b9;
	stroke-width: 32;
	stroke-dasharray: 50;
}

path {
	opacity: .001;
	fill: transparent;
	stroke: #4ca454;
	stroke-width: 32;
}


/* =============== OUTPUT =============== */
[id='inf'] {
	position: absolute;
	top: 0; right: 0;
	width: 21em; height: 2em;
	background: #be4c39;
	color: white;
	font: 700 1.5em/2 monospace;
	text-align: center;
}


/* =============== CONTROLS =============== */
$ctrl-bg: #333;
$ctrl-ll: #aaa;
$ctrl-hl: #fff;

$td: .3s;

$btn-a: 2em;

$play-l: .625*$btn-a;
$play-h: .5625*$btn-a;
$loop-d: $play-l;
$loop-bw: .125em;

$popup-pad: 1.5em;
$vf: 2 1.5 1.25 1 .75 .5 .25;

$track-w: 19em;
$track-h: .25em;

$thumb-d: 1.25em;
$btn-d: 1.25em;
$th: .875em;

@mixin track() {
	width: $track-w; height: $track-h;
	background: $ctrl-ll;
}

@mixin fill() {
	background: $theme-hl;
}

@mixin thumb() {
	border: none;
	width: $thumb-d; height: $thumb-d;
	border-radius: 50%;
	background: $theme-hl;
}

form {
	position: absolute;
	background: $ctrl-bg;
	color: $ctrl-ll;
	
	section { position: relative; }
}

label, button, input {
	font: inherit;
	cursor: pointer;
	transition: $td;
	
	&:focus {
		outline: dashed 1px rgba($ctrl-ll, .1);
	}
}

[id='fopts'] {  padding: 0; }

[type='radio'] {
	position: absolute;
	transform: translate(-100vw);
	
	+ label {
		float: left;
		width: 2em;
		
		&:not(:first-of-type) {
			border-left: solid 1px $ctrl-ll;
		}
		&:not(:last-of-type) {
			border-right: solid 1px $theme-base;
		}
	}
	
	&:checked + label {
		border-right-color: darken($theme-hl, 16%);
		background: $theme-hl;
		color: $ctrl-hl;
		font-weight: 600;
	}
}

[id='player'] {
	right: 7em; bottom: 0;
	padding: .25em;
	height: $btn-a;
	
	> * {
		display: inline-block;
		vertical-align: middle;
	}
	
	section { position: relative; }
}

.popup {
	position: absolute;
	bottom: 100%; left: 50%;
	margin-bottom: .5625em;
	padding: $popup-pad 0;
	height: $track-w; width: 5*$btn-a;
	transform: translate(-50%);
	background: $ctrl-bg;
	font-size: .75em;
	
	* {
		position: absolute;
	}
}

button {
	margin: 0;
	border: none;
	padding: 0;
	width: 2*$btn-a; height: $btn-a;
	box-shadow: inset 0 0 0 2px rgba($ctrl-ll, .05);
	background: transparent;
	color: inherit;
	
	&.replaced {
		position: relative;
		width: $btn-a;
		
		&:before, &:after {
			position: absolute;
			top: 50%;
			transition: $td;
			content: ''
		}
	}
	
	.popup & {
		left: 35%;
		margin: -.5*$btn-a (-$btn-a);
		
		&:hover, &:focus {
			box-shadow: inset 0 0 0 2px rgba($ctrl-ll, .32);
		}
		
		&.active {
			color: $theme-hl;
		}
		
		@each $f in $vf {
			&[data-f='#{$f}'] {
				bottom: $popup-pad + .5*$thumb-d + 
					.5*($f - .1)*($track-w - $thumb-d);
			}
		}
	}
}

[id='play'] {
	&:before, &:after {
		border: solid 0 transparent;
		height: $play-l;
		border-left: solid .25*$play-l currentColor;
		transform: translateY(-50%);
		content: '';
	}
	
	&:before {
		left: .5*($btn-a - $play-h);
	}
	
	&:after {
		right: .5*($btn-a - $play-h);
	}
	
	&:hover, &:focus {
		color: $theme-hl;
	}
	
	&.paused {
		&:before {
			border-width: 
				.5*$play-l 0 .5*$play-l $play-h;
			height: 0;
		}
		&:after {
			border-width: 0;
			height: 0;
		}
	}
}

[id='sped'] {	
	&:hover, &:focus, &:active, &.active {
		color: $theme-hl;
	}
}

[id='loop'] {
	opacity: .5;
	
	&:before, &:after { left: 50%; }
	
	&:before {
		box-sizing: border-box;
		border: solid $loop-bw currentColor;
		border-right-color: transparent;
		@include sp($loop-d);
		border-radius: 50%;
		transform: rotate(45deg);
	}
	
	&:after {
		margin: 0 (.5*$loop-d - 2.5*$loop-bw);
		border: solid 2*$loop-bw currentColor;
		border-color: currentColor transparent transparent;
	}
	
	&:hover, &:focus, &.loop { opacity: .999; }
	
	&.loop { color: $theme-hl; }
}

[type='range'] {
	&, 
	&::-webkit-slider-runnable-track, 
	&::-webkit-slider-thumb {
		-webkit-appearance: none;
	}
	
	margin: 0;
	padding: 0;
	width: $track-w; height: $btn-a;
	background: none;
	
	&::-webkit-slider-runnable-track {
		@include track();
	}
	&::-moz-range-track {
		@include track();
	}
	&::-ms-track {
		border: none;
		@include track();
		color: transparent;
	}
	
	&::-webkit-slider-thumb {
		margin-top: ($track-h - $thumb-d)/2;
		@include thumb();
	}
	&::-moz-range-thumb {
		@include thumb();
	}
	&::-ms-thumb {
		@include thumb();
	}
	
	&::-ms-tooltip { display: none; }
}

[id='progress'] {
	&::-moz-range-progress {
		height: $track-h;
		@include fill();
	}
	&::-ms-fill-lower {
		@include fill();
	}
}

[id='factor'] {
	top: 50%; left: 75%;
	transform: translate(-50%, -50%) rotate(-90deg);
	
	&::-ms-fill-lower {
		background: transparent;
	}
}
              
            
!

JS

              
                Object.getOwnPropertyNames(Math).map(function(p) {
  window[p] = Math[p];
});

var T = 60, 
		DIR = ['X', 'Y'], 
		
		b, h, ani, flag = false, r, max, 
		f = document.querySelector('.builder *'), 
		fi = document.querySelector('.ini *'), 
		popup = document.querySelector('.popup'), 
		bplay = document.getElementById('play'), 
		bsped = document.getElementById('sped'), 
		rp = document.getElementById('progress'), 
		rf = document.getElementById('factor'), 
		inf = document.getElementById('inf'), 
		svg = document.querySelectorAll('svg'), 
		arc = document.querySelectorAll('path');

var FaceData = function(idx, el, b, h) {
	var x, y, d;
	
	this.el = el || null;
	
	this.init = function(idx) {
		this.idx = idx || 0;
		this.dir = (this.idx < 4) ? 1 : 0;
		this.frot = (this.dir ? this.idx : pow(-1, this.idx))*90;
		this.ft = .5*(this.dir ? b : h) || 0;
		this.crot = 0;
		this.ct = 0;
		
		if(svg[this.dir].classList.contains('hidden')) {
			svg[this.dir].classList.remove('hidden');
			svg[1 - this.dir].classList.add('hidden');
		}
		
		arc[this.dir].setAttribute('d', '');
		
		if(this.el) {
			this.el.dataset.f = (this.idx + 1);
			this.el.dataset.type = 
			fi.dataset.type = 
				(this.idx < 4) ? 'lat' : 'base';
			this.setTransform();
		}
	};
	
	this.refreshRot = function(sf) {
		var rad, f1, f2;
		
		this.crot = sf*this.frot;
		
		rad = (this.crot/180 - 1)*PI;
		x = ~~(r*cos(rad));
		y = ~~(r*sin(rad));
		f1 = (this.crot > 180)?1:0;
		f2 = (this.crot > 0)?1:0;
		d = 'M' + -r + ',0A' + r + ' ' + r + ' 0 ' + 
			f1 + ' ' + f2+ ' ' + x + ' ' + y
		arc[this.dir].setAttribute('d', d);
		if(sf < 1) { this.ct = 0; }
	};
	
	this.refreshPos = function(sf) {
		var d1, sgn = sign(x || -y);
		
		d1 = d + ((y == 0)?'V':'H') + ~~(sgn*sf*r);
		arc[this.dir].setAttribute('d', d1);
		this.ct = sf*this.ft;
	};
	
	this.setTransform = function() {
		var tt = 'none', tt1 = 'none';
		
		if(abs(this.crot) > 0) {
			tt = 'rotate' + DIR[this.dir] + 
				'(' + this.crot.toFixed(2) + 'deg)';
			tt1 = 'rotate' + DIR[this.dir] + 
				'(' + ~~this.crot + 'deg) ';
		}
		if(this.ct > 0) {
			tt += 'translateZ(' + this.ct.toFixed(8) + 'em)';
			tt1 += 'translateZ(' + this.ct.toFixed(2) + 'em)';
		}
		tt = tt.replace('none', '');
		tt1 = tt1.replace('none', '').replace('0.', '.');
				
		this.el.style.webkitTransform = 
		this.el.style.transform = tt;
		inf.textContent = tt1;
	};
	
	this.init();
};

var Animation = function(data, vf, pausd, loop) {
	this.data = data;
	
	this.vf = vf || 1;
	this.paused = pausd || true;
	this.stopped = true;
	this.at = 0;
	this.loop = loop || false;
	this.t = 0;
	this.rid = null;
	
	this.updateData = function() {
		this.ns = abs(this.data.frot)/90 + 1;
		this.ratio = (this.ns - 1)/this.ns;
		this.tbase = this.ns*T;
		this.tscaled = this.tbase;
				
		if(this.rid) this.cancel();
	};
	
	this.reset = function() {
		rp.value = 0;
		this.t = 0;
		this.at = 0;
	};
	
	this.cancel = function() {
		cancelAnimationFrame(this.rid);
		this.rid = null;
	};
	
	this.switch = function() {
		if(this.stopped) {
			this.stopped = false;
			this.reset();
		}
		
		this.paused = !this.paused;
		bplay.classList.toggle('paused');
		bplay.setAttribute(
			'title', 
			this.paused ? 'play' : 'pause'
		);
		
		if(this.paused) {
			this.cancel();
			return;
		}
		else {
			arc[this.data.dir].setAttribute('d', '');
			this.run();
		}
	};
	
	this.run = function() {
		if(~~rp.value === max) {
			this.data.refreshRot(1);
			this.data.refreshPos(1);
			this.data.setTransform();
			this.data.ct = 0;
			this.data.crot = 0;
			
			if(!this.loop) {
				this.switch();
				this.stopped = true;
				this.cancel()
				return;
			}
			else {
				this.reset();
			}
		}
		
		rp.value = this.at*max;
				
		if(this.at > this.ratio) {
			this.data.refreshRot(1);
			this.data.refreshPos((this.at - this.ratio)*this.ns);
		}
		else {
			this.data.refreshRot(this.at/this.ratio);
		}
		
		this.data.setTransform();
		
		this.t = this.at*this.tscaled + this.vf;
		this.at = this.t/this.tscaled;
		
		this.rid = 
			requestAnimationFrame(this.run.bind(this));
	};
	
	this.speed = function(factor, curr) {
		var fa = popup.querySelector('.active');
		
		this.vf = factor || 1;
		this.tscaled = this.tbase/this.vf;
		if(fa) fa.classList.remove('active');
		if(!curr) {
			curr = popup.querySelector('[data-f="' + this.vf + '"]');
		}
		if(curr) {
			curr.classList.add('active');
			rf.value = this.vf;
		}
		
		this.at = rp.value/max;
		
		bsped.textContent = (this.vf + 'x').replace('0.', '.');
	};
	
	this.updateData();
};

var init = function() {
	size();
	
	ani = new Animation(new FaceData(1, f, b, h));
	r = ~~document.querySelector('circle').getAttribute('r');
	max = ~~rp.max || 100;
};

var size = function() {
	var s, fs;
	
	if(f) {
		s = getComputedStyle(f);
		fs = ~~s.fontSize.split('px')[0];
		b = s.width.split('px')[0]/fs;
		h = s.height.split('px')[0]/fs;
	}
};

var pchange = function() {
	if(ani.at*max != ~~rp.value) {
		ani.at = rp.value/max;
		if(ani.at > ani.ratio) {
			ani.data.refreshPos((ani.at - ani.ratio)*ani.ns);
			ani.data.refreshRot(1);
		}
		else {
			ani.data.refreshRot(ani.at/ani.ratio);
		}
		ani.data.setTransform();
	}
};

var fchange = function() {
	var val = 1*rf.value;
		
	if(val !== ani.vf) ani.speed(val);
};

init();

addEventListener('resize', size, false);

addEventListener('click', function(e) {
	var tg = e.target, val;
	
	if(tg.id !== 'sped' && popup && 
		 tg.parentNode !== popup) {
		popup.classList.add('hidden');
		bsped.classList.remove('active');
	}
	
	if(ani.data && tg.tagName.toLowerCase() === 'label') {
		ani.data.init(tg.textContent - 1);
		ani.updateData();
		if(!ani.paused) {
			ani.switch();
			ani.reset();
		}
		return;
	}
	
	if(tg.tagName.toLowerCase() === 'button') {
		e.preventDefault();
		if(tg.id) {
			switch(tg.id) {
				case 'play':
					ani.switch();
					break;
				case 'sped':
					popup.classList.toggle('hidden');
					tg.classList.toggle('active');
					break;
				case 'loop':
					ani.loop = !ani.loop;
					tg.classList.toggle('loop');
					break;
			}
		}
		else {
			if(!tg.classList.contains('active')) {
				ani.speed(1*tg.dataset.f, tg);
			}
		}
		
		tg.blur();
	}
}, false);

rp.addEventListener('input', pchange, false);
rp.addEventListener('change', pchange, false);

rp.addEventListener('mousedown', function() {
	if(ani.rid) {
		flag = true;
		ani.switch();
	}
}, false);

rp.addEventListener('mouseup', function() {
	if(flag) {
		flag = false;
		ani.switch();
	}
}, false);

rf.addEventListener('input', fchange, false);
rf.addEventListener('change', fchange, false);
              
            
!
999px

Console