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.

            
              <canvas id="myCanvas" width="854px" height="480px"></canvas>
<br>synced canvas & glitch
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Economica);
body{
  text-align:center;
  padding:20px;
  background-color:#3498db; //Red:	52	Green:	152	Blue:	219
  font-family: 'Economica', sans-serif;
  color:#FFF;
  font-size:30px;
}

#myVideo, #myCanvas{
  border:solid 10px #FFF;
}
#myVideo{}
#myCanvas{
  background-color:#000;
}
            
          
!
            
              $(function(){
  /* 
    :glitchBoy
  */
  function glitchBoy(canvas, options){
    this.canvas = canvas;
    this.ctx = canvas.getContext('2d');
    this.origCanvas = document.createElement('canvas');
    this.origContext = this.origCanvas.getContext('2d');
    this.width = canvas.width;
    this.height = canvas.height;
    this.options = options;
  }
  glitchBoy.prototype.drawImage = function(img, x, y){
    this.canvas.getContext("2d").drawImage(img, x, y);
  };
  glitchBoy.prototype.glitchWave = function(renderLineHeight, cuttingHeight){
    var image = this.ctx.getImageData(0, renderLineHeight, this.width, cuttingHeight);
    this.ctx.putImageData(image, 0, renderLineHeight - 10);
  };
  glitchBoy.prototype.glitchSlip = function(waveStrength, startHeight, endHeight){
    if(endHeight < startHeight){
      var temp = endHeight;
      endHeight = startHeight;
      startHeight = temp;
    }
    for(var h = startHeight; h < endHeight; h++){
      if(Math.random() < 0.1)h++;
      var image = this.ctx.getImageData(0, h, this.width, 1);
      this.ctx.putImageData(image, Math.random()*waveStrength-(waveStrength/2), h); 
    }
  };
  glitchBoy.prototype.glitchFillRandom = function(fillCnt, cuttingMaxHeight){
    var cw = this.width;
    var ch = this.height;
    for(var i = 0; i< fillCnt; i++){
      var rndX = cw * Math.random();
      var rndY = ch * Math.random();
      var rndW = cw * Math.random();
      var rndH = cuttingMaxHeight * Math.random();
      var image = this.ctx.getImageData(rndX,rndY,rndW, rndH);
      this.ctx.putImageData(image, (rndX* Math.random())%cw, rndY);
    }
  }
  glitchBoy.prototype.process = function () {
  
  }

  /* 
    :videoGirl
  */
  function videoGirl(options, callback){
    var options = $.extend({
      src:"",
      type:'video/ogg',
      controls:false,
      autoplay:true,
      loop:true,
      muted:true
    }, options);
    var video = document.createElement('video');
    video.crossOrigin = 'anonymous'; // important!!!!
    video.controls = options.controls;
    video.autoplay = options.autoplay;
    video.loop = options.loop;
    video.muted = options.muted;
    var source = document.createElement('source');
    source.src = options.src;
    source.type = options.type;
    video.appendChild(source);
    this.video = video;
    this.source = source;
    //video.play();
    // load
    if(callback !== null){
      video.addEventListener('loadeddata', callback);
    }
  };


  // sync
  var FPS = 30;
  var frm = 0;
  var vGirl = new videoGirl({
    src:'http://upload.wikimedia.org/wikipedia/commons/b/b1/Big_buck_bunny_zoom_in.ogv',
    type:'video/ogg'
  }, sync);
  function sync(){
    var canvas = document.getElementById("myCanvas");
    var glitch = new glitchBoy(canvas);
    setInterval(function(){
      frm++;
      glitch.drawImage(vGirl.video, 0, 0); 
      glitch.glitchWave((frm * 3) % glitch.height, 10);
      if(frm %100 < 10){
        // fillCnt, cuttingMaxHeight
        glitch.glitchFillRandom(5, 20);
      }
      if(80 < frm%100){
        glitch.glitchSlip(10,200,300);
      }
      if(95 < frm%100){
        glitch.glitchSlip(10,100* Math.random(),400 * Math.random());
      }
    }, 1000/FPS);
  }

});
            
          
!
999px
Loading ..................

Console