A Simple Canvas Vignette - Gists · GitHub

Skip to content Search Gists Search Gists All gists Back to GitHub Sign in Sign up Sign in Sign up Dismiss alert {{ message }}

Instantly share code, notes, and snippets.

@positlabs positlabs/Vignette.js Created March 21, 2013 19:47 Show Gist options
  • Star (2) You must be signed in to star a gist
  • Fork (0) You must be signed in to fork a gist
  • Embed Select an option
    • Embed Embed this gist in your website.
    • Share Copy sharable link for this gist.
    • Clone via HTTPS Clone using the web URL.

    No results found

    Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/positlabs/5216101.js"></script>
  • Save positlabs/5216101 to your computer and use it in GitHub Desktop.
Code Revisions 1 Stars 2 Embed Select an option
  • Embed Embed this gist in your website.
  • Share Copy sharable link for this gist.
  • Clone via HTTPS Clone using the web URL.

No results found

Learn more about clone URLs Clone this repository at <script src="https://gist.github.com/positlabs/5216101.js"></script> Save positlabs/5216101 to your computer and use it in GitHub Desktop. Download ZIP A simple canvas vignette Raw Vignette.js This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters
Vignette = function (canvas) {
var alpha = .7,
context,
visible,
data;
(function initView() {
context = canvas.getContext("2d");
show();
})();
function draw() {
var w = canvas.width = window.innerWidth;
var h = canvas.height = window.innerHeight;
context.clearRect(0, 0, w, h);
context.rect(0, 0, w, h);
// create radial gradient
var outerRadius = w * .5;
var innerRadius = w * .2;
var grd = context.createRadialGradient(w / 2, h / 2, innerRadius, w / 2, h / 2, outerRadius);
// light blue
grd.addColorStop(0, 'rgba(0,0,0,0)');
// dark blue
grd.addColorStop(1, 'rgba(0,0,0,' + alpha + ')');
context.fillStyle = grd;
context.fill();
}
this.show = function() {
if (!visible) {
visible = true;
canvas.style.display = "block";
window.addEventListener("resize", draw);
draw();
}
}
this.hide = function() {
if (!visible) {
visible = false;
canvas.style.display = "none";
window.removeEventListener("resize", draw);
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment You can’t perform that action at this time.

Tag » How To Vignette In Canva