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 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

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.

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

              
                
<head>
  <meta charset="UTF-8">
  <title>Censorship</title>
  <style>
    * {
      box-sizing: border-box;
    }

    body {
      margin: 0;
    }

    .wrap {
      position: relative;
      min-height: 100vh;
      display: grid;
      justify-content: center;
      align-items: center;
    }

    .wrap>* {
      grid-column: 1;
      grid-row: 1;
    }

    .face {
      position: absolute;
    }
  </style>
</head>

<body>
  <div class="wrap">
    <video class="webcam"></video>
    <canvas class="video"></canvas>
    <canvas class="face"></canvas>
  </div>

</body>
              
            
!

CSS

              
                /* Variables */
html {
    --grey: #e7e7e7;
    --gray: var(--grey);
    --blue: #0072B9;
    --pink: #D60087;
    --yellow: #ffc600;
    --black: #2e2e2e;
    --red: #c73737;
    --green: #61e846;
    --text-shadow: 2px 2px 0 rgba(0,0,0,0.2);
    --box-shadow: 0 0 5px 5px rgba(0,0,0,0.2);
    font-size: 62.5%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    box-sizing: border-box;
  }
  
  *, *:before, *:after {
    box-sizing: inherit;
  }
  
  body {
    font-size: 2rem;
    line-height: 1.5;
    background-color: var(--black);
    background-image: url("data:image/svg+xml,%3Csvg width='20' height='100' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 21.184c.13.357.264.72.402 1.088l.661 1.768C4.653 33.64 6 39.647 6 50c0 10.271-1.222 15.362-4.928 24.629-.383.955-.74 1.869-1.072 2.75v6.225c.73-2.51 1.691-5.139 2.928-8.233C6.722 65.888 8 60.562 8 50c0-10.626-1.397-16.855-5.063-26.66l-.662-1.767C1.352 19.098.601 16.913 0 14.85v6.335zm20 0C17.108 13.258 16 8.077 16 0h2c0 5.744.574 9.951 2 14.85v6.334zm0 56.195c-2.966 7.86-4 13.123-4 22.621h2c0-6.842.542-11.386 2-16.396v-6.225zM6 0c0 8.44 1.21 13.718 4.402 22.272l.661 1.768C14.653 33.64 16 39.647 16 50c0 10.271-1.222 15.362-4.928 24.629C7.278 84.112 6 89.438 6 100h2c0-10.271 1.222-15.362 4.928-24.629C16.722 65.888 18 60.562 18 50c0-10.626-1.397-16.855-5.063-26.66l-.662-1.767C9.16 13.223 8 8.163 8 0H6z' fill='%23fff' fill-rule='nonzero' fill-opacity='.1' opacity='.349'/%3E%3C/svg%3E%0A");
    background-size: 15px;
  }
  
  
  /* Table Styles */
  
  table {
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 2rem;
    border-collapse: collapse;
  }
  
  td, th {
    border: 1px solid var(--grey);
    padding: 0.5rem;
  }
  
  
  /* Helper Divs */
  
  .wrapper {
    max-width: 1000px;
    margin: 4rem auto;
    padding: 2rem;
    background: white;
  }
  
  .box, .wrapper {
    box-shadow: 0 0 3px 5px rgba(0,0,0,0.08653);
  }
  a {
    color: var(--blue);
    text-decoration-color: var(--yellow);
  }
  
  
  a.button, button, input[type="button"] {
    color: white;
    background: var(--pink);
    padding: 1rem;
    border: 0;
    border: 2px solid transparent;
    text-decoration: none;
    font-weight: 600;
    font-size:2rem;
  }
  
  :focus {
    outline-color: var(--pink);
  }
  
  fieldset {
    border: 1px solid black;
  }
  
  input:not([type="checkbox"]):not([type="radio"]), textarea, select {
    display: block;
    padding: 1rem;
    border: 1px solid var(--grey);
  }
  
  .success {
    border: 1px solid red;
  }
  
  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    color: white;
    margin-top: 0;
    line-height: 1;
    text-shadow: var(--text-shadow);
  }
  .wrapper h1,
  .wrapper h2,
  .wrapper h3,
  .wrapper h4,
  .wrapper h5,
  .wrapper h6 {
    color: var(--black);
    text-shadow: none;
  }
              
            
!

JS

              
                
const overall = document.querySelector('body');
console.log(window.innerWidth);

const video = document.querySelector('.webcam');
const canvas = document.querySelector('.video');
const ctx = canvas.getContext('2d');
const faceCanvas = document.querySelector('.face');
const faceCtx = faceCanvas.getContext('2d');
const faceDetector = new window.FaceDetector();

console.log(faceDetector);
console.log(faceCtx.drawImage);

if (window.innerHeight > window.innerWidth){
    window.innerHeight = window.innerWidth;
}

async function populateVideo() {
  const stream = await navigator.mediaDevices.getUserMedia({
    video: { width: innerWidth, height: innerHeight },
  });
  video.srcObject = stream;
  await video.play();
  // size the canvases to be the same size as the video
  console.log(video.videoWidth, video.videoHeight);
  canvas.width = video.videoWidth;
  canvas.height = video.videoHeight;
  faceCanvas.width = video.videoWidth;
  faceCanvas.height = video.videoHeight;
}

async function detect() {
  const faces = await faceDetector.detect(video);
  faces.forEach(censor);
  requestAnimationFrame(detect);
}

function Circle(x, y, radius) {
    this.x = x;
    this.y = y;
    this.radius = radius;

    this.draw = function(){

        ctx.beginPath();
        ctx.arc(this.x, this.y, this.radius, 0, Math.PI*2, false);
        ctx.fill();
    }
}

function Ellipse(x, y, xradius, yradius) {
    this.x = x;
    this.y = y;
    this.xradius = xradius;
    this.yradius = yradius;

    this.draw = function(){

        ctx.beginPath();
        ctx.ellipse(this.x, this.y, this.xradius, this.yradius, 0, 0, Math.PI*2, false);
        ctx.fill();
    }
}


var facecount = Array(10);

// are based on height of face being ~5 inches
var startDepth = 24;
var startWidth = 18;
var startHyp = Math.sqrt(startDepth*startDepth + (startWidth/2)*(startWidth/2));

function adjacent(context) {
    return (startDepth * context) / (startWidth*96)
}

var scale = startDepth / startHyp;
var screenWidth = window.innerWidth;
var screenDepth = adjacent(screenWidth);
console.log(screenDepth);
function censor({ boundingBox: face }) {      
  facecount.shift();
  facecount.push(face);

  const averageBy = (arr, fn) =>
  arr.map(typeof fn === 'function' ? fn : val => val[fn]).reduce((acc, val) => acc + val, 0) /
  arr.length;

  var left = averageBy(facecount, "left");
  var right = averageBy(facecount, "right");
  var width = averageBy(facecount, "width");
  var top = averageBy(facecount, "top");
  var bottom = averageBy(facecount, "bottom");
  var height = averageBy(facecount, "height");
  
  //scale = 0.2;
  wmiddle = left + width / 2;
  wtheta = Math.atan(scale*(innerWidth / 2 - wmiddle) / (screenDepth*96 / 2));
  wcenterOffset = -(screenDepth/2)*96*Math.sin(wtheta);
  wcenter = canvas.width/2 - wcenterOffset;

  hmiddle = top + height / 2;
  htheta = Math.atan(scale*(innerHeight / 2 - hmiddle) / (screenDepth*96 / 2));
  hcenterOffset = -(screenDepth/2)*96*Math.sin(htheta);
  hcenter = canvas.height/2 + hcenterOffset;

  wradius1 = Math.sin(wtheta + Math.PI / 6);
  wradius2 = Math.sin(wtheta - Math.PI / 6);
  wradiScale = wradius1 - wradius2;

  hradius1 = Math.sin(htheta + Math.PI / 6);
  hradius2 = Math.sin(htheta - Math.PI / 6);
  hradiScale = hradius1 - hradius2;
  console.log(hradiScale);

  ctx.clearRect(0, 0, canvas.width, canvas.height);
  ctx.fillStyle = "rgba(0, 0, 0, 1)";
  ctx.fillRect(0, 0, canvas.width, canvas.height);
  ctx.fillStyle = "rgba(355, 355, 355, 1)";

  //ctx.ellipse(canvas.width / 2, canvas.height / 2, window.innerWidth/2, window.innerHeight/2, 0, 0, Math.PI*2);
  ctx.ellipse(canvas.width / 2, canvas.height / 2, wradiScale*window.innerWidth/2, hradiScale*window.innerHeight/2, 0, 0, Math.PI*2);
  ctx.fill();

  ctx.fillStyle = "gray";
//  var pupil = new Circle(wcenter, hcenter, window.innerWidth / 4);
//  pupil.draw();
var pupil = new Ellipse(wcenter, hcenter, wradiScale*window.innerWidth / 4, hradiScale*window.innerWidth / 4);
pupil.draw();
  
  ctx.fillStyle = "rgba(0, 0, 0, 1)";
//  var pupil2 = new Circle(wcenter, hcenter, window.innerWidth / 8);
//  pupil2.draw();
  var pupil2 = new Ellipse(wcenter, hcenter, wradiScale*window.innerWidth / 7, hradiScale*window.innerWidth / 7);
  pupil2.draw();
  
  ctx.fillStyle = "black";
  ctx.beginPath();
  ctx.ellipse(innerWidth/2, innerHeight/2, wradiScale*innerWidth/2, hradiScale*innerHeight/2, 0, 0, 2 * Math.PI);
  ctx.rect(innerWidth, 0, - innerWidth, innerHeight);
  ctx.fill();
}

populateVideo().then(detect);
              
            
!
999px

Console