Video (p5.dom.js)

In this example below you will see how to do a Video (p5.dom.js) with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by Twinbee, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright Twinbee ©
  • HTML
  • CSS
  • JavaScript
    <div class="container">
  <div id="sketch-holder"></div>
</div>

<div class="button" onclick='playPause()'>></div>

/*Downloaded from https://www.codeseek.co/Twinbee/video-p5domjs-jxBWVX */
    body {
  width: 100vw;
  height: 100vh;
  
  margin: 0;
  padding: 0;
  
  background: #222229;
  
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

// A nice Frame
.container {
  height: 388px;
  width: 612px;
  
  margin: 0 0 20px;
  background: #fff;
  
  box-shadow: 0px 6px 20px #001;
  display: flex;
  justify-content: center;
  align-items: center;
}

.button {
  height: 50px;
  width: 50px;
  
  background: white;
  border-radius: 100%;
  box-shadow: 0px 6px 20px #001;
  
  display: flex;
  justify-content: center;
  align-items: center;
}


/*Downloaded from https://www.codeseek.co/Twinbee/video-p5domjs-jxBWVX */
    // Global Variable Declarations
let c = {
  "width": 512,
  "height": 288
}

let cx = c.width/2,
    cy = c.height/2,
    vid,
    toggle=1;

// Setting up the Canvas
function setup() {
  let canvas = createCanvas(c.width, c.height);
  canvas.parent('sketch-holder');
  
  vid = createCapture(VIDEO);

  vid.size(512, 288);
  vid.hide();
}

// Where the Magic Happens (It draws)
function draw() {
  background(0);
  if (toggle == 1) {
    image(vid, 0, 0, 512, 288);
  }
}

function playPause() {
  if (toggle != 1) {
    vid.stop();
  } else {
    vid.start();
  }
  return toggle=toggle*-1;
}

// On Screen Console Function
function clog(txt) {
  console.log(txt);
  $('.console').text(txt);
}

Comments