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

              
                <!-- Hidden inputs -->

<button class="hidden" id="turnLeft"></button>
<button class="hidden" id="turnRight"></button>
<button class="hidden" id="cannonAngle"></button>
<input  class="hidden" id="shoot" type="checkbox">

<!-- Controllers layer -->

<div class="controllers">
  
  <p>Scene</p>
  <div class="controllers_smallLabels">
    <label for="turnLeft"><<</label>
    <label for="turnRight">>></label>
  </div>
  
  <div class="controllers_cannon">
    <p>Cannon</p>
    <label for="cannonAngle"  class="controllers_cannonAngle">Angle<br><small>(click and hold)</small></label>
    <label for="shoot" class="controllers_shoot"></label>   
  </div> 

</div>

<!-- Game elements -->

<div class="game">
  <div class="cameraRotate_left">
    <div class="cameraRotate_right">

      <div class="player">
        <div class="player_base">
          <div class="player_base-top"></div>
          <div class="player_base-bottom"></div>
          <div class="player_base-front"></div>
          <div class="player_base-back"></div>
          <div class="player_base-left"></div>
          <div class="player_base-right"></div>
        </div>
        <div class="player_cannon">
          <div class="player_cannon-top"></div>
          <div class="player_cannon-bottom"></div>
          <div class="player_cannon-front"></div>
          <div class="player_cannon-back"></div>
        </div>
      </div>
      
      <div class="cube_container">
        <div class="cube">
          <div></div><div></div><div></div><div></div><div></div>
          <div></div><div></div><div></div><div></div><div></div>
          <div></div><div></div><div></div><div></div><div></div>
          <div></div><div></div><div></div><div></div><div></div>
          <div></div><div></div><div></div><div></div><div></div>
          <div></div><div></div><div></div><div></div><div></div>
          <div></div><div></div><div></div><div></div><div></div>
          <div></div><div></div><div></div><div></div><div></div>
          <div></div><div></div><div></div><div></div><div></div>
          <div></div><div></div><div></div><div></div><div></div>
          <div></div><div></div><div></div><div></div>
        </div>

      </div>
      
      <div class="floor"></div>

    </div>
  </div>
</div>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Open+Sans&display=swap');

*, *::before, *::after {
  padding: 0;
  margin: 0 auto;
  box-sizing: border-box;
  transform-style: preserve-3d;
}

body {
  font-family: 'Open Sans', sans-serif;
  background-color: #000;
  color: #fff;
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
}

// Hidden inputs

.hidden {
  position: fixed;
  top: -100vh; left: -100vw;
  appearance: none;
  background: none;
  border: none;
}

// Controllers layer

.controllers {
  position: fixed;
  top: 1em; right: 2em;
  text-align: center;
  width: 8em;

  & p {
    margin-top: 1em;
    text-decoration: underline;
  }

  & label {
    display: block;
    width: 100%;
    background-color: #222;
    color: #fff;
    border: 1px solid #fff;
    margin: 0.5em 0;
    user-select: none;
    line-height: 1;
    padding: 0.5em 0;
    transition: all 0.25s;

    &:hover {
      background-color: #444;
    }

    &:active {
      background-color: #fff;
      color: #000;
    }
  }

  &_smallLabels {
    display: flex;
    justify-content: space-between;
  }
  
  label.controllers_shoot {
    padding: 1em 0;

    &::after {
      content: 'Shoot';
    }
  }
}

// Game Layer

.game {
  position: relative;
  perspective: 50vw;
}

.cameraRotate {
  
  &_left {
    animation: sceneRotateX 10s -9s infinite linear paused;
  }

  &_right {
    animation: sceneRotateX 10s infinite linear paused reverse;
  }
  
  @keyframes sceneRotateX {
    from { transform: rotateY(0deg); }
    to { transform: rotateY(-360deg); }
  }
}

.player {
  position: absolute;
  right: -15vw; bottom: -10vw;
  $playerColor: #777;

  &_base {
    width: 4vw; height: 2vw;
    position: absolute;
    left: -2vw; bottom: 0;

    & > * {
      position: absolute;
      box-shadow: 0 0 1vw #000 inset;
      background-color: $playerColor;
    }

    &-front {
      width: 4vw; height: 2vw;
      transform: translateZ(1.5vw);
    }
    &-right {
      width: 3vw; height: 2vw;
      transform: rotateY(90deg) translateZ(2.5vw);
    }
    &-back {
      width: 4vw; height: 2vw;
      transform: rotateY(180deg) translateZ(1.5vw);
    }
    &-left {
      width: 3vw; height: 2vw;
      transform: rotateY(270deg) translateZ(1.5vw);
    }
    &-top {
      width: 4vw; height: 3vw;
      transform: rotateX(90deg) translateZ(1.5vw);

      &::after {
        content: '';
        position: absolute;
        top: 1vw; left: 0.5vw;
        width: 3vw; height: 1vw;
        background-color: #222;
        box-shadow: 0 0 0.25vw 0.25vw #000;
      }
    }
    &-bottom {
      width: 4vw; height: 3vw;
      transform: rotateX(90deg) translateZ(-0.45vw);
      box-shadow: 0 0 0.5vw 0.25vw #000;
    }
  }

  &_cannon {
    width: 5vw; height: 1vw;
    position: absolute;
    right: -1.5vw; bottom: 1vw;
    transform-origin: top right;
    animation: cannonAngle 3s -1.5s infinite ease-in-out alternate paused;

    @keyframes cannonAngle {
      from { transform: rotateZ(20deg); }
      to   { transform: rotateZ(70deg); }
    }

    & > * {
      position: absolute;
      box-shadow: 0 0 0.5vw #000 inset;
      width: 100%; height: 100%;
    }

    &-front {
      background-color: lighten($playerColor, 5%);
      transform: translateZ(0.5vw);
    }
    &-top {
      background-color: lighten($playerColor, 20%);
      transform: rotateX(90deg) translateZ(0.5vw);
    }
    &-back {
      background-color: lighten($playerColor, 5%);
      transform: rotateX(180deg) translateZ(0.5vw);
    }
    &-bottom {
      background-color: darken($playerColor, 20%);
      transform: rotateX(270deg) translateZ(0.5vw);
    }
  }
}

$cubeSpeed: 4s;
.cube {

  &_container {
    position: absolute;
    right: -16.5vw; bottom: -10vw;
    animation: cubeContainer 3s -1.5s infinite ease-in-out alternate paused;

    @keyframes cubeContainer {
      from { width: 50vw; height: 6vw; }
      to   { width: 25vw; height: 20vw; }
    }
  }

  position: absolute;
  right: 0.3vw; bottom: 1.4vw;
  width: 0.3vw; height: 0.3vw;

  @keyframes cubeTrasform {
    0%, 5% { transform: scale(0); }
    8% { transform: scale(1); }
    70%, 100% { transform: scale(1) rotateX(1080deg) rotateY(1080deg);}
  }

  @keyframes cubeRight {
    0% { right: 0; }
    70%, 100% { right: 100%; }
  };

  @keyframes cubeBottom {
    0% { bottom: 2vw; }
    35% { bottom: 100%; animation-timing-function: ease-in; }
    70%, 100% { bottom: 0; }
  };

  @keyframes cubeExplode {
    0%, 70% {
      transform: translate3d(0, 0, 0) rotateX(var(--rx, 0)) rotateY(var(--ry, 0)) rotateZ(var(--rz, 0)) translate3d(var(--tx, 0), var(--ty, 0), var(--tz, 0));
      opacity: 1;
    }
    100% {
      transform: translate3d(var(--ntx), var(--nty), var(--ntz)) rotateX(var(--nrx)) rotateY(var(--nry)) rotateZ(var(--nrz)) translate3d(0, 0, 0);
      opacity: 0;
    }
  }

  & > div {
    position: absolute;
    width: 100%; height: 100%;
    background-color: hsl(var(--hue), 100%, 60%);
    --tz: 0.45vw;

    @for $i from 1 through 54 {
      &:nth-child(#{$i}) {
        --hue: #{random(360)};
        --ntx: #{2.5 - random(10)}vw;
        --nty: #{-2 - random(8)}vw;
        --ntz: #{5 - random(10)}vw;
        --nrx: #{random(360)}deg;
        --nry: #{random(360)}deg;
        --nrz: #{random(360)}deg;
      }
    }

    &:nth-child(9n + 1)     {
      --tx: -100%; --ty: -100%;
      background-image: radial-gradient(circle at 150% 150%, #0000, #0008 0.5vw); 
    }
    &:nth-child(9n + 2) {
      --tx: 0%; --ty: -100%;
      background-image: radial-gradient(circle at 50% 150%, #0000, #0008 0.5vw); 
    }
    &:nth-child(9n + 3) {
      --tx: 100%; --ty: -100%;
      background-image: radial-gradient(circle at -50% 150%, #0000, #0008 0.5vw); 
    }
    &:nth-child(9n + 4) {
      --tx: -100%; --ty: 0%;
      background-image: radial-gradient(circle at 150% 50%, #0000, #0008 0.5vw); 
    }
    &:nth-child(9n + 5) {
      --tx: 0%; --ty: 0%;
      background-image: radial-gradient(circle at 50% 50%, #0000, #0008 0.5vw); 
    }
    &:nth-child(9n + 6) {
      --tx: 100%; --ty: 0%;
      background-image: radial-gradient(circle at -50% 50%, #0000, #0008 0.5vw); 
    }
    &:nth-child(9n + 7) {
      --tx: -100%; --ty: 100%;
      background-image: radial-gradient(circle at 150% -50%, #0000, #0008 0.5vw); 
    }
    &:nth-child(9n + 8) {
      --tx: 0%; --ty: 100%;
      background-image: radial-gradient(circle at 50% -50%, #0000, #0008 0.5vw);
    }
    &:nth-child(9n + 9) {
      --tx: 100%; --ty: 100%;
      background-image: radial-gradient(circle at -50% -50%, #0000, #0008 0.5vw); 
    }

    &:nth-child(n + 10):nth-child(-n + 18) { --ry: 90deg; }
    &:nth-child(n + 19):nth-child(-n + 27) { --ry: 180deg; }
    &:nth-child(n + 28):nth-child(-n + 36) { --ry: 270deg; }
    &:nth-child(n + 37):nth-child(-n + 45) { --rx: 90deg; }
    &:nth-child(n + 46):nth-child(-n + 54) { --rx: 270deg; }
  }
}

.floor {
  position: absolute;
  top: 10vw;
  width: 100vw; height: 100vw;
  background-color: #222;
  background-image:
    radial-gradient(#0000, #000 66%),
    linear-gradient(0deg, #444 1px, #0000 1px),
    linear-gradient(90deg, #444 1px, #0000 1px);
  background-size: 100%, 2vw 2vw, 2vw 2vw;
  transform: translate(-50%, -50%) rotateX(90deg);
}

// Controllers action

#turnLeft:active ~ .game .cameraRotate_left,
#turnRight:active ~ .game .cameraRotate_right {
  animation-play-state: running;
}

#cannonAngle:active ~ .game .player_cannon,
#cannonAngle:active ~ .game .cube_container {
  animation-play-state: running;
}

#shoot:checked {

  & ~ .controllers .controllers_shoot {
    background-color: #fff;
    color: #000;

    &::after {
      content: 'Reload';
    }
  }

  & ~ .controllers .controllers_cannon {
    animation: disableControllers $cubeSpeed;

    @keyframes disableControllers {
      0%, 100% {
        pointer-events: none;
        opacity: 0;
      }
    }
  }

  & ~ .game .cube {
    animation:
      cubeTrasform $cubeSpeed ease-in,
      cubeRight $cubeSpeed linear,
      cubeBottom $cubeSpeed ease-out;

    & > div {
      animation: cubeExplode $cubeSpeed ease-out;
    }
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console