Last active
June 23, 2018 10:30
-
-
Save supergoat/bf948e6647ee08a7ebc1b341f63b1ffd to your computer and use it in GitHub Desktop.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Snake Game</title> | |
</head> | |
<body> | |
<canvas id="gameCanvas" width="300" height="300"></canvas> | |
<script> | |
/** CONSTANTS **/ | |
const CANVAS_BORDER_COLOUR = 'black'; | |
const CANVAS_BACKGROUND_COLOUR = "white"; | |
// Get the canvas element | |
var gameCanvas = document.getElementById("gameCanvas"); | |
// Return a two dimensional drawing context | |
var ctx = gameCanvas.getContext("2d"); | |
// Select the colour to fill the canvas | |
ctx.fillStyle = CANVAS_BACKGROUND_COLOUR; | |
// Select the colour for the border of the canvas | |
ctx.strokestyle = CANVAS_BORDER_COLOUR; | |
// Draw a "filled" rectangle to cover the entire canvas | |
ctx.fillRect(0, 0, gameCanvas.width, gameCanvas.height); | |
// Draw a "border" around the entire canvas | |
ctx.strokeRect(0, 0, gameCanvas.width, gameCanvas.height); | |
</script> | |
</body> | |
</html> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment