Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Created April 27, 2020 11:53
Show Gist options
  • Save sandrabosk/9f331fed0b0b6e0a0f3311a3b871c1d6 to your computer and use it in GitHub Desktop.
Save sandrabosk/9f331fed0b0b6e0a0f3311a3b871c1d6 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.strokeStyle = 'rgb(0, ' + Math.floor(255 - 42.5 * i) + ', ' +
Math.floor(255 - 42.5 * j) + ')';
ctx.beginPath();
ctx.arc(12.5 + j * 25, 12.5 + i * 25, 10, 0, Math.PI * 2, true);
ctx.stroke();
}
}
}
draw();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment