Created
April 27, 2020 11:51
-
-
Save sandrabosk/8dcb20209e68bd7096fe00c8e10eafce to your computer and use it in GitHub Desktop.
This file contains hidden or 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 lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<title>Canvas Animations</title> | |
</head> | |
<body> | |
<canvas id="canvas" width="150" height="150"></canvas> | |
<!-- add js file in the end when the DOM is already loaded --> | |
<script src="index.js"></script> | |
</body> | |
</html> |
This file contains hidden or 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
function draw() { | |
const ctx = document.getElementById('canvas').getContext('2d'); | |
for (let i = 0; i < 6; i++) { | |
for (let j = 0; j < 6; j++) { | |
ctx.fillStyle = 'rgb(' + Math.floor(255 - 42.5 * i) + ', ' + | |
Math.floor(255 - 42.5 * j) + ', 100)'; | |
ctx.fillRect(j * 25, i * 25, 25, 25); | |
} | |
} | |
} | |
draw(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment