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="container">
   <div class='row'>
     <div class="col-sm-12" id="buttons-row">
        <h1>Web SnapChat Clone</h1>
       <h6> because sometimes bunnies & hamsters are cuter than humans</h6>
      <button class="btn btn-default"id="flower-crown"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/450347/flower-crown.png"></button>
      <button class="btn btn-default" id="bunny-ears"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/450347/bunny-ears.png"></button> 
      <button class="btn btn-default"id="doggy"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/450347/dog-face.png"></button>
      <button class="btn btn-default" id="hearts"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/450347/hearts.png"></button>     
       </div> <!-- end of col-sm-12 -->
    </div> <!-- end of row -->     
     <div class="row justify-content-center videorow">
      <video id="video" width="500" height="325" preload autoplay loop muted></video>
      <canvas id="canvas" width="500" height="325"></canvas>  
   </div><!-- end of row -->
       <div class="row justify-content-center videorow">
         <button class="btn btn-default" id="snap" onclick="snap()"></button>
       </div>
</div> <!-- end of row -->
<div class="row">
       <div class="col-sm-12 justify-content-center videorow" id="output">
           <canvas id="canvas2" width="500" height="325"></canvas>                                                                      </div>
</div>
</div><!-- end of container -->

         
         <!-- CREDITS
0. No copyright infringments intended
1. Image: https://ibankcoin.com/flyblog/2017/02/16/king-unicorn-come-public-will-buy-snap-opening-tick/
2.http://www.instructables.com/id/Facial-Recognition-With-Trackingjs/
-->
            
          
!
            
              import url("https://fonts.googleapis.com/css?family=Lato:400,400i,700");

body{
  background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/450347/snap1.png");
  background-size: 100px;
 font-family: Lato, sans-serif; 
}
.container{
  margin-top: 150px;
  background-color:#FFFFFF ;
  border: 12px solid #FFFC00;
  width: 700px;
}
h1, h6{
  font-weight: 900;
  text-transform: uppercase;
   color: #8e7ba7;   
}

.row{
  margin: 30px;
  text-align:center;
}
.btn{
 margin-bottom: 10px;
}

.btn-default{
 background-color: #FFFFFF;
  text-transform: uppercase;
  border: 1px solid #8e7ba7;
  border-radius: 60px;
  height: 90px;
  width: 90px;
}
#snap{
  width: 40px;
  height: 40px;
  border-radius: 40px;
  background-color: #FFFC00;
}
img{
  width: 80px;
  height: 60px;
  margin-left: -8px;

}
#canvas{
  margin-left: -500px;
  /*border: 1px solid red; */
}


            
          
!
            
              
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
const tracker = new tracking.ObjectTracker('face');
const flowerCrownButton = document.getElementById('flower-crown');
const bunnyEarsButton = document.getElementById('bunny-ears');
const doggyButton = document.getElementById('doggy');
const heartsButton = document.getElementById('hearts');
tracker.setInitialScale(3);
tracker.setStepSize(1.7);
tracker.setEdgesDensity(.2);



// image constructor create new image element
//new Image();
// image(w,h)
const img = document.createElement("img");
img.setAttribute("id", "pic");
img.src = canvas.toDataURL();

let filterX = 0;
let filterY = 0;
let filterWidth = 0;
let filterHeight = 0;

function changePic (x, y, width, height, src) {
 // alert("function changePic")
  img.src = src;
  filterX = x;
  filterY = y;
  filterWidth = width;
  filterHeight = height;
}


function flowerCrown () {
  //alert("ok")
  changePic(0, -0.5, 1, 1, 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/450347/flower-crown.png')
}

flowerCrownButton.addEventListener('click', flowerCrown);


/*
bunnyEarsButton.addEventListener('click', () => {
  //alert("ok")
  changePic(-0.5, -1, 2, 2, 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/450347/bunny-ears.png')
})

function doggy () {
  //alert("ok")
  changePic(0, -1, 1, 3, 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/450347/dog-face.png')
}

doggyButton.addEventListener('click', doggy);


function hearts( ) {
  changePic(0, -1, 2, 2, 'https://s3-us-west-2.amazonaws.com/s.cdpn.io/450347/hearts.png')
}

heartsButton.addEventListener('click', hearts);
*/

//listen for track events
tracker.on('track', function(event) {
  //if (event.data.length === 0) {
    //alert("No objects were detected in this frame.");
  //} else {
context.clearRect(0, 0, canvas.width, canvas.height)
  event.data.forEach(rect=> {
  //alert(JSON.stringify(rect))
 context.drawImage(img, rect.x + (filterX * rect.width),
    rect.y + (filterY * rect.height),
    rect.width * filterWidth,
    rect.height * filterHeight
  )  
  })
});

//start tracking
tracking.track('#video', tracker, { camera: true })




  var canvas2 = document.getElementById('canvas2');
var context2 = canvas2.getContext('2d');
var video = document.querySelector("video");
var w, h, ratio;


video.addEventListener("loadedmetadata", function() {
  ratio = video.videoWidth / video.videoHeight;
   w = video.videoWidth - 100;
     h = parseInt(w / ratio, 10);
    canvas2.width = w;
    canvas2.height = h;
}, false);

function snap(){
     context2.drawImage(video, 10, 10);
  
}


            
          
!
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