-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
363202f
commit aee0ee7
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Document</title> | ||
</head> | ||
<body> | ||
<canvas id="c" width="800" height="600"></canvas> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
let height = 0; | ||
let width = 0; | ||
let tick = 0; | ||
let ctx; | ||
|
||
window.onload = function() { | ||
const canvas = document.querySelector("#c"); | ||
if (!canvas) { | ||
console.error("No Canvas Found"); | ||
return; | ||
} | ||
height = canvas.height; | ||
width = canvas.width; | ||
ctx = canvas.getContext("2d"); | ||
if (!ctx) { | ||
console.error("Could Not Get Context"); | ||
return; | ||
} | ||
requestAnimationFrame(main); | ||
} | ||
|
||
|
||
|
||
function main(timeStamp) { | ||
if (tick == 0) { | ||
tick = timeStamp; | ||
} | ||
const dt = timeStamp - tick; | ||
tick = timeStamp; | ||
render(); | ||
requestAnimationFrame(main); | ||
} | ||
|
||
function blackoutCanvas() { | ||
ctx.fillStyle = 'black'; | ||
ctx.fillRect(0,0, width, height); | ||
} | ||
|
||
function drawRectangle(x, y, width, height, color) { | ||
ctx.fillStyle = color; | ||
ctx.fillRect(x, y, width, height); | ||
} | ||
|
||
function render() { | ||
blackoutCanvas(); | ||
drawRectangle(10, 10, 10, 10, 'blue'); | ||
} |