text: const video = document.querySelector('.player');
  const canvas = document.querySelector('.photo');
  const ctx = canvas.getContext('2d');
  const strip = document.querySelector('.strip');
  const snap = document.querySelector('.snap');
  
  function getVideo() {
      navigator.mediaDevices
      .getUserMedia({ video: true, audio: false })
      .then(localMediaStream => {
          video.srcObject = localMediaStream;
          video.play();
      })
      .catch(e => {
          console.error('Error accessing the camera.', e);
      });
  }
  
  function paintToCanvas() {
      const width = video.videoWidth;
      const height = video.videoHeight;
  
      canvas.width = width;
      canvas.height = height;
  
      return setInterval(() => {
          ctx.drawImage(video, 0, 0, width, height);
          // get current image
          let pixels = ctx.getImageData(0, 0, width, height);
  
          // apply filter
          pixels = redScreen(pixels);
          // pixels = rgbSplit(pixels);
  
          // put filtered image back
          ctx.putImageData(pixels, 0, 0);
      }, 16);
  }
  
  function redScreen(pixels) {
      for (let i = 0; i < pixels.data.length; i+=4) {
          pixels.data[i] = pixels.data[i] + 100;
          pixels.data[i+1] = pixels.data[i+1] - 50;
          pixels.data[i+2] = pixels.data[i+2] - 100;
      }
  
      return pixels;
  }
  
  function rgbSplit(pixels) {
      for (let i = 0; i < pixels.data.length; i+=4) {
          pixels.data[i] = pixels.data[i-250];
          pixels.data[i+1] = pixels.data[i+250];
          pixels.data[i+2] = pixels.data[i+2];
      }
  
      return pixels;
  }
  
  function takePhoto() {
      // play snap sound
      snap.currentTime = 0;
      snap.play();
  
      // take out a screenshot
      let data = canvas.toDataURL('image/jpeg');
      let link = document.createElement('a');
      link.href = data;
      link.setAttribute('download', 'handsome');
      link.innerHTML = `<img src=${data} alt=""/>`;
      strip.insertBefore(link, strip.firstChild);
  }
  
  getVideo();
  video.addEventListener('canplay', paintToCanvas);