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

              
                <button class="hidden" id="turnRight"></button>
<button class="hidden" id="turnLeft"></button>
<input type="checkbox" class="hidden" id="shot">
<button class="hidden" id="cannonMove"></button>

<div class="controls">
  <p>Scene</p>
  <div class="controls_smallLabels">
    <label for="turnLeft"><<</label>
    <label for="turnRight">>></label>
  </div>
  <p class="controls_cannonText">Cannon</p>
  <label for="cannonMove" class="controls_cannonMove">Angle<small>(click and hold)</small></label>
  <label for="shot" class="controls_shot"></label>
</div>
<div class="game">
  <div class="rotateRight">
    <div class="rotateLeft">
      <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: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;

}

.game {
  position: relative;
  perspective: 50vw;
  perspective-origin: 50% -5vw;
}

.rotateRight {
  animation: sceneRotateX 10s -1s infinite linear paused;
}

.rotateLeft {
  animation: sceneRotateX 10s infinite linear paused reverse;
}

@keyframes sceneRotateX {
  from { transform: rotateY(0deg); }
  to { transform: rotateY(360deg); }
}

.player {
  position: absolute;
  right: -15vw; bottom: -10vw;

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

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

    &-front {
      background-color: #666;
      width: 4vw; height: 2vw;
      transform: translateZ(1.5vw);
    }
    &-right {
      background-color: #666;
      width: 3vw; height: 2vw;
      transform: rotateY(90deg) translateZ(2.5vw);
    }
    &-back {
      background-color: #666;
      width: 4vw; height: 2vw;
      transform: rotateY(180deg) translateZ(1.5vw);
    }
    &-left {
      background-color: #666;
      width: 3vw; height: 2vw;
      transform: rotateY(270deg) translateZ(1.5vw);
    }
    &-top {
      background-color: #999;
      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: #000;
        box-shadow: 0 0 0.25vw 0.25vw #000;
      }
    }
    &-bottom {
      background-color: #111;
      width: 4vw; height: 3vw;
      transform: rotateX(90deg) translateZ(-0.45vw);
      box-shadow: 0 0 0.5vw 0.5vw #111;
    }
  }

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

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

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

    &-front {
      background-color: #666;
      transform: translateZ(0.5vw);
    }
    &-top {
      background-color: #999;
      transform: rotateX(90deg) translateZ(0.5vw);
    }
    &-back {
      background-color: #666;
      transform: rotateX(180deg) translateZ(0.5vw);
    }
    &-bottom {
      background-color: #333;
      transform: rotateX(270deg) translateZ(0.5vw);
    }
  }
}

$cubeSpeed: 4s;
.cube {

  &_container {
    position: absolute;
    right: -16.5vw; bottom: -10vw;
    width: 42vw; height: 5vw;

    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;
  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%, calc(-50% + 10vw)) rotateX(90deg);
}

// CONTROL

.hidden {
  position: fixed;
  top: -100vh; left: -100vw;
}

#turnRight {

  &:active ~ .game .rotateRight {
    animation-play-state: running;
  }
}

#turnLeft {
  &:active ~ .game .rotateLeft {
    animation-play-state: running;
  }
}

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

#shot {

  & ~ .controls .controls_shot::after {
    content: 'Shot';
  }

  &:checked {

    & ~ .controls .controls_shot {
      animation: shotText $cubeSpeed;
      background-color: #fed;

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

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

    & ~ .controls .controls_cannonText {
      animation: shotText $cubeSpeed;
    }
    & ~ .controls .controls_cannonMove {
      display: none;
    }

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

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

.controls {
  position: fixed;
  top: 0; right: 0;
  padding: 1em 2em 0;
  text-align: center;
  width: 11em;

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

  & label {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #fff;
    color: #000;
    border: 1px solid #fff;
    transition: all 0.25s;
    margin: 0.25em 0;
    user-select: none;

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

  &_smallLabels {
    display: flex;
    justify-content: space-between;

    & label {
      width: 3em; height: 3em;
    }
  }

  &_cannonMove {
    height: 3em;
    flex-direction: column;
  }

  &_shot {
    height: 3em;
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console