Skip to content

Instantly share code, notes, and snippets.

@mfields
Created May 19, 2013 13:43
Show Gist options
  • Save mfields/5607666 to your computer and use it in GitHub Desktop.
Save mfields/5607666 to your computer and use it in GitHub Desktop.
Off-screen canvas rendering of a gradient
( function () {
var canvas = document.getElementById( 'stage' ),
context = stage.getContext( '2d' ),
gradient = document.createElement( 'canvas' );;
( function ( size, renderFunction ) {
var gc = gradient.getContext( '2d' ),
size = 100,
half = size / 2,
glow;
gradient.width = size;
gradient.height = size;
glow = gc.createRadialGradient( half, half, 1, half, half, half );
glow.addColorStop( 0, 'rgba( 255, 255, 255, 0.5 )' );
glow.addColorStop( 1, 'rgba( 255, 255 ,255, 0 )' );
gc.fillStyle = glow;
gc.fillRect( 0, 0, size, size );
} )();
context.drawImage( gradient, 0, 0 );
} )();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment