cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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

    <title>3D video cube</title>
        
</head>
<body>
    <h1>3D video cube</h1>
    <p>
        In this example, the local camera stream is used as the texture of the cube. On each side a different filter effect is applied. Your browser needs to support <a href="http://caniuse.com/#feat=stream" title="caniuse.com" target="_blank">getUserMedia/Stream API</a> to run this example.
    </p>
    
    <div class="wrap">
        <div class="cube">
            <div class="front">
                <canvas></canvas>
                <p class="caption">none</p>
                
            </div>
            <div class="back">
                <canvas data-filter="blue"></canvas>
                <p class="caption">blue</p>
            </div>
            <div class="top">
                <canvas data-filter="sepia"></canvas>
                <p class="caption">sepia</p>
            </div>
            <div class="bottom">
                <canvas data-filter="brightness"></canvas>
                <p class="caption">brightness</p>
            </div>
            <div class="left">
                <canvas data-filter="red"></canvas>
                <p class="caption">red</p>
            </div>
            <div class="right">
                <canvas data-filter="grayscale"></canvas>
                <p class="caption">grayscale</p>
            </div>
        </div>
    </div>
    
    
    <script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
    
</body>
</html>
            
          
!
            
              
@-webkit-keyframes rotate {
    0% { -webkit-transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg)}                   
    50% { -webkit-transform: rotateX(360deg) rotateY(180deg) rotateZ(180deg)}
    100% { -webkit-transform: rotateX(720deg) rotateY(360deg) rotateZ(360deg)}
}
@-moz-keyframes rotate {
    0% { -moz-transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg)}                   
    50% { -moz-transform: rotateX(360deg) rotateY(180deg) rotateZ(180deg)}
    100% { -moz-transform: rotateX(720deg) rotateY(360deg) rotateZ(360deg)}
}
@-ms-keyframes rotate {
    0% { -ms-transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg)}                   
    50% { -ms-transform: rotateX(360deg) rotateY(180deg) rotateZ(180deg)}
    100% { -ms-transform: rotateX(720deg) rotateY(360deg) rotateZ(360deg)}
}
@-o-keyframes rotate {
    0% { -o-transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg)}                   
    50% { -o-transform: rotateX(360deg) rotateY(180deg) rotateZ(180deg)}
    100% { -o-transform: rotateX(720deg) rotateY(360deg) rotateZ(360deg)}
}
@keyframes rotate {
    0% { transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg)}                   
    50% { transform: rotateX(360deg) rotateY(180deg) rotateZ(180deg)}
    100% { transform: rotateX(720deg) rotateY(360deg) rotateZ(360deg)}
}


body {
    background-color: #fff;
}


.cube {
    margin: auto;
    position: relative;
    height: 200px;
    width: 200px;
    -webkit-transform-style: preserve-3d;
    -moz-transform-style: preserve-3d;
    -ms-transform-style: preserve-3d;
    -o-transform-style: preserve-3d;
    transform-style: preserve-3d;

    -webkit-animation: rotate 20s infinite linear;
    -moz-animation: rotate 20s infinite linear;
    -ms-animation: rotate 20s infinite linear;
    -o-animation: rotate 20s infinite linear;
    animation: rotate 20s infinite linear;
}

.cube .error{
    padding:30px;
    text-align: center;
    font-size: 1.4em;
}

.cube .caption{
    padding:10px;
    background: rgba(0,0,0,0.5);
    position: absolute;
    bottom:0;
    right:0;
}

.cube > div {
    position: absolute;
    padding: 0;
    box-sizing: border-box;
    height: 100%;
    width: 100%;
    opacity: 0.9;
    background-color: #000;
    color: #fff;
    font: 10px arial;
    transition: transform 0.2s ease-in;
    outline: 1px solid transparent;
    text-align: center;
    overflow:hidden;
    border:solid 1px #fff;
}

.cube > div > canvas{
    height:100%;
}


.front {
    -webkit-transform: translateZ(100px);
    -moz-transform: translateZ(100px);
    -ms-transform: translateZ(100px);
    -o-transform: translateZ(100px);
    transform: translateZ(100px);
}

.back {                
    -webkit-transform: translateZ(-100px) rotateY(180deg);
    -moz-transform: translateZ(-100px) rotateY(180deg);
    -ms-transform: translateZ(-100px) rotateY(180deg);
    -o-transform: translateZ(-100px) rotateY(180deg);
    transform: translateZ(-100px) rotateY(180deg);
}

.right {

    -webkit-transform: rotateY(-270deg) translateX(100px);
    -moz-transform: rotateY(-270deg) translateX(100px);
    -ms-transform: rotateY(-270deg) translateX(100px);
    -o-transform: rotateY(-270deg) translateX(100px);
    transform: rotateY(-270deg) translateX(100px);

    -webkit-transform-origin:  top right;
    -moz-transform-origin:  top right;
    -ms-transform-origin:  top right;
    -o-transform-origin:  top right;
    transform-origin:  top right;
}

.left {
    -webkit-transform: rotateY(270deg) translateX(-100px);
    -moz-transform: rotateY(270deg) translateX(-100px);
    -ms-transform: rotateY(270deg) translateX(-100px);
    -o-transform: rotateY(270deg) translateX(-100px);
    transform: rotateY(270deg) translateX(-100px);

    -webkit-transform-origin: left center;
    -moz-transform-origin: left center;
    -ms-transform-origin: left center;
    -o-transform-origin: left center;
    transform-origin: left center;
}

.top {
    -webkit-transform: rotateX(-270deg) translateY(-100px);
    -moz-transform: rotateX(-270deg) translateY(-100px);
    -ms-transform: rotateX(-270deg) translateY(-100px);
    -o-transform: rotateX(-270deg) translateY(-100px);
    transform: rotateX(-270deg) translateY(-100px);

    -webkit-transform-origin: top center;
    -moz-transform-origin: top center;
    -ms-transform-origin: top center;
    -o-transform-origin: top center;
    transform-origin: top center;
}

.bottom {
    -webkit-transform: rotateX(270deg) translateY(100px);
    -moz-transform: rotateX(270deg) translateY(100px);
    -ms-transform: rotateX(270deg) translateY(100px);
    -o-transform: rotateX(270deg) translateY(100px);
    transform: rotateX(270deg) translateY(100px);

    -webkit-transform-origin: bottom center;
    -moz-transform-origin: bottom center;
    -ms-transform-origin: bottom center;
    -o-transform-origin: bottom center;
    transform-origin: bottom center;
}


.wrap {

    margin-top: 150px;
    perspective: 1000px;
    perspective-origin: 50% 50%;


}

.wrap:hover .front {
    -webkit-transform: translateZ(200px);
    -moz-transform: translateZ(200px);
    -ms-transform: translateZ(200px);
    -o-transform: translateZ(200px);
    transform: translateZ(200px);
}

.wrap:hover .back {
    -webkit-transform:  translateZ(-200px) rotateY(180deg);
    -moz-transform:  translateZ(-200px) rotateY(180deg);
    -ms-transform:  translateZ(-200px) rotateY(180deg);
    -o-transform:  translateZ(-200px) rotateY(180deg);
    transform: translateZ(-200px) rotateY(180deg);
}

.wrap:hover .right {
    -webkit-transform: rotateY(-270deg) translateZ(100px) translateX(100px);
    -moz-transform: rotateY(-270deg) translateZ(100px) translateX(100px);
    -ms-transform: rotateY(-270deg) translateZ(100px) translateX(100px);
    -o-transform: rotateY(-270deg) translateZ(100px) translateX(100px);
    transform: rotateY(-270deg) translateZ(100px) translateX(100px);
}

.wrap:hover .left {
    -webkit-transform: rotateY(270deg) translateZ(100px) translateX(-100px);
    -moz-transform: rotateY(270deg) translateZ(100px) translateX(-100px);
    -ms-transform: rotateY(270deg) translateZ(100px) translateX(-100px);
    -o-transform:rotateY(270deg) translateZ(100px) translateX(-100px);
    transform: rotateY(270deg) translateZ(100px) translateX(-100px);
}

.wrap:hover .top {
    -webkit-transform: rotateX(-270deg) translateZ(100px) translateY(-100px);
    -moz-transform: rotateX(-270deg) translateZ(100px) translateY(-100px);
    -ms-transform: rotateX(-270deg) translateZ(100px) translateY(-100px);
    -o-transform:rotateX(-270deg) translateZ(100px) translateY(-100px);
    transform: rotateX(-270deg) translateZ(100px) translateY(-100px);
}

.wrap:hover .bottom {
    -webkit-transform: rotateX(270deg) translateZ(100px) translateY(100px);
    -moz-transform: rotateX(270deg) translateZ(100px) translateY(100px);
    -ms-transform: rotateX(270deg) translateZ(100px) translateY(100px);
    -o-transform: rotateX(270deg) translateZ(100px) translateY(100px);
    transform: rotateX(270deg) translateZ(100px) translateY(100px);
}
            
          
!
            
              navigator.getUserMedia = (navigator.getUserMedia ||
                  navigator.webkitGetUserMedia ||
                  navigator.mozGetUserMedia ||
                  navigator.msGetUserMedia);


if(navigator.getUserMedia) { 

    var $cube=$(".cube"),
        $video=$("<video></video>"),
        video=$video.get(0),
        imgPerSec=30,
        canvasStack=[];

    // fill cube
    $(".cube > div > canvas").each(function(idx){
        canvasStack.push($(this));
    });

    $video.css({visibility:"hidden",height:$cube.height(),width:$cube.width()}).appendTo("body");

    var int = setInterval(function(){
        if( video.videoWidth !== 0){

            var videoWidth=$video.width(),
                videoHeight=$video.height();

            for( var i=0; i<canvasStack.length; i++){
                var $canvas = canvasStack[i], canvas = $canvas.get(0);
                canvas.getContext("2d").drawImage(video, 0, 0, videoWidth, videoHeight);

                // check for filter
                var fn = window[$canvas.data("filter")];
                if(typeof fn === 'function') {
                    filterCanvas(canvas,fn);
                }

            }
        }
    },1000/imgPerSec);
  
    // get the webcam stream
    navigator.getUserMedia( 
        { "video": true }, 
        function(stream) {
            var url = window.URL || window.webkitURL;
            video.src = url ? url.createObjectURL(stream) : stream;
            video.play();
        }, 
        function(error) {
            $(".cube > div").empty().append("<p class='error'>Video capture error: "+ error.code+"</p>");
            clearInterval(int);
        }
    );




    // grayscale filter using an arithmetic average of the color 
    // components
    var grayscale = function (pixels, args) {
      var d = pixels.data;
      for (var i = 0; i < d.length; i += 4) {
        var r = d[i];
        var g = d[i + 1];
        var b = d[i + 2];
        d[i] = d[i + 1] = d[i + 2] = (r+g+b)/3;
      }
      return pixels;
    };

    // sepia-style filter that gives a warm antique feel to an image
    var sepia = function (pixels, args) {
      var d = pixels.data;
      for (var i = 0; i < d.length; i += 4) {
        var r = d[i];
        var g = d[i + 1];
        var b = d[i + 2];
        d[i]     = (r * 0.393)+(g * 0.769)+(b * 0.189); // red
        d[i + 1] = (r * 0.349)+(g * 0.686)+(b * 0.168); // green
        d[i + 2] = (r * 0.272)+(g * 0.534)+(b * 0.131); // blue
      }
      return pixels;
    };

    // filter that shifts all color information to red
    var red = function (pixels, args) {
      var d = pixels.data;
      for (var i = 0; i < d.length; i += 4) {
        var r = d[i];
        var g = d[i + 1];
        var b = d[i + 2];
        d[i] = (r+g+b)/3;        // apply average to red channel
        d[i + 1] = d[i + 2] = 0; // zero out green and blue channel
      }
      return pixels;
    };


    // filter that shifts all color information to blue
    var blue = function (pixels, args) {
      var d = pixels.data;
      for (var i = 0; i < d.length; i += 4) {
        var r = d[i+1];
        var g = d[i + 2];
        var b = d[i];
        d[i] = (r+g+b)/3;        // apply average to blue channel
        d[i] = d[i + 1] = 0;
      }
      return pixels;
    };

    // filter that brightens an image by adding a fixed value 
    // to each color component
    // a javascript closure is used to parameterize the filter 
    // with the delta value
    var brightness = function(delta) {
       return function (pixels, args) {
         var d = pixels.data;
         for (var i = 0; i < d.length; i += 4) {
           d[i] += delta;     // red
           d[i + 1] += delta; // green
           d[i + 2] += delta; // blue   
         }
         return pixels;
       };
    };


    function filterCanvas(canvas, filter) {
        if (canvas.width > 0 && canvas.height > 0) {
          var imageData = canvas.getContext("2d").getImageData(0, 0, canvas.width, canvas.height);
          filter(imageData);
          canvas.getContext("2d").putImageData(imageData, 0, 0);
        }
    }


}else{
    $(".cube > div").empty().append("<p class='error'>getUserMedia is not supported by your browser. Please use another browser to see this demo</p>");
}

            
          
!
999px
Loading ..................

Console