Skip to content

Instantly share code, notes, and snippets.

@desandro
Created August 23, 2010 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save desandro/545932 to your computer and use it in GitHub Desktop.
Save desandro/545932 to your computer and use it in GitHub Desktop.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>basic canvas</title>
<style media="screen">
body {
font-family: 'Helvetica Neue', Arial, sans-serif;
}
canvas {
border: 1px solid #CCC;
}
</style>
<script>
function init() {
var canvas = document.getElementsByTagName('canvas')[0];
if (canvas.getContext) {
var
ctx = canvas.getContext("2d"),
w = canvas.width, // canvas width
h = canvas.height // canvas height
;
// begin canvas code
ctx.fillStyle = "rgb(200,0,0)";
ctx.fillRect (10, 10, 50, 50);
ctx.fillStyle = "rgba(0, 0, 200, 0.5)";
ctx.beginPath();
ctx.arc (70, 70, 40, 0, Math.PI*2, true);
ctx.fill();
ctx.closePath();
}
}
window.addEventListener('load', init, false);
</script>
</head>
<body>
<h1>basic canvas</h1>
<canvas width="150" height="150"></canvas>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment