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

              
                <body>
  <input type="checkbox" id="playPause" name="playPause">
  <label class="playBtn" for="playPause">
    <div></div>
    <div></div>
  </label>
  <div id="scene">
    <div id="dhedron">
      <div class="pentagon">
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
      </div>
      <div class="pentagon">
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
      </div>
      <div class="pentagon">
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
      </div>
      <div class="pentagon">
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
      </div>
      <div class="pentagon">
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
      </div>
      <div class="pentagon">
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
      </div>
      <div class="pentagon">
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
      </div>
      <div class="pentagon">
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
      </div>
      <div class="pentagon">
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
      </div>
      <div class="pentagon">
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
      </div>
      <div class="pentagon">
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
      </div>
      <div class="pentagon">
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
        <div class="hinge">
          <div class="triangle"></div>
        </div>
      </div>
    </div>
  </div>
</body>
              
            
!

CSS

              
                body {
  margin: 0;
  background: #000;
  display: grid;
  min-height: 100vh;
  animation: crawl 3s ease-in-out alternate infinite;
  max-height: 100vh;
  overflow: hidden;
  font-size: 40vh;
  }

#scene {
  width: 1em;
  height: 1em;
  place-self: center;
  perspective: 1em;
  animation: hue 10s linear infinite;
        filter: drop-shadow(0 0 3vw #086);
  }

#scene * {
  transform-style: preserve-3d;
  }

#dhedron {
  display: grid;
  width: 100%;
  height: 100%;        
  position: relative;
  animation: spin 8s linear infinite;
    }

@keyframes spin {
  100% {
    transform: rotateY(360deg) rotateX(360deg);
        }
    }

.pentagon {
  position: absolute;
  width: 50%;
  height: 50%;
  place-self: center;
  transform-origin: center;
  transform: rotate(calc( var(--sideUp)*180deg )) rotateY(calc(var(--turnY)*72deg)) rotateX(calc( var(--turnX) + var(--flip) ) ) translateZ(calc( -.324em ));
    }


.pentagon:nth-child(1) {
  --pChild: 1;
  }
    
.pentagon:nth-child(2) {
  --pChild: 2;
  }
    
.pentagon:nth-child(3) {
  --pChild: 3;
  }
    
.pentagon:nth-child(4) {
  --pChild: 4;
  }
    
.pentagon:nth-child(5) {
  --pChild: 5;
  }
    
.pentagon:nth-child(6) {
  --pChild: 6;
  }
    
.pentagon:nth-child(7) {
  --pChild: 7;
  }
    
.pentagon:nth-child(8) {
  --pChild: 8;
  }
    

.pentagon:nth-child(9) {
  --pChild: 9;
  }
    

.pentagon:nth-child(10) {
  --pChild: 10;
  }
    
.pentagon:nth-child(11) {
  --pChild: 11;
  }
    

.pentagon:nth-child(12) {
  --pChild: 12;
  }
    

.pentagon:nth-child(1), .pentagon:nth-child(2) {
  --sideUp: 1;
  --turnY: 0;
  --turnX: 90deg;
  }

.pentagon:nth-child(3), .pentagon:nth-child(4)  {
  --turnY: 0;
  }

.pentagon:nth-child(5), .pentagon:nth-child(6)  {
  --turnY: 1;
  }

.pentagon:nth-child(7), .pentagon:nth-child(8)  {
  --turnY: 2;
  }

.pentagon:nth-child(9), .pentagon:nth-child(10)  {
  --turnY: 3;
  }

.pentagon:nth-child(11), .pentagon:nth-child(12)  {
  --turnY: 4;
  }

.pentagon:not(:nth-child(1)).pentagon:not(:nth-child(2)) {
  --sideUp: 0;
  --turnX: 26.565051177078deg;
}

.pentagon:nth-child(2n+1) {
  --flip: 0deg;
  }
    
.pentagon:nth-child(2n) {
  --flip: 180deg;
}

.pentagon .hinge {
  animation-delay: calc(-1s + var(--pChild) * -.125s );
  }

.hinge {
  position: absolute;
  bottom: 50%;
  right: calc(50% - (58.778525229247%)/2);
  height: 40.450849718747%;
  width: 58.778525229247%;
  transform-origin: 50% 100%;
  animation: pivot 2s linear infinite alternate;
  }

@keyframes pivot {
  0% {
    transform: rotate(calc(var(--child)*72deg)) translateY(100%) rotateY(-90deg) skewX(0deg);
   }
  66.66%, 100% {
    transform: rotate(calc(var(--child)*72deg)) translateY(100%) rotateY(-90deg) skewX(calc(90deg - 26.565051177078deg));
    }
  }

.hinge:nth-child(1) {
  --child: 1;
  }

.hinge:nth-child(2) {
  --child: 2;
  }

.hinge:nth-child(3) {
  --child: 3;
  }

.hinge:nth-child(4) {
  --child: 4;
  }

.hinge:nth-child(5) {
  --child: 5;
  }

@keyframes rainbow {
  0%,100% {
    background: #f00;
    background-image: var(--grad), var(--grad);    
    }
  16.66% {
    background: #ff0;
    background-image: var(--grad), var(--grad);
    }
  33.33% {
    background: #0f0;
    background-image: var(--grad), var(--grad);    
    }
  50% {
    background: #0ff;
    background-image: var(--grad), var(--grad);    
    }
  66.66% {
    background: #00f;
    background-image: var(--grad), var(--grad);    
    }
  83.33% {
    background: #f0f;
    background-image: var(--grad), var(--grad);    
    }
  }

.triangle {
  position: absolute;
  inset: 0;
  animation: rainbow 3s linear infinite, hypno 3s linear infinite;
  clip-path: polygon(50% -1px, -1px 100%, calc(100% + 1px) 100%);
  transform: rotateY(90deg);
  padding: 0px;
  --grad: repeating-linear-gradient(#000 0 16.66%,#0000 16.66% 33.33%);
  }

@keyframes hypno {
  0% {
    background-position-y: 0, 0;
    }
  100% {
    background-position-y: -3.33vw, 0;
    }
  }

#playPause {
  display: none;
}

.playBtn {
  position: absolute;
  display: grid;
  grid-template-rows: 1.5fr 1fr;
  width: .4em;
  aspect-ratio: 1;
  perspective: 1px;
  perspective-origin: 100% 50%;
  transition: all .3s cubic-bezier(1, 0, 0.24, 1);
  margin: .1em;
  filter: drop-shadow(0 0 0 #f0f);
  mask-image: repeating-conic-gradient(at 30% -30%, transparent 0 5deg, black 5deg 12deg);
}

.playBtn:after {
  content: '';
  position: absolute;
  inset: 0;
}

.playBtn:hover {
  filter: drop-shadow(0 0 .07em #f0f);
}

.playBtn div {
  transform-origin: 0 ;
  transition: inherit;
}

.playBtn div:nth-child(1) {
  background-color: red;
}

.playBtn div:nth-child(2) {
  background: blue;
}

#playPause:not(:checked) ~ .playBtn {
}

#playPause:checked ~ .playBtn {
  rotate: 90deg;
}

#playPause:not(:checked) ~ .playBtn div {
  rotate: y 25deg;  
}

#playPause:checked ~ .playBtn div:nth-child(1) {
  margin-bottom: 25%;
  background-color: yellow;
}

#playPause:checked ~ .playBtn div:nth-child(2) {
  background-color: lime;
}

#playPause:not(:checked) ~ #scene :is(#dhedron, .hinge, .triangle) {
  animation-play-state: paused;
}

@media (orientation: portrait) {
  body {
    font-size: 50vw;
  }
}
              
            
!

JS

              
                /*

The dodecahedron has been a sort of unholy Grail of mine. Took some mental gymnastics to figure out the geometry -- all on my own, without looking into predefined formulas. And then I decided it'd look even cooler with spikes - like a 3D pentagram. Once I had the geometry down, I fell down the rabbit hole of hypnotic, gradient-based f/x. Drove me to insanity, and then some - at which point I dropped the whole thing and went on to work on the pumpkin. But it's been bugging me since. So I decided to do a whole series, trying out different f/x with each - both the spiky thing and the bare dodecahedron, which is a fascninating shape on its own and holds much promise even in its most basic, static form. And that's just the tip of the iceberg! More to come!

There is some ugly CSS repetition in the gradients' keyframes. Apparently background and background-image can't be animated separately, so I had to repeat the whole sequence for all 6 keypoints. Thank goodness for vars, they made it just a bit less clunky. Speaking of which, I'm so looking forward to @property, that's going to make things so much easier.

*/
              
            
!
999px

Console