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

              
                 <div class="container">
    <div class="turret">
      <div class="antenna-container">
        <div class="left antenna">
          <div class="part top"></div>
          <div class="part middle"></div>
          <div class="part bottom"></div>
        </div>
        <div class="right antenna"></div>
      </div>
      <div class="body-container">
        <div class="left part">
          <div class="chassis-container"></div>
          <div class="weapon-container"></div>
          <div class="arm"></div>
        </div>
        <div class="body">
          <div class="body-top"></div>
          <div class="body-core"></div>
        </div>
        <div class="right part">
          <div class="chassis-container"></div>
          <div class="weapon-container"></div>
          <div class="arm"></div>
        </div>
        <div class="eye-container">
          <div class="eye blink">
            <div class="iris">
              <div class="pupil"></div>
            </div>
            <div class="lid-top"></div>
            <div class="lid-bottom"></div>
          </div>
          <div class="line"></div>
        </div>
      </div>
      <div class="legs-container">
        <div class="top">
          <div class="left tube"></div>
          <div class="right tube"></div>
        </div>
        <div class="left leg"></div>
        <div class="middle leg"></div>
        <div class="right leg"></div>
        <div class="left chassis"></div>
        <div class="right chassis"></div>
      </div>
    </div>
  </div>

<div class="created">
  <span>Created by</span>
  <a href="https://manz.dev/"><h2>Manz.dev</h2></a>
  <p>on <a href="https://twitch.tv/ManzDev">Twitch</a> / <a href="https://youtu.be/7t5e_aTi4Wo">Youtube</a></p>
</div>
              
            
!

CSS

              
                @use postcss-nested;

:root {
  --turret-body-color: #eee;
  --turret-border-color: #3b3630;
  --turret-border-filter: drop-shadow(3px 0 0 var(--turret-border-color)) drop-shadow(0 3px 0 var(--turret-border-color)) drop-shadow(-3px 0 0 var(--turret-border-color)) drop-shadow(0 -3px 0 var(--turret-border-color));
  --turret-eye-gradient:
    radial-gradient(#df0a0a 30%, transparent 55%),
    repeating-conic-gradient(#c70a0a 1% 3%, #222 4% 5%);
}

.container {
  display: flex;
  justify-content: center;
  margin-top: 4em;
}

.turret {
  width: 225px;
  height: 325px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: rotate(var(--turret-rotate, 0));

  & .antenna-container {
    position: absolute;
    width: 40px;
    height: 45px;
    transform: translateY(-45px);
    display: flex;
    justify-content: center;
    align-items: flex-end;

    & .left.antenna {
      width: 20px;
      height: 40px;

      & .part {
        width: 4px;
        height: 20px;
        border-radius: 5px;
        background: var(--turret-border-color);
        position: absolute;
        left: 10px;

        &.top {
          transform: translate(15px, 0);
        }

        &.middle {
          transform: translate(8px, 12px) rotate(64deg);
        }

        &.bottom {
          transform: translate(0, 25px);
        }
      }
    }

    & .right.antenna {
      width: 4px;
      height: 15px;
      border-radius: 4px;
      position: relative;
      left: -3px;
      background: var(--turret-border-color);
    }
  }

  & .body-container {
    width: 100%;
    height: 225px;
    display: flex;
    justify-content: center;
    align-items: flex-end;

    & .part {
      border-left: 20px solid var(--turret-body-color);
      width: 40px;
      height: 175px;
      border-radius: 50% 0 0 50% / 70% 0 0 70%;
      position: relative;
      filter: var(--turret-border-filter);
      transform: translateX(60px);
      display: flex;
      align-items: center;
      transition: transform 0.5s;

      &.open {
        transform: translateX(0);
      }

      &.right {
        transform: translateX(-60px) scaleX(-1);

        &.open {
          transform: translateX(0) scaleX(-1);
        }
      }

      & .chassis-container {
        background: var(--turret-body-color);
        width: 16px;
        height: 172px;
        clip-path: polygon(0 0, 100% 25%, 100% 98%, 0 100%);
        transform: translateX(-1px);
      }

      & .weapon-container {
        width: 20px;
        height: 60px;
        border-radius: 0 8px 8px 0;
        background: #282829;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;

        &::before {
          content: "";
          display: block;
          width: 10px;
          height: 10px;
          border-radius: 50%;
          border: 4px solid #333;
          background: #111;
        }

        &::after {
          content: "";
          display: block;
          width: 7px;
          height: 7px;
          border-radius: 50%;
          border: 4px solid #333;
          background: #111;
          margin-top: 6px;
        }
      }

      & .arm {
        position: absolute;
        z-index: -1;
        width: 60px;
        height: 10px;
        background: linear-gradient(#555 45%, #444 50%);
      }
    }

    & .body {
      width: 125px;
      height: 225px;
      display: flex;
      flex-direction: column;
      justify-content: flex-end;
      align-items: center;
      position: relative;
      z-index: 5;
      filter: var(--turret-border-filter);

      /* Central line */
      &::before {
        position: absolute;
        top: 0;
        z-index: 5;
        content: "";
        display: block;
        width: 4px;
        height: 100%;
        background: var(--turret-border-color);
      }

      & .body-top {
        position: absolute;
        top: 0;
        background: var(--turret-body-color);
        width: 100px;
        height: 200px;
        border-radius: 50%;
        clip-path: polygon(0 0, 100% 0, 100% 20%, 80% 35%, 20% 35%, 0 20%);
      }

      & .body-core {
        background: var(--turret-body-color);
        width: 75px;
        height: 200px;
        border-radius: 50%;
      }
    }

    & .eye-container {
      position: absolute;
      width: 55px;
      height: 55px;
      background: conic-gradient(#aaa 25%, #fff 35% 80%, #aaa 90%);
      border-radius: 50%;
      z-index: 10;
      transform: translateY(-70px);
      display: flex;
      justify-content: center;
      align-items: center;

      & .line {
        position: absolute;
        top: 0;
        z-index: 5;
        content: "";
        display: block;
        width: 4px;
        height: 100%;
        background: var(--turret-border-color);
      }

      & .eye {
        width: 35px;
        height: 35px;
        border: 3px solid var(--turret-border-color);
        border-radius: 50%;
        position: relative;
        z-index: 10;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: hidden;
        background-color: #222;

        & .iris {
          border-radius: 50%;
          position: absolute;
          width: 100%;
          height: 100%;
          background: var(--turret-eye-gradient);
          display: flex;
          justify-content: center;
          align-items: center;
          transform: translate(var(--x, 0), var(--y, 0));
          transition: transform 0.25s;

          & .pupil {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            background: #222;
            background: radial-gradient(#222 80%, transparent 80%);

            /* filter: drop-shadow(0 0 3px #222); */
          }
        }

        &.blink .lid-top {
          animation: topBlink 2s ease infinite alternate;
        }

        &.blink .lid-bottom {
          animation: bottomBlink 2s ease infinite alternate;
        }

        & .lid-top,
        & .lid-bottom {
          content: "";
          display: block;
          position: absolute;
          background: var(--turret-body-color);
          width: 100%;
          height: 50%;
          left: 0;
          right: 0;
          z-index: 20;
        }

        & .lid-top {
          border-bottom: 2px solid var(--turret-border-color);
          top: 0;
        }

        & .lid-bottom {
          border-top: 2px solid var(--turret-border-color);
          bottom: 0;
        }
      }
    }
  }

  & .legs-container {
    width: 150px;
    height: 100px;
    margin: auto;
    display: flex;
    justify-content: space-around;
    filter: var(--turret-border-filter);

    & .top {
      position: absolute;
      width: 80px;
      height: 20px;
      background: #333;
      z-index: 5;

      & .tube {
        position: absolute;
        border: 10px solid #444;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        clip-path: polygon(0 0, 50% 0, 50% 50%, 0 50%);

        &.left {
          transform: translate(-25px, -48px) scale(-1, -1);
        }

        &.right {
          transform: translate(35px, -48px) scale(1, -1);
        }
      }
    }

    & .leg {
      width: 20px;
      height: 100px;
      background: linear-gradient(to bottom, #484848 40%, #656769 42%);
      clip-path: polygon(0 0, 100% 0, 100% 75%, 50% 100%, 0 75%);
      position: relative;

      &.left {
        transform: rotate(25deg);
        z-index: 6;
      }

      &.middle {
        transform: translateY(-15px);
      }

      &.right {
        transform: rotate(-25deg);
        z-index: 6;
      }
    }

    & .chassis {
      position: absolute;
      width: 32px;
      height: 32px;
      background: linear-gradient(#ccc 25%, var(--turret-body-color) 35%);
      border-radius: 25px 25px 5px 5px / 10px 10px 30px 30px;
      z-index: 6;

      &.left {
        top: -8px;
        left: 28px;
        transform: rotate(25deg);
      }

      &.right {
        top: -8px;
        right: 28px;
        transform: rotate(-25deg);
      }
    }
  }
}

@keyframes topBlink {

  0%,
  85% {
    transform: translateY(-20px);
  }

  100% {
    transform: translateY(0);
  }
}

@keyframes bottomBlink {

  0%,
  85% {
    transform: translateY(20px);
  }

  100% {
    transform: translateY(1px);
  }
}

.created {
  background: 
    url(https://assets.codepen.io/154065/internal/avatars/users/default.png),
    linear-gradient(to bottom, #884ced, #ec1cce);
  background-size: 75px 75px, cover;
  background-repeat: no-repeat;
  position: absolute;
  top: 0;
  right: 0;
  width: 250px;
  height: 75px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-left: 2em;
  
  & span,
  & h2,
  & p,
  & a {
    font-family: Montserrat;
    margin: 0;
  }
  
  & a,
  & p,
  & span {
    color: #fff;    
  }
  
  & h2 {
    font-weight: 700;
    transform: translate(0, -4px);    
  }
  
  & a {
    text-decoration-color: rgba(255,255,255,0.4);
  }
  
  & a:hover {
    color: #e6e82a;
  }
}
              
            
!

JS

              
                const turret = document.querySelector(".turret");
const leftPart = document.querySelector(".body-container .left.part");
const rightPart = document.querySelector(".body-container .right.part");
const iris = document.querySelector(".iris");
const sounds = {
  turretFire: new Howl({
    src: ["https://manzdev.github.io/twitch-turret/turret-fire.ogg"],
    loop: true
  }),
  turretHola: new Howl({
    src: ["https://manzdev.github.io/twitch-turret/turret-hola.mp3"]
  }),
  turretHayAlguienAhi: new Howl({
    src: ["https://manzdev.github.io/twitch-turret/turret-hay-alguien-ahi.mp3"]
  }),
  turretHoraDeLaSiesta: new Howl({
    src: ["https://manzdev.github.io/twitch-turret/turret-hora-de-la-siesta.mp3"]
  }),
  turretModoSiestaActivo: new Howl({
    src: ["https://manzdev.github.io/twitch-turret/turret-modo-siesta-activo.mp3"]
  }),
  fxDespliegue: new Howl({
    src: ["https://manzdev.github.io/twitch-turret/turret-fx-despliegue.mp3"]
  }),
  fxCierre: new Howl({
    src: ["https://manzdev.github.io/twitch-turret/turret-cierre.mp3"]
  })
};

const checkTurret = () => {
  const isLeftOpen = leftPart.classList.contains("open");
  const isRightOpen = rightPart.classList.contains("open");

  if (isLeftOpen && isRightOpen) {
    sounds.fxDespliegue.play();
    sounds.turretHola.play();
    setTimeout(() => sounds.turretHayAlguienAhi.play(), 1000);
  }

  if (!isLeftOpen && !isRightOpen) {
    sounds.fxCierre.play();
    const r = ~~(Math.random() * 2);
    if (r === 0) { sounds.turretHoraDeLaSiesta.play(); } else { sounds.turretModoSiestaActivo.play(); }
  }
};

document.body.addEventListener("click", (ev) => {
  if (ev.detail === 2 || ev.detail === 1) {
    leftPart.classList.toggle("open");
  }
  if (ev.detail === 3 || ev.detail === 1) {
    rightPart.classList.toggle("open");
  }

  checkTurret();
});

const moveIris = () => {
  const x = ~~(Math.random() * 5) - 2;
  const y = ~~(Math.random() * 5) - 2;
  iris.style.setProperty("--x", `${x}px`);
  iris.style.setProperty("--y", `${y}px`);
  const time = ~~(Math.random() * 600) + 150;
  setTimeout(() => moveIris(), time);
};

setTimeout(() => moveIris(), 500);

let times = 30;

const rotateTurret = () => {
  const rotate = ~~(Math.random() * 10) - 5;
  turret.style.setProperty("--turret-rotate", `${rotate}deg`);
  const time = ~~~(Math.random() * 750) + 250;

  if (times === 30) {
    sounds.turretFire.play();
  }
  times--;
  if (times > 0) {
    setTimeout(() => rotateTurret(), time);
  } else {
    sounds.turretFire.pause();
  }
};
              
            
!
999px

Console