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>
  <div></div>
</main>
<aside>
  <div class="scrubber-container">
    <label for="scrubber">Points</label>
    <input id="scrubber" type="range" min="1" max="256" value="256" step="1" />
  </div>
  <output for="scrubber"><b>clip-path: polygon(evenodd, ...)</b></output>
</aside>
              
            
!

CSS

              
                main div {
  margin: 5vmin auto;
  width: 50vmin;
  height: 50vmin;
  position: relative;
  --mid-y: 47%;
  --mid-left: 20%;
  --mid-center: 50%;
  --mid-right: 80%;
  --mouth-rad-side: 3%;
  --mouth-rad-top: 27%;
  --mouth-rad-bottom: 33%;

  --eye-left-x: 37%;
  --eye-right-x: 63%;
  --eye-rad: 9%;
  --eye-y: 35%;
  background: linear-gradient(135deg, hsl(16 100% 64%), hsl(296 100% 64%));
  border: 1.5vmin solid hsl(296 100% 84%);
  border-radius: 50%;
  box-sizing: border-box;
}
p {
  border-radius: 50%;
  font-size: 0.5rem;
  font-size: system-ui, sans-serif;
}

body {
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  background: repeating-linear-gradient(
      0deg,
      hsl(344 100% 90% / 10%) 0 0.2vmin,
      hsl(234 100% 60% / 0%) 0 2vmin
    ),
    linear-gradient(45deg, hsl(344 100% 10%), hsl(234 100% 20%));
  /*
  background: conic-gradient(from 90deg at 50% 30vmin, hsl(334 100% 60%), hsl(284 100% 60%), hsl(244 100% 60%), hsl(44 100% 60%)); */
}
aside {
  color: white;
  flex: 1;
  height: 30vmin;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  left: 0;
  right: 0;
  padding: 1rem 1rem 0;
  background: hsl(223 100% 3% / 87%);
  backdrop-filter: blur(8px);
  font-family: system-ui, sans-serif;
  border-top: 0.5vmin solid hsl(343 100% 60%);
}
.scrubbable .scrubber-container {
  opacity: 1;
}
label {
  padding-right: 0.5rem;
}
.scrubber-container {
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 400ms ease-out;
}
output {
  font-family: monospace;
  overflow-y: auto;
  padding: 0.5rem 0.5rem 1rem;
  margin-top: 0.75rem;
}
output li.active {
  font-weight: bold;
}
output li:nth-last-child(1 of .active) {
  border-bottom: 2px dashed hsl(203 100% 50%);
  margin-bottom: 0.5rem;
}

              
            
!

JS

              
                const div = document.querySelector("div");
const output = document.querySelector("output");

const supportsCssMath = window?.CSS?.supports("width: calc(sin(0deg) * 1vw)");

if (supportsCssMath) {
  div.classList.add("css-math-supported");
  finalPoints = generateViaCss();
  setupInteraction();
} else {
  document.querySelector("aside").textContent =
    "CSS Trig Functions are not supported in this browser. Please try the latest version of Safari, Firefox, Edge, or Chrome.";
}

function generateViaCss() {
  //Start by cutting around the full element and then going inside the element, to initiate the start of the cutouts
  let points = [
    "50% 50%",
    "50% 0%",
    "0% 0%",
    "0% 100%",
    "100% 100%",
    "100% 0%",
    "50% 0%",
    "50% var(--eye-y)"
  ];

  //left eye
  for (let i = 0; i <= 360; i = i + 6) {
    points.push(
      `calc(var(--eye-left-x) + calc(cos(${i}deg) * var(--eye-rad))) calc(var(--eye-y) + calc(sin(${i}deg) * var(--eye-rad)))`
    );
  }

  //right eye
  for (let i = 0; i <= 360; i = i + 6) {
    points.push(
      `calc(var(--eye-right-x) + calc(cos(${i}deg) * var(--eye-rad))) calc(var(--eye-y) + calc(sin(${i}deg) * var(--eye-rad)))`
    );
  }

  //cut back to the first point on the inside
  points.push("50% var(--eye-y)");

  //cut to the center midpoint for the smile
  points.push("50% var(--mid-y)");

  //mouth/smile
  //rounded top left
  for (let i = 180; i <= 360; i = i + 6) {
    points.push(
      `calc(var(--mid-left) + calc(cos(${i}deg) * var(--mouth-rad-side))) calc(var(--mid-y) + calc(sin(${i}deg) * var(--mouth-rad-side)))`
    );
  }
  //top of main smile arc
  for (let i = 180; i >= 0; i = i - 6) {
    points.push(
      `calc(var(--mid-center) + calc(cos(${i}deg) * var(--mouth-rad-top))) calc(var(--mid-y) + calc(sin(${i}deg) * var(--mouth-rad-top)))`
    );
  }
  //rounded top right
  for (let i = 180; i <= 360; i = i + 6) {
    points.push(
      `calc(var(--mid-right) + calc(cos(${i}deg) * var(--mouth-rad-side))) calc(var(--mid-y) + calc(sin(${i}deg) * var(--mouth-rad-side)))`
    );
  }
  //bottom of main smile arc
  for (let i = 0; i <= 180; i = i + 6) {
    points.push(
      `calc(var(--mid-center) + calc(cos(${i}deg) * var(--mouth-rad-bottom))) calc(var(--mid-y) + calc(sin(${i}deg) * var(--mouth-rad-bottom)))`
    );
  }

  //cut back to center midpoint for the smile to close the inner connections
  points.push("50% var(--mid-y)");

  return points;
}

function setupInteraction() {
  scrubber.setAttribute("max", finalPoints.length);
  scrubber.setAttribute("value", finalPoints.length);

  const animatedPaths = [];
  const pathLength = finalPoints.length;
  console.log(pathLength);
  for (let i = 1; i <= pathLength; i++) {
    animatedPaths.push(
      `polygon(evenodd, ${finalPoints.slice(0, i).join(",")})`
    );
  }
  const duration = 4800;

  div.style.clipPath = animatedPaths[animatedPaths.length - 1];
  const animation = div.animate(
    {
      clipPath: animatedPaths
    },
    {
      duration,
      iterations: 1,
      fill: "forwards"
    }
  );

  animation.onfinish = () => {
    document.body.classList.add("scrubbable");
  };

  scrubber.addEventListener("input", (e) => {
    const step = scrubber.value;
    animation.pause();
    animation.currentTime = (duration * step) / pathLength;
    updateOutput(step);
  });

  function createOutput() {
    const wrapper = document.createElement("ol");

    finalPoints.forEach((point) => {
      const item = document.createElement("li");
      item.textContent = point;
      item.className = "active";
      wrapper.appendChild(item);
    });

    output.appendChild(wrapper);
  }
  function updateOutput(index) {
    const items = document.querySelectorAll("output li");
    finalPoints.forEach((point, i) => {
      const item = items[i];
      if (i < index) {
        item.classList.add("active");
      } else if (i == index) {
        item.classList.add("active");
        item.scrollIntoView({ block: "center" });
      } else {
        item.classList.remove("active");
      }
    });
  }

  createOutput();
}

              
            
!
999px

Console