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

              
                - var n = 5;
- var dim = 2;

body(style=`--dim: ${dim}` data-dim=dim)
	form
		span.toggle(role='group' aria-label='Switch between 2D and 3D view for the graphics below.')
			- for(var i = 0; i < 2; i++) {
				input(type='radio' name='dim' id=`dim${i}` value=i + 2 checked= dim === i + 2)
				label(for=`dim${i}` style=`--i: ${i}`) #{i + 2}D
			- }
			span.toggle__vis(aria-hidden='true')
	section.scene(role='graphics-document' aria-label='Shows how the shape is made, animating its two components, the pentagonal rotunda and the decagonal antiprism from their 2D nets into their 3D shape.')
		.a3d
			.ppoint
				.s3d.j6
					- for(var i = 0; i < n; i++)
						.s2d.j6__face.lat.s3gon.dir
						.s2d.j6__face.lat.s5gon.dir
						.s2d.j6__face.lat.s3gon.rev
					.s2d.j6__face.base(class=`s${n}gon`)
				.label pentagonal rotunda
			.ppoint
				.s3d.ap10
					- for(var i = 0; i < 2*n; i++)
						.s2d.ap10__face.lat.s3gon.dir
						.s2d.ap10__face.lat.s3gon.rev
					.s2d.ap10__face.base(class=`s${2*n}gon`)
				.label decagonal antiprism
			.label gyroelongated pentagonal rotunda	
              
            
!

CSS

              
                $bg: #323232;
$fg: #f7f7f7;
$c-main: #f44336;
$c-sec: #ff6fff;
$lh: 1.25;

$pen-b: .125em;
$pen-p: .125em;
$pen-r: .25em;
$pen-g: 1vw;

$btn-d: 1em;

$cell-w: $btn-d + $pen-b + $pen-p;

// GEOMETRY
$l: 8vmin; // edge length
$n: 5; // gyroelongated rotunda type (5 = pentagonal)
// lateral face heights
$ba3gon: bc-ang(3);
$ri3gon: in-rad($l, $ba3gon);
$h3gon: poly-h($l, 3);
$ba5gon: bc-ang(5);
$ri5gon: in-rad($l, $ba5gon);
$h5gon: poly-h($l, 5);
// pentagonal diagonal
$d5gon: 2*$l*sin(.5*vx-ang(5));
// base planes
$ba-b0: bc-ang($n); // top base central angle
$ri-b0: in-rad($l, $ba-b0); // top base inradius
$rc-b0: cc-rad($l, $ba-b0); // top base circumradius
$ba-b1: bc-ang(2*$n); // bottom base central angle
$ri-b1: in-rad($l, $ba-b1); // bottom base inradius
$rc-b1: cc-rad($l, $ba-b1); // bottom base circumradius
// mid plane
$rc-d: cc-rad($d5gon, $ba-b0);
$ap-h: cath1($h3gon, $rc-b1 - $ri-b1);
$proj: 2*$rc-b1*sin(.75*$ba-b1);
$cord: hypot($ap-h $proj);

// face background & edge data
$clst: #ff8a00 #da1b60 #9c27b0;
$flst: 3 $n 2*$n;
$llen: length($flst);

$t: 2s;

@mixin poly($n, $ba) {
	--rc: #{cc-rad($l, $ba)};
	--ri: #{in-rad($l, $ba)};
	--poly: #{polygon(get-poly-points($n))};
	
	&:before { --poly: #{polygon(get-poly-points($n, $bw: 2px))} }
}

* { margin: 0 }

body {
	--f3d: calc(var(--dim) - 2);
	--c3d: calc(1 - var(--f3d));
	--q: 0;
	--notq: calc(1 - var(--q));
	display: flex;
	flex-direction: column;
	overflow: hidden;
	min-height: 100vh;
	background: $bg;
	color: $fg;
	font: 1.25em/ #{$lh} consolas, monaco, monospace;
	
	@media (orientation: portrait) { --q: 1	}
}

form {
	padding: .5em 1vw;
	box-shadow: 0 0 7px rgba(#000, .8)
}

.toggle {
	display: grid;
	place-content: center;
	grid-template: 100% / max-content repeat(2, $cell-w) max-content
}

[type='radio'] {
	position: absolute;
	left: -100vw;

	+ label {
		--i: 0;
		--j: calc(1 - var(--i));
		grid-row: 1;
		grid-column: calc(2*var(--i) + 1)/ span 2;
		place-self: center;
		position: relative;
		z-index: 1;
		padding: 0 $pen-r;
		margin: 0 calc(var(--j)*(#{$cell-w} + #{$pen-g})) 
			0 calc(var(--i)*(#{$cell-w} + #{$pen-g}));
		width: max-content;
		border-radius: $pen-r;
		white-space: nowrap;
		cursor: pointer;
		transition: $t;
		
		&:before {
			--cover-w: calc(#{$cell-w} + #{$pen-g});
			position: absolute;
			left: calc(var(--j)*100% - var(--i)*var(--cover-w));
			width: var(--cover-w);
			height: 100%;
			content: ''
		}
		
		&:first-of-type { justify-self: end }
	}
	
	~ [aria-hidden='true'] {
		grid-row: 1;
		grid-column: 2/ span 2;
		place-self: center;
		position: relative;
		z-index: 0;
		border: solid $pen-b $fg;
		padding: $pen-p;
		width: 2*$btn-d; height: $btn-d;
		border-radius: $btn-d;
		color: $c-sec;
		transition: color $t;
		
		&:before {
			position: absolute;
			width: $btn-d; height: $btn-d;
			border-radius: 50%;
			transform: translate(calc(var(--f3d)*100%));
			background: currentcolor;
			transition: transform $t;
			content: ''
		}
	}

	&:checked + label {
		color: $c-sec
	}

	&:focus, &:hover {
		+ label {
			background: $c-main;
			color: $fg
		}

		~ div { color: $c-main }
	}
}

section {
	flex: 1;
	position: relative;
	font: 4vmin satisfy, cursive;
}

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

.a3d {
	--h-rot: #{cath1($h5gon, $ri-b1 - $rc-b0)};
	--h-mid: #{$ap-h};
	--h: calc(var(--h-rot) + var(--h-mid));
	top: 50%; left: 50%;
	transform: scale(calc(var(--f3d) + 1));
	transition: $t
}

@keyframes r { to { transform: rotatey(1turn) } }

.ppoint {
	--p: 0;
	--notp: calc(1 - var(--p));
	--sgnp: calc(1 - 2*var(--p));
	transform: 
		translate(
			calc(var(--c3d)*var(--notq)*var(--sgnp)*5em), 
			calc(var(--c3d)*(var(--q)*1em - var(--sgnp)*25vh))
		);
	perspective: 10em;
	transition: $t;
	
	& + & { --p: 1 }
}

.label {
	width: 100vw;
	transform: 
		translate(-50%, -120%) 
		scale(calc(1/(var(--f3d) + 1)))
		translatey(50vh);
	opacity: var(--f3d);
	text-align: center;
	transition: $t;
	
	.ppoint & {
		width: calc((1 + var(--q))*5em);
		transform: 
			translate(
				calc(var(--c3d)*(var(--notq)*(var(--sgnp)*#{-($rc-b1 + $l)} - var(--notp)*100%) + var(--q)*-50%) - var(--f3d)*var(--sgnp)*100vw), 
				calc(var(--c3d)*(var(--q)*(#{-($rc-b1 + $l)} - 100%) - var(--notq)*50%))
			)
			scale(var(--c3d));
		opacity: var(--c3d);
	}
}

.s3d {
	animation: r calc(var(--f3d)*9s) linear $t infinite
}

@keyframes r {
	0% { transform: rotatex(0deg) rotatey(0deg) }
	20% { transform: rotatex(0deg) rotatey($ba-b0) }
	to { transform: rotatex(1turn) rotatey($ba-b0) }
}

.j6 {
	--j6rax: calc(var(--f3d)*#{-1*to-deg(acos(($rc-d - $ri-b0)/$h3gon))});
		
	&__face {		
		&.lat {
			--lat: 
				rotate(calc(var(--k)*#{$ba-b0} - .5turn)) 
				translatey(#{-$ri-b0})
				rotatex(var(--j6rax))
				var(--det, #{unquote(' ')});
			
			&:not(.s3gon), &:not(.dir) {
				--det: 
					translatey(#{-$ri3gon}) 
					rotate(#{.5*$ba3gon})
					translatey(#{-$ri3gon}) 
					rotatex(var(--j6rax)) 
					var(--fin, #{unquote(' ')})
			}
			
			&.rev {
				--fin: 
					translatey(#{-$ri5gon}) 
					rotate(#{.5*$ba5gon})
					translatey(#{-$ri5gon}) 
					rotatex(var(--j6rax))
			}
			
			@for $k from 0 to $n {
				&:nth-child(n + #{3*$k + 1}) { --k: #{$k} }
			}
		}
	}
}

.ap10 {
	$a: to-deg(acos(($rc-b1 - $ri-b1)/$h3gon));
	
	&__face {		
		&.lat {
			--lat: 
				rotate(calc(var(--k)*#{$ba-b1} - .5turn)) 
				translatey(#{-$ri-b1})
				rotatex(calc(var(--f3d)*#{-1*$a}))
				var(--fin, #{unquote(' ')});
			
			&.rev {
				--fin: 
					translatey(#{-$ri3gon}) 
					rotate(#{.5*$ba3gon})
					translatey(#{-$ri3gon}) 
					rotatex(calc(#{to-deg(acos(.5*(2*$h3gon*$h3gon - $cord*$cord)/$h3gon/$h3gon))} - 180deg))
			}
			
			@for $k from 0 to 2*$n {
				&:nth-child(n + #{2*$k + 1}) { --k: #{$k} }
			}
		}
	}
}

.s2d {
	margin: calc(-1*var(--rc));
	padding: var(--rc);
	transform: 
		translatey(calc(var(--f3d)*var(--sgnp)*-.5*var(--h))) 
		rotatex(calc(var(--f3d)*var(--sgnp)*-90deg)) 
		rotate(calc(var(--f3d)*var(--p)*#{.5*$ba-b1}))
		var(--lat, #{unquote(' ')});
	-webkit-clip-path: var(--poly);
					clip-path: var(--poly);
	transition: $t;
	
	&:before, &:after {
		position: absolute;
		top: 0; right: 0; bottom: 0; left: 0;
		-webkit-clip-path: var(--poly);
						clip-path: var(--poly);
		content: ''
	}
	
	&:before { background: currentcolor }
}

@for $i from 0 to $llen {
	$m: nth($flst, $i + 1);
	
	.s#{$m}gon {
		@include poly($m, bc-ang($m));
		background: rgba(nth($clst, $i + 1), calc(1 - var(--f3d)*.25))
	}
}

.lat {
	margin-top: calc(-1*var(--rc) - var(--ri));
	transform-origin: 50% calc(50% + var(--ri));
}
              
            
!

JS

              
                addEventListener('change', e => {
	document.body.style.setProperty('--dim', document.body.dataset.dim = +e.target.value)
}, false);
              
            
!
999px

Console