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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

              
                <svg width='0' height='0'>
	<symbol id='basepoly'>
		<polygon/>
	</symbol>
</svg>

<div class='prism'>
	<div class='pos'>
		<div class='prism__face--base'>
			<svg>
				<use xlink:href='#basepoly'/>
			</svg>
		</div>
		<div class='prism__face--base'>
			<svg>
				<use xlink:href='#basepoly'/>
			</svg>
		</div>
	</div>
</div>

<form>
	<fieldset>
    <button id='s0' data-txt='flatten'>flatten</button>
    <button id='s1' data-txt='3D shape'>3D shape </button>
    <input id='k' min='-100' type='range'/>
  </fieldset>
	
	<input type='range' id='n' 
				 min='3' value='5' max='20'/>
	<label for='n'>number of lateral faces</label>
	
	<input type='range' id='h' 
				 min='8' value='32' max='45'/>
	<label for='h'>height</label>
	
	<fieldset class='const'>
		<p>Keep unchanged:</p>
		<div>
			<input type='radio' name='const' id='cr' 
						 value='0' checked/>
			<label for='cr'>base circumradius</label>
		</div>
		<div>
			<input type='radio' name='const' id='l' 
						 value='1'/>
			<label for='l'>base edge length</label>
		</div>
	</fieldset>
	
	<input type='checkbox' id='auto'/>
	<label for='auto'>auto rotate</label>
</form>
              
            
!

CSS

              
                $theme-ll: rgba(darken(#d49b00, 39%), .5);
$theme-hl: #e18728;
$easeOutBack: cubic-bezier(.17, .89, .32, 1.28);


*, :before, :after { box-sizing: inherit; }

html, body { height: 100%; }

html {
	box-sizing: border-box;
	overflow: hidden;
	min-width: 15em;
}

/* =============== GEOMETRY =============== */

body {
  margin: 0;
  overflow: hidden;
  perspective: 64em;
  background: #191919;
}

.prism {
	&, div, svg {
		position: absolute;
		top: 50%; left: 50%;
		transform-style: preserve-3d;
		transition: .2s $easeOutBack, 
			transform .4s $easeOutBack;
	}
	
	animation: rot 16s linear infinite;
	animation-play-state: paused;
		
	&__face {
		&--lateral {
			border: solid .5vmin $theme-hl;
			transform-origin: 0 50%;
			background: $theme-ll;
		}
	}
}

.auto-rot {
	animation-play-state: running;
}

@keyframes rot {
	to { transform: rotate(1turn) rotateY(1turn); }
}

.pos {
	/* this is for a 3D look in IE 10-11 */
	-ms-perspective-origin: 50% 10vmin;
	-ms-perspective: 800px;
}

polygon {
	fill: $theme-ll;
	stroke: $theme-hl;
}



/* =============== CONTROLS =============== */


//* CTRL VARS */

$ctrl-bg: #262626;
$ctrl-ll: #aaa;
$ctrl-hl: $theme-hl;

$check-d: 1.25em;

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

$thumb-d: 1.25em;


//* CTRL MIXINS */

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

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

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

form {
	position: absolute;
	top: .25em; right: .25em;
	margin: .25em;
	padding: .5em;
	background: $ctrl-bg;
	color: $ctrl-ll;
	font: 1em/1.375em trebuchet ms, sans serif;
	
	p, div { text-align: left; }
	
	p { margin: .375em 0; }
}

fieldset {
	margin: 0 0 .75em;
	border: none;
	box-shadow: inset 0 0 .125em currentColor;
	text-align: center;
	
	&:not(:first-child) { margin-top: .5em; }
}

button {
	overflow: hidden;
	position: relative;
	margin: .5em .125em 0;
	border: none;
	width: 6.25rem; height: 2rem;
	box-shadow: 0 0 0 .125em $ctrl-ll;
	background: transparent;
	color: rgba($ctrl-ll, 0);
	font: inherit;
	line-height: 2;
	transition: .4s ease-out .175s;
	cursor: pointer;
	
	&:before, &:after {
		position: absolute;
		left: 0; right: 0;
		background: $ctrl-ll;
		color: $ctrl-bg;
		transition: .3s ease-out;
		content: attr(data-txt);
	}
	
	&:before { top: 0; bottom: 50%; }
	&:after {
		top: 50%; bottom: 0;
		line-height: 0;
	}
	
	&:hover, &:focus {
		outline: none;
		color: $ctrl-ll;
		
		&:before { transform: translateY(-100%); }
		&:after { transform: translateY(100%); }
	}
	
	&:active {
		color: $ctrl-hl;
		box-shadow: 0 0 0 .125em $ctrl-hl;
	}
}

input[type='checkbox'], input[type='radio'] {
	transform: translate(-100vw);
	
	+ label {
		display: inline-block;
		position: relative;
		color: $ctrl-ll;
		line-height: 2;
		cursor: pointer;
		
		&:hover {
			color: mix($ctrl-ll, $ctrl-hl);
		}
		
		&:before {
			position: absolute;
			top: 50%; right: 100%;
			margin: -$check-d/2 $check-d/4;
			border: solid .125em $ctrl-ll;
			padding: .25em;
			width: $check-d; height: $check-d;
			color: transparent;
			font: 900 1em/.5 sans-serif;
			text-indent: -.125em;
			transition: .3s ease-out;
			content: '✓';
		}
	}
	
	&:focus + label {
		color: mix($ctrl-ll, $ctrl-hl);
	}
	
	&:checked + label {
		&, &:before { color: $ctrl-hl; }
	}
}

input[type='radio'] {	
	+ label {		
		&:before {
			border-radius: 50%;
			background-clip: content-box;
			content: ''
		}
	}
	
	&:checked + label:before {
		background-color: $ctrl-hl;
	}
}

input[type='range'] {
	&, 
	&::-webkit-slider-runnable-track, 
	&::-webkit-slider-thumb {
		-webkit-appearance: none;
	}
	
	display: block;
	margin: 1em auto 0;
	padding: 0;
	width: $track-w; height: 2em;
	background: none;
	font-size: 1em;
	cursor: pointer;
	
	&::-webkit-slider-runnable-track {
		@include track();
	}
	&::-moz-range-track {
		@include track();
	}
	&::-ms-track {
		border: none;
		@include track();
		color: transparent;
	}
	
	&::-moz-range-progress {
		height: $track-h;
		@include fill();
	}
	&::-ms-fill-lower {
		@include fill();
	}
	
	&::-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; }
	
	+ label {
		display: block;
		text-align: center;
	}
		
	&:focus { outline: none; }
}

input.hide-me { 
	&, & + label { display: none; }
}
              
            
!

JS

              
                /* because me lazy */
Object.getOwnPropertyNames(Math).map(function(p) {
		window[p] = Math[p];
});

var rs = function(k) {
		return (random() < (k || .5)) ? -1 : 1;
};

Node.prototype.setAttrs = function(attr_obj) {
		for (var prop in attr_obj) {
				this.setAttribute(prop, attr_obj[prop]);
		}
};

var BASE_CR = 13,
		BASE_L = 8,
		VB_R = 1000,
		SW = 32,

		sym = document.getElementById('basepoly'),
		poly = sym.querySelector('polygon'),
		s3d = document.querySelector('.prism'),
		rot3d = true,
		pos = s3d.querySelector('.pos'),
		faces = {
				'lat': [],
				'base': []
		},
		lat_sel = '.prism__face--lateral',
		data = {},
		u = 'vmin',

		form = document.querySelector('form'),
		const_g = form.querySelector('.const'),
		k_el = document.getElementById('k'),
		n_el = document.getElementById('n'),
		h_el = document.getElementById('h'),
		const_sel = '[name=const]:checked',
		const_el,
		auto_el = document.getElementById('auto'),

		style = document.createElement('style'),
		styles = ['', '', ''];

/* no rotation if preserve-3d not supported */
var shapeRotInit = function() {
		var ts = getComputedStyle(s3d).transformStyle;

		if (ts !== 'preserve-3d') {
				auto_el.classList.add('hide-me');
				rot3d = false;
		}
};

var init = function() {
		var b, rtest;

		rtest = document.querySelector('[class*=ms]');

		document.body.appendChild(style);

		sym.setAttribute(
				'viewBox', [-VB_R, -VB_R, 2 * VB_R, 2 * VB_R].join(' ')
		);

		b = s3d.querySelectorAll('[class*=base]');

		for (var i = 0; i < 2; i++) {
				faces.base.push({
						'pos': b[i],
						'rot': b[i].querySelector('svg')
				});

				if (rtest) {
						/* comment next line to test in IE */
						/* hiding appears not to work in Edge :( */
						b[i].style.display = 'none';
						/**/
				}
		}

		update();
};

var update = function() {
		updateNData();
		updateHeight();
};

/* update data */
var updateNData = function() {
		data.n = ~~n_el.value;
		data.centralAngle = 2 * PI / data.n;
		data.polygonAngle = (data.n - 2) * PI / data.n;
		data.sin = sin(.5 * data.centralAngle);
		data.cos = cos(.5 * data.centralAngle)
		data.rCorrection =
				.5 * SW / sin(.5 * data.polygonAngle);
		data.rAdjusted = VB_R - data.rCorrection;

		updateBasePoly();
		updateLateralN();
		updateConstCrit();
		update3dFactor();
};

var updateHeight = function() {
		data.h = ~~h_el.value;

		updateBasePosition();
		updateLatSizing();
};

var updateConstCrit = function() {
		const_el = document.querySelector(const_sel);
		data.const = ~~const_el.value;

		if (!data.const) {
				data.cr = BASE_CR;
				data.l = 2 * data.cr * data.sin;
		} else {
				data.l = BASE_L;
				data.cr = .5 * data.l / data.sin;
		}

		data.ci = data.cr * data.cos;

		updateBaseSizing();
		updateBasePosition();
		updateLatSizing();
		update3dPosition();
};

var update3dFactor = function() {
		data.k = ~~k_el.value * .01;
		data.kAngle = data.k * (PI - data.polygonAngle);

		updateBaseRot();
		updateLatPosition();
		update3dPosition();
};

/* update graphics */
var updateBasePoly = function() {
		var curr_a, x, y, points_txt = '';

		for (var i = 0; i < (data.n || 3); i++) {
				curr_a = (i - .5) * data.centralAngle - .5 * PI;
				x = data.rAdjusted * cos(curr_a);
				y = data.rAdjusted * sin(curr_a);

				points_txt +=
						round(x) + ',' + round(y) + ' ';
		}

		poly.setAttrs({
				'points': points_txt.trim(),
				'stroke-width': SW
		});
};

var updateLateralN = function() {
		var old_nl = faces.lat.length,
				frag, curr_el;

		if (old_nl > data.n) {
				styles[2] =
						lat_sel + ':nth-child(n + ' +
						(data.n + 3) + '){opacity:.001}';
		} else {
				frag = document.createDocumentFragment();
				styles[2] = '';
		}

		style.textContent = styles.join('');

		for (var i = 0; i < data.n; i++) {
				if (i >= old_nl) {
						curr_el = document.createElement('div');
						curr_el.classList.add(
								lat_sel.replace('.', '')
						);
						faces.lat.push(curr_el);
						frag.appendChild(curr_el);
				}
		}

		if (frag) {
				pos.appendChild(frag);
		}
};

var updateBaseSizing = function() {
		styles[0] = '.prism svg{margin:' + -data.cr + u + ';width:' + 2 * data.cr + u + ';height:' + 2 * data.cr + u + ';transform-origin:50% ' + (data.cr - data.ci) + u + '}';
		style.textContent = styles.join('');
};

var updateLatSizing = function() {
		if (data.h && data.l) {
				styles[1] = lat_sel +
						'{margin:' + -.5 * data.h + u + ' ' + -.5 * data.l + u + ';width:' + data.l + u + ';height:' + data.h + u + ';}';
				style.textContent = styles.join('');
		}
};

var updateBasePosition = function() {
		var ttxt = 'translateY(' +
				(.5 * data.h + data.ci) + u + ')';

		faces.base[0].pos.style.transform = ttxt;
		faces.base[1].pos.style.transform =
				'rotate(.5turn)' + ttxt;
};

var updateBaseRot = function() {
		var rot_a = -data.k * .25;

		faces.base[0].rot.style.transform =
				faces.base[1].rot.style.transform =
				'rotateX(' + rot_a + 'turn)';
};

var updateLatPosition = function() {
		var ttxt = '';

		for (var i = 1; i < data.n; i++) {
				ttxt += 'translate(100%)' +
						'rotateY(' + data.kAngle + 'rad)'

				faces.lat[i].style.transform = ttxt;
		}
};

var update3dPosition = function() {
		var x = -.5 * (data.n - 1) * (1 - abs(data.k)) * data.l + u,
				z = data.k * data.ci + u;
		pos.style.transform = 'translate3d(x,0,z)'
				.replace('x', x).replace('z', z);
};

shapeRotInit();
init();

addEventListener('click', function(e) {
		var t = e.target;

		if (t.tagName.toLowerCase() === 'button') {
				e.preventDefault();
				k_el.value = t.id.split('s')[1] * 100 * rs();
				update3dFactor();
		}
}, false);

k_el.addEventListener('input', update3dFactor, false);
k_el.addEventListener('change', update3dFactor, false);

n_el.addEventListener('input', updateNData, false);
n_el.addEventListener('change', updateNData, false);

h_el.addEventListener('input', updateHeight, false);
h_el.addEventListener('change', updateHeight, false);

const_g.addEventListener('click', function(e) {
		if (e.target.tagName.toLowerCase() == 'label') {
				updateConstCrit();
		}
}, false);

auto_el.addEventListener('change', function() {
		s3d.classList.toggle('auto-rot');
}, false);
              
            
!
999px

Console