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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <main>
  <svg viewBox="0 0 50 50">
    <defs>
      <g id=pacman>
        <path d="M2 0C2 1.104 1.104 2 0 2-0.88 2-1.628 1.432-1.895 0.642 0 0-1.895 0.642 0 0-1.884-0.673 0 0-1.884-0.673-1.607-1.446-0.868-2 0-2 1.104-2 2-1.104 2 0z"/>
        <circle cx="-0.5" cy="-1.1" r="0.3"/>
      </g>
      <g id=monster>
        <path d="M-2 0a2 2 0 014 0v1.3a.7.7 0 01-1.35.25.7.7 0 01-1.3 0A.7.7 0 01-2 1.3V0z"/>
        <circle cx="-1" r=".5"/>
        <circle cx="-1.15" cy=".1" r=".25"/>
        <circle cx=".8" r=".5"/>
        <circle cx=".65" cy=".1" r=".25"/>
      </g>
    </defs>
    <path id="motion-path" d="M25 0A25 25 0 110 25h25V0z" />
    <use id=target href="#pacman" />
    <use id=target2 href="#monster" />
    <circle id=eye cx="35" cy="15" r="3"/>
  </svg>
</main>
            
          
!

CSS

            
              
body {
  background-color: #0c1419;
}

main {
  display: grid;
  height: 100vh;
  justify-content: center;
  align-content: center;
}

svg {
  width: 80vw;
  max-height: 80vh;
  overflow: visible !important;
}

#motion-path {
  fill: #292714;
  stroke: #fff;
  stroke-width: 0.3;
  stroke-dasharray: 0.1 1;
  stroke-linecap: round;
}

#pacman path {
  fill: #fcee21;
  animation: mouth 200ms infinite;
}
#eye {
  fill: #0c1419;
}

#monster path {
  fill: #ed1c24;
  animation-name: destroy;
  animation-iteration-count: infinite;
  animation-duration: 4s;
}
#monster.destroy path {
  animation-play-state: paused;
}
#monster circle:nth-of-type(odd) {
  fill: #fff;
}
#monster circle:nth-of-type(even) {
  fill: #00f;
}

@keyframes mouth {
  to {
    d: path('M2 0C2 1.104 1.104 2 0 2-0.88 2-2 1.297-2 0-1 0-1 0 0 0-1 0-1 0-2 0-2-1.4-0.868-2 0-2 1.104-2 2-1.104 2 0z');
  }
}

@keyframes destroy {
  3% {
    opacity: 0;
  }
  6% {
    opacity: 1;
  }
  9% {
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  15% {
    opacity: 0;
  }
  18% {
    opacity: 1;
  }
  21% {
    opacity: 0;
  }
  22% {
    opacity: 1;
  }
}
            
          
!

JS

            
              
/* https://developer.mozilla.org/en-US/docs/Web/API/SVGGeometryElement/getPointAtLength#Browser_compatibility */
/* https://developer.mozilla.org/en-US/docs/Web/API/SVGPathElement/getPointAtLength#Browser_compatibility */

const init = () => {
  
  const duration = 4000
  const path = document.getElementById('motion-path')
  const length = path.getTotalLength()

  let start
  let ticking = false
  
  const animate = timestamp => {

    if (ticking) {
      return
    } else if (!start) {
      start = timestamp
    }
    ticking = true

    const currentTime = timestamp - start
    const { x, y } = path.getPointAtLength(currentTime / duration * length)
    const { x: x2, y: y2 } = path.getPointAtLength(currentTime / duration * (length + 15))
    const angle = Math.atan2(y - y2, x - x2)

    target.setAttribute('transform', `translate(${x} ${y}) rotate(${angle * 180 / Math.PI})`)
    target2.setAttribute('transform', `translate(${x2} ${y2})`)

    if (currentTime > duration) {
      
      start = null
      monster.classList.toggle('destroy')
      
      return setTimeout(
        () => {
          ticking = false
          requestAnimationFrame(animate)
          monster.classList.toggle('destroy')
        }, 
        500)
    }
    
    ticking = false
    requestAnimationFrame(animate)
  }

  requestAnimationFrame(animate)
}

document.addEventListener('DOMContentLoaded', init)
            
          
!
999px

Console