Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
33 lines (29 sloc) 1 KB
<!doctype html>
<meta charset="utf-8">
<title>Gradient Fill 2</title>
<link rel="stylesheet" href="../include/style.css">
Example from <a href=""><em>Foundation HTML5 Animation with JavaScript</em></a>
<canvas id="canvas" width="400" height="400"></canvas>
window.onload = function () {
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d'),
pt1 = {x: 100, y: 100}, //gradient start point
pt2 = {x: 200, y: 200}, //gradient end point
gradient = context.createLinearGradient(pt1.x, pt1.y, pt2.x, pt2.y);
//white to blue to red
gradient.addColorStop(0, "#ffffff");
gradient.addColorStop(0.5, "#0000ff");
gradient.addColorStop(1, "#ff0000");
context.fillStyle = gradient;
context.fillRect(100, 100, 100, 100);