Skip to content

Instantly share code, notes, and snippets.

@sguzman
Created July 8, 2017 00:30
Show Gist options
  • Save sguzman/d5a05f5538651a440ecfb6d665c63fc9 to your computer and use it in GitHub Desktop.
Save sguzman/d5a05f5538651a440ecfb6d665c63fc9 to your computer and use it in GitHub Desktop.
2d HTML context example - draws a simple square with an arc on top
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Canvas 2d Example</title>
<style>
body {
margin: 0;
}
canvas {
position: absolute;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<canvas id="canvas">
</canvas>
<script>
const canvas = document.getElementById('canvas');
const context = canvas.getContext('2d');
context.fillStyle = 'blue';
context.fillRect(10, 20, 200, 100);
context.lineWidth = 5;
context.lineCap = 'round';
context.arc(50, 50, 20, 0, Math.PI, false);
context.stroke();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment