cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmloctocatspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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.

            
              <select id="compmode">
  <option value="difference">difference</option>
  <option value="multiply">multiply</option>
  <option value="screen">screen</option>
  <option value="overlay">overlay</option>
  <option value="darken">darken</option>
  <option value="lighten">lighten</option>
  <option value="color-dodge">color-dodge</option>
  <option value="color-burn">color-burn</option>
  <option value="hard-light">hard-light</option>
  <option value="soft-light">soft-light</option>
  <option value="exclusion">exclusion</option>
  <option value="hue">hue</option>
  <option value="saturation">saturation</option>
  <option value="color">color</option>
  <option value="luminosity">luminosity</option>
</select>

<canvas id="canvas"></canvas>
<br/>
<small>Credit <a href="http://www.flickr.com/photos/scjn/4494613395/"> Wellington City Night by Donovan Govan</a></small>

            
          
!
            
              canvas {
   width: 1024px;
   height: 681px;
   display: block;
}
            
          
!
            
              (function() {
  var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
                              window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
  window.requestAnimationFrame = requestAnimationFrame;
})();

var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
canvas.width = 1024;
canvas.height = 681;

var overlayWidth = 300;
var overlayHeight = canvas.height;
var direction = true; // expands the overlay from right to left
var randomColor = false;
var currentColor = 'rgb(205, 0, 0)';

canvas.addEventListener("mouseover", function(){randomColor = true; }, false);
canvas.addEventListener("mouseout", function(){randomColor = false; }, false);

var img = document.createElement('img');
img.src = "http://upload.wikimedia.org/wikipedia/en/thumb/5/5c/Wellington_City_Night_downtown.jpg/1024px-Wellington_City_Night_downtown.jpg";

function drawOverlayRect() {
  ctx.fillStyle = currentColor;
  ctx.strokeStyle = 'rgb(0,0,0)';

  ctx.beginPath();
  if (direction)
    ctx.fillRect(canvas.width - overlayWidth, 0, overlayWidth, overlayHeight);
  else
    ctx.fillRect(0, 0, overlayWidth, overlayHeight);
}

function drawOverlay() {
  ctx.clearRect(0, 0, 500, 500);
  ctx.globalCompositeOperation = 'source-over';
  ctx.drawImage(img, 0, 0);
  ctx.globalCompositeOperation = compmode.value;

  if (direction) // expand overlay
    overlayWidth += 3;
  else // shrink overlay
    overlayWidth -= 3;

  drawOverlayRect();

  if (overlayWidth >= canvas.width
    || overlayWidth <= 0)
    direction = !direction;

  requestAnimationFrame(drawOverlay);
}

function generateNewColor() {
  if (!randomColor)
    return;

  currentColor = 'rgb('
    + Math.floor(Math.random() * 256) + ', '
    + Math.floor(Math.random() * 256) + ', '
    + Math.floor(Math.random() * 256)
    + ')';
}

setInterval(generateNewColor, 1000);
requestAnimationFrame(drawOverlay);

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console