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="container">
   <div class='row'>
     <div class="col-sm-12" id="buttons-row">
        <h1>SnapCat</h1>
       <h3> because sometimes bunnies & hamsters are cuter than humans<h3>
      <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> 
           <button class="btn btn-default" id="story"><img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/450347/unicorn.jpg"></button>
      
       </div> <!-- end of col-sm-12 -->
    </div> <!-- end of row -->     
     <div class="row justify-content-center">
      <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><!-- 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/
3. Code: tracking.js and Ally Spitel 

-->
              
            
!

CSS

              
                @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/unicorn.jpg");
  background-size: 100px;
 font-family: Lato, sans-serif;
 height: 1200px;
}
.container{
  margin-top: 150px;
  background-color:#FFFFFF ;
  border: 12px solid #FFFC00;
}
h1, h3{
  font-weight: 900;
  text-transform: uppercase;
}

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

.btn{
  /*background-color: #eabdfd;*/
  color: black;
  text-transform: uppercase;
  border: 3px solid #eabdfd;
}
img{
  width: 120px;
  height: 80px;
}
#canvas{
  margin-left: -500px;
}

              
            
!

JS

              
                
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(1);
tracker.setStepSize(2.7);
 tracker.setEdgesDensity(.2);

// image constructor create new image element
//new Image();
// image(w,h)
const img = document.createElement("img");
let filterX = 0;
let filterY = 0;
let filterWidth = 0;
let filterHeight = 0;

function changePic (x, y, width, height, src) {
  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', () => {
  changePic(-0.5, -0.9, 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 => {
 context.drawImage(img, rect.x + (filterX * rect.width),
    rect.y + (filterY * rect.height),
    rect.width * filterWidth,
    rect.height * filterHeight
  )  })
  //}// end of else
});

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




              
            
!
999px

Console