Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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.

            
              <div class="intro">
  <h1>Using chrome's new <a href="https://www.chromestatus.com/feature/4757990523535360">Shape detection API</a></h1>
  <p>Will not work without experimental web platform features enabled. </br> Go to <code>chrome://flags/#enable-experimental-web-platform-features</code> to access and enable experimental web platform features.</p>
</div>
<div class="container">
  <video crossorigin="anonymous" autoplay class="player"></video>

  <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 354.77   270">
  <defs>
    <circle id="mask" cx="170.1" cy="124.3" r="93.5"/>
    <style>
      .cls-1{fill:#65c8ce}.cls-4{fill:#1c4c4c}
    </style>
    <linearGradient id="linear-gradient" x1="115.08" y1="135.92" x2="269.17" y2="277.18" gradientUnits="userSpaceOnUse">
      <stop offset="0" stop-color="#81d0d6"/>
      <stop offset="1" stop-color="#65c8ce"/>
    </linearGradient>
    
     <radialGradient id="leftcheek" cx="111.498" cy="166.243" r="41.952" gradientUnits="userSpaceOnUse">
    <stop offset=".001" stop-color="#E0A8D9"/>
    <stop offset=".171" stop-color="#E0A8D9" stop-opacity=".83"/>
    <stop offset=".326" stop-color="#E0A8D9" stop-opacity=".675"/>
    <stop offset=".475" stop-color="#E0A8D9" stop-opacity=".526"/>
    <stop offset=".62" stop-color="#E0A8D9" stop-opacity=".38"/>
    <stop offset=".763" stop-color="#E0A8D9" stop-opacity=".237"/>
    <stop offset=".901" stop-color="#E0A8D9" stop-opacity=".099"/>
    <stop offset="1" stop-color="#E0A8D9" stop-opacity="0"/>
  </radialGradient>
  <radialGradient id="rightcheek" cx="218.316" cy="178.321" r="41.952" gradientUnits="userSpaceOnUse">
    <stop offset=".001" stop-color="#E0A8D9"/>
    <stop offset=".171" stop-color="#E0A8D9" stop-opacity=".83"/>
    <stop offset=".326" stop-color="#E0A8D9" stop-opacity=".675"/>
    <stop offset=".475" stop-color="#E0A8D9" stop-opacity=".526"/>
    <stop offset=".62" stop-color="#E0A8D9" stop-opacity=".38"/>
    <stop offset=".763" stop-color="#E0A8D9" stop-opacity=".237"/>
    <stop offset=".901" stop-color="#E0A8D9" stop-opacity=".099"/>
    <stop offset="1" stop-color="#E0A8D9" stop-opacity="0"/>
  </radialGradient>
  </defs>
  <ellipse class="arm arm1" fill="#65c8ce" cx="93.5" cy="160.3" rx="60.5" ry="25.3"/>
  <ellipse class="arm arm2" fill="#65c8ce"cx="262" cy="151.2" rx="60.5" ry="25.3"/>
  <g class="leg leg1">
  <ellipse fill="#65c8ce" transform="rotate(-57.289 129.083 254.096)" class="st0" cx="129.1" cy="254.1" rx="67.8" ry="30"/>
  </g>
  <g class="leg leg2">
  <ellipse fill="#65c8ce" cx="222.33" cy="251.1" rx="29.99" ry="67.81" transform="rotate(-10.95 222.424 251.334)"/>
  </g>
  <circle class="tummy" cx="183.91" cy="199.01" r="104.52" fill="url(#linear-gradient)"/>
  <g class="head">
    <circle cx="170.09" cy="124.29" r="93.5" fill="#81d0d6"/> 
   <clipPath id="clip">
    <use xlink:href="#mask" overflow="visible"/>
  </clipPath>
  <circle class="blush" cx="111.5" cy="166.2" r="42" clip-path="url(#clip)" fill="url(#leftcheek)"/>
  <circle class="blush" cx="218.3" cy="178.3" r="42" clip-path="url(#clip)" fill="url(#rightcheek)"/>
    <g class="squint">
    <circle class="eye" fill="#1c4c4c" cx="217.17" cy="150.96" r="9.71"/>
    </g>
    <g class="squint">
    <circle class="eye" fill="#1c4c4c" cx="117.13" cy="134" r="9.71"/>
    </g>
  </g>
</svg>
</div>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Gochi+Hand');

body {
  padding: 0;
  margin: 0;
  background-color: #dbd7f2;
  min-height: 100vh;
  padding: 1rem;
  box-sizing: border-box;
  color: hsl(198, 1%, 29%);
  display: flex;
  justify-content: space-between;
  flex-direction: column;
}

.intro {
  text-align: center;
  font-family: 'Gochi Hand', cursive;
  max-width: 90ch;
  margin: 0 auto;
}

p {
  font-size: 1.2rem;
  line-height: 1.8rem;
}

a {
  color: #65c8ce;
}

code {
  background: #ffffff;
  border: 1px solid #cacaca;
  border-radius: 6px;
  line-height: 1.85714rem;
  padding: 4px 4px 1px;
  font-family: 'Gochi Hand', cursive;
}

video { 
  width: 400px;
  height: 400px;
  object-fit: cover;
}

.container {
  padding: 0;
  margin: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  flex-wrap: wrap;
}

svg {
  height: 60vh;
  max-height: 600px;
  min-width: 400px;
  flex: 0;
}

.blush {
  opacity: 0;
}
            
          
!
            
              const dancing = new TimelineMax({repeat:-1, yoyo:true, paused:true})
  .fromTo(".head", 1, { transformOrigin: "center", rotation: -20, ease: Sine.easeInOut },  { rotation: 5, ease: Sine.easeInOut },0 )
  .fromTo(".tummy", 1, { transformOrigin: "center", xPercent: -4, scale: 1.03, rotation: -2, ease: Sine.easeInOut },  { xPercent: 0, rotation: 2,  ease : Sine.easeInOut },0 )
  .to(".leg1", 1, { transformOrigin: "50% 20%", rotation: 30, ease : Sine.easeInOut },0 )
  .to(".leg2", 1, {transformOrigin: "center", rotation: 13, ease: Sine.easeInOut },0 )
  .fromTo(".arm1", 1, {transformOrigin: "80% 0%", rotation: 15, ease: Sine.easeInOut }, {transformOrigin: "80% 50%", rotation: -15, ease: Sine.easeInOut },0 )
  .fromTo(".arm2", 1,{transformOrigin: "30% 30%", rotation: 15, ease: Sine.easeInOut },  {rotation: -15, ease: Sine.easeInOut },0 )


const blinking = new TimelineMax({repeat:-1, yoyo:true, paused:true})
.to(".eye", 0.2, {transformOrigin: "center", scaleY : 0.2, ease : Sine.easeInOut,}, 4 )

const blushing = new TimelineMax({paused:true})
  .to(".blush", 2, {autoAlpha: 1, ease : Sine.easeInOut}, 0 )
  .to(".squint", 0.5, {transformOrigin: "center", scaleY : 0.2, ease : Sine.easeInOut}, 0 )
  // .to(".squint", 1, {transformOrigin: "center", scaleY: 0.2, Sine.easeInOut}, 0 )


const video = document.querySelector('.player')
const refreshRate = 1000;

function getVideo() {
  navigator.mediaDevices.getUserMedia({ video: true, audio: false })
    .then(webCamFeed => {
      video.srcObject = webCamFeed;
      setInterval(findFaysh, refreshRate);
    })
    .catch(err => {
      console.error('Oh no, you denied the webcam, no fun for you.', err)
    })
}

const findFaysh = async () => {
  const myWebcamFeed = document.querySelector('.player');
  const faceDetector = new FaceDetector();

  try {
    const faces = await faceDetector.detect(myWebcamFeed);
    console.log(faces[0]);
    if(faces.length){
      dancing.pause();
      blushing.play(); 
      blinking.pause();
    } else {
      dancing.play();
      blinking.play();
      blushing.reverse().timeScale(2.5)
    }
    } catch (error) {
      console.log("oops, something went wrong with face detection")
  };
}

window.addEventListener('load', getVideo);
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console