Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Created April 27, 2020 11:51
Show Gist options
  • Save sandrabosk/8dcb20209e68bd7096fe00c8e10eafce to your computer and use it in GitHub Desktop.
Save sandrabosk/8dcb20209e68bd7096fe00c8e10eafce to your computer and use it in GitHub Desktop.
<!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>
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