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

              
                <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