gwdean's blog

Canvas Drawing Framework Iteration 1.

Posted in Uncategorized by gwdean on August 19, 2011

The following code is the beginning of a small framework used to test Canvas drawings.
It is adapted from David Flanagan’s JavaScript: The Definitive Guide, 5th edition.


<html>
<head>
<script>
function makeCanvas(id, width, height) {
  var canvas = document.createElement("canvas");
  canvas.id = id;
  canvas.width = width;
  canvas.height = height;
  return canvas;
}
function pieChart(canvas, data, cx, cy, r, colors, labels, lx, ly) {}

function init() {
  var canvas = makeCanvas("canvas", 600, 400);
  document.body.appendChild(canvas);
  pieChart("canvas", [12,23,34,45], 200, 200, 150,
           ["red", "blue", "yellow", "green"],
           ["North", "South", "East", "West"],
           400, 100);
}
</script>
</head>
<body onload="init()"></body>
</html>

Advertisement
Follow

Get every new post delivered to your Inbox.