123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              - var nlayers = 3

mixin slice3gon(nlayers)
	- var n3gon = 3;
	- var ca3gon = 2*Math.PI/n3gon;
	- var r = .5;
	- var v = []; // vertex coord array
	- for(var i = 0; i < n3gon; i++) {
		- var a = i*ca3gon - .5*Math.PI;
		- var x = r*(1 + Math.cos(a));
		- var y = r*(1 + Math.sin(a));
		- v.push([x, y]);
	- }
	- var p = []; // slice coord array
	- for(var i = 0; i < nlayers; i++) {
		- p.push([]);
		- var j = i/nlayers;
		- var k = (i + 1)/nlayers;
		- var x = (1 - j)*v[0][0] + j*v[1][0];
		- var y = (1 - j)*v[0][1] + j*v[1][1];
		- p[i].push([x.toFixed(5), y.toFixed(5)]);
		- var x = (1 - k)*v[0][0] + k*v[1][0];
		- var y = (1 - k)*v[0][1] + k*v[1][1];
		- p[i].push([x.toFixed(5), y.toFixed(5)]);
		- var x = (1 - k)*v[0][0] + k*v[2][0];
		- var y = (1 - k)*v[0][1] + k*v[2][1];
		- p[i].push([x.toFixed(5), y.toFixed(5)]);
		- if(i > 0) {
			- var x = (1 - j)*v[0][0] + j*v[2][0];
			- var y = (1 - j)*v[0][1] + j*v[2][1];
			- p[i].push([x.toFixed(5), y.toFixed(5)]);
		- }
		clipPath(id=`c${nlayers - i}` clipPathUnits='objectBoundingBox')
			polygon(points=p[i].join(' '))
	- }

svg
	+slice3gon(nlayers)

.a3d
	while nlayers--
		.s3d
			- var nfaces = (nlayers == 0)?4:5;
			while nfaces--
				.s2d

a(href='https://codepen.io/thebabydino/pen/wMvPaQ' target='_blank') see my other layered pyramid
            
          
!
            
              @import 'compass/css3';

$l: 13em; // edge of pyramid
$n-layers: 3; // same as in HTML
$t: 5s; // animation duration

$n-3gon: 3; // 3gon = polygon with 3 edges
$ca-3gon: 360deg/$n-3gon; // central angle
$rc-3gon: .5*$l/sin(.5*$ca-3gon); // circumradius
$ri-3gon: .5*$l/tan(.5*$ca-3gon); // circumradius
$h-3gon: $rc-3gon + $ri-3gon;

$n-4gon: 4; // 4gon = polygon with 4 edges
$ca-4gon: 360deg/$n-4gon; // central angle
$ri-4gon: .5*$l/tan(.5*$ca-4gon); // inradius

$ax-4pyramid: asin($ri-4gon/$h-3gon)*180deg/pi();
$h-4pyramid: sqrt(pow($h-3gon, 2) - pow($ri-4gon, 2));

$texture: url(https://upload.wikimedia.org/wikipedia/commons/2/20/Light_brown_stone_texture.jpg) 50%/cover;
$over: url(https://upload.wikimedia.org/wikipedia/commons/a/a7/Stone_gimp.png) 0/#{$l};
$under: url(https://upload.wikimedia.org/wikipedia/commons/a/a7/Stone_gimp.png) 0/#{$l};

body {
	overflow: hidden;
	height: 100vh;
	perspective: 32em;
	perspective-origin: 50% calc(50% - #{$l});
	background: linear-gradient(#000, #222);
}

.a3d { animation: r $t linear infinite; }
@keyframes r { to { transform: rotateY(1turn) } }

div, :before {
	position: absolute;
	top: 50%; left: 50%;
	transform-style: preserve-3d; // 3D nesting
}

.s3d {
	@for $i from 0 to $n-layers {
		&:nth-child(#{$i + 1}) {
			@if $i > 0 {
				animation: split#{$i + 1} 2*$t ease-in infinite alternate;
				
				@at-root {				
					@keyframes split#{$i + 1} {
						0%, 25% { transform: none; }
						75%, 100% { transform: translateY(($i + 1)*-2em); }
					}
				}
			}
			
			@if $i < $n-layers - 1 {
				$dim: ($n-layers - $i - 1)*$l/$n-layers;
				
				.s2d:last-child {
					margin: -.5*$dim;
					width: $dim; height: $dim;
					transform: translateY($ri-3gon - ($i + 1)/$n-layers*$h-4pyramid)
						rotateX(90deg);
				}
			}
			
			.s2d:nth-child(-n + #{$n-4gon}) {
				clip-path: url(#c#{$i + 1});
			}
		}
	}
}

.s2d {
	overflow: hidden;
	backface-visibility: hidden;
	background: $texture;
	
	&:before {
		margin: inherit;
		width: inherit; height: inherit;
		background: #000;
		content: '';
	}
	
	&:nth-child(-n + #{$n-4gon}) {
		margin: -$rc-3gon;
		width: 2*$rc-3gon; height: 2*$rc-3gon;
		transform-origin: 50% $h-3gon;
		background: $texture, $over, $under;
		background-blend-mode: lighten;
		animation: shine $t/$n-4gon linear infinite;
		
		&:before {
			opacity: .01;
			animation: shade .5*$t linear infinite alternate;
		}
	}
	
	&:nth-child(#{$n-4gon + 1}):before {
		opacity: .85;
		transform: scale(.95);
		animation: shadow 2*$t ease-in infinite alternate;
	}
	
	@for $i from 0 to $n-4gon {
		&:nth-child(#{$i + 1}) {
			transform: rotateY($i*$ca-4gon) 
				translateZ($ri-4gon) 
				rotateX($ax-4pyramid);
			
			&:before { animation-delay: -.25*$i*$t; }
		}
	}
}

@keyframes shine {
	to { background-position: 50%, -$l, -3*$l; }
}

@keyframes shade { to { opacity: .75; } }
@keyframes shadow { to { filter: blur(1.5em) } }

a {
	position: absolute;
	top: 1em; left: 1em;
	color: lime;
	font: 1em trebuchet ms, verdana, sans-serif;
}
            
          
!
            
              /* 
This demo (and a lot of other recent 3D demos I've done) uses `clip-path` on HTML elements, currently not supported in IE/ Edge. 

If you like my 3D stuff, please vote for `clip-path` on HTML elements to be implemented in Edge https://wpdev.uservoice.com/forums/257854-microsoft-edge-developer/suggestions/6519995-support-clip-path-property
*/
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console