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="note">
   Tilt the head to vary the ascendants of the word "village"
</div>
<article>
  <h1>The hitchhiker's Guide to the Galaxy</h1>
  <h2>Chapter 1</h2>
  <p>The house stood on a slight rise just on the edge of the <span style="color: red;">village</span>. It stood on its own and looked out over a broad spread of West Country farmland. Not a remarkable house by any means—it was about thirty years old, squattish, squarish, made of brick, and had four windows set in the front of a size and proportion which more or less exactly failed to please the eye. </p>

  <p>The only person for whom the house was in any way special was Arthur Dent, and that was only because it happened to be the one he lived in. He had lived in it for about three years, ever since he had moved out of London because it made him nervous and irritable. He was about thirty as well, tall, dark-haired and never quite at ease with himself. The thing that used to worry him most was the fact that people always used to ask him what he was looking so worried about. He worked in local radio which he always used to tell his friends was a lot more interesting than they probably thought. It was, too—most of his friends worked in advertising.</p>

  <p>On Wednesday night it had rained very heavily, the lane was wet and muddy, but the Thursday morning sun was bright and clear as it shone on Arthur Dent’s house for what was to be the last time.</p>

  <p>It hadn’t properly registered yet with Arthur that the council wanted to knock it down and build a bypass instead.</p>
</article>

<div class="dev">
  <video></video>
  <canvas></canvas>
</div>

<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-core"></script>
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-converter"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgl"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/facemesh"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjs/7.2.0/math.min.js"></script>

              
            
!

CSS

              
                @font-face {
    src: url('https://cors-anywhere.herokuapp.com/https://v-fonts.com/assets/fonts/AmstelvarAlpha-VF.woff2');
    font-family:'Amstelvar';
    font-style: normal;
}

:root {
  --angle: 0;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Amstelvar', serif;
}

article {
  padding: 1em;
  width: 60ch;
  max-width: 100%;
  font-size: 1.5em;
  line-height: calc(1ex / .32);

  --min-ascender: 750;
  --max-ascender: 850;
  --ascender: max(var(--min-ascender), calc(var(--min-ascender) + (var(--angle) * (var(--max-ascender) - var(--min-ascender)))));
  --min-descender: 250;
  --max-descender: 350;
  --descender: max(var(--min-descender), calc(var(--min-descender) + (-1 * var(--angle) * (var(--max-descender) - var(--min-descender)))));
  font-variation-settings: 'YTAS' var(--ascender), 'YTDE' var(--descender);
}

article > *:first-child {
  margin-top: 0;
}

article > *:last-child {
  margin-bottom: 0;
}

article p {
  margin: 0 0 0.75em 0;
}

.dev {
  position: fixed;
  bottom: 1em;
  right: 1em;
  box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
}

.dev video {
  display: block;
  width: 320px;
  max-width: 50vw;
  height: auto;
}

.dev canvas {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.note {
  padding: 1em;
  font-family: sans-serif;
  font-size: 1.5em;
  background: #e1f9fd;
}
              
            
!

JS

              
                (async () => {
  // get the video
  const video = document.querySelector('video');

  // setup facemesh
  const model = await facemesh.load({
      backend: 'wasm',
      maxFaces: 1,
  });

  async function detectFaces() {
      const faces = await model.estimateFaces(video);
      
      // dev stuff
      renderPrediction(video, faces);

      if (faces.length === 0) {
          // is somebody out there?
          return requestAnimationFrame(detectFaces);
      }

      const [face] = faces;
    
      let mesh = math.matrix(face.scaledMesh);
      let leftEyeCoords = math.squeeze(math.row(mesh, 33)).toArray();
      let rightEyeCoords = math.squeeze(math.row(mesh, 263)).toArray();
      let midPointCoords = [
        (leftEyeCoords[0] + rightEyeCoords[0]) / 2,
        leftEyeCoords[1],
        leftEyeCoords[2],
      ];
      let chinCoords = math.squeeze(math.row(mesh, 152)).toArray();

      let rx = math.subtract(leftEyeCoords, rightEyeCoords);
          rx = math.divide(rx, math.norm(rx));
      let ry = math.subtract(midPointCoords, chinCoords);
          ry = math.divide(ry, math.norm(ry));
      let rz = math.cross(rx, ry);

      let rotationMatrix = math.matrix([rx, ry, rz]).toArray();
      let sy = Math.sqrt(Math.pow(rotationMatrix[0][0], 2) + Math.pow(rotationMatrix[1][0], 2));

      let angle;
      if (sy < 0.000001) {
        angle = Math.atan2(rotationMatrix[1][2], rotationMatrix[1][1]);
      } else {
        angle = Math.atan2(rotationMatrix[2][1], rotationMatrix[2][2]);
      }

      document.documentElement.style.setProperty('--angle', Math.round(angle * 10) / 10);

      // recursively detect faces
      requestAnimationFrame(detectFaces);
  }
  
  // enable autoplay
  video.setAttribute('autoplay', '');
  video.setAttribute('muted', '');
  video.setAttribute('playsinline', '');
  // start face detection when ready
  video.addEventListener('canplaythrough', detectFaces);
  // stream the camera
  video.srcObject = await navigator.mediaDevices.getUserMedia({
      audio: false,
      video: {
          facingMode: 'user',
      },
  });
  // let’s go!
  video.play();
})();

async function renderPrediction(video, predictions) {
    const canvas = document.querySelector('canvas');
    if (canvas.width !== video.videoWidth) {
        canvas.width = video.videoWidth;
        canvas.height = video.videoHeight;
    }

    const ctx = canvas.getContext('2d');
    ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, canvas.width, canvas.height);

    predictions.forEach(prediction => {
        const keypoints = prediction.scaledMesh;
        for (let i = 0; i < keypoints.length; i++) {
            const x = keypoints[i][0];
            const y = keypoints[i][1];
            ctx.fillStyle = '#32EEDB';
            ctx.strokeStyle = '#32EEDB';
            ctx.beginPath();
            ctx.arc(x, y, 1 /* radius */ , 0, 2 * Math.PI);
            ctx.fill();
        }
    });
}
              
            
!
999px

Console