Skip to content

Instantly share code, notes, and snippets.

@Skoatpalace
Created August 24, 2020 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Skoatpalace/0da01c32e63a0d0939667ba5091229cc to your computer and use it in GitHub Desktop.
Save Skoatpalace/0da01c32e63a0d0939667ba5091229cc to your computer and use it in GitHub Desktop.
Canvas HTML Rosace
const canvas = document.getElementById('canvas');
let ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let x = 0;
let y = 0;
let tour = 0;
ctx.translate(innerWidth / 2, innerHeight / 2);
const draw = () => {
requestAnimationFrame(draw);
ctx.beginPath();
ctx.strokeStyle = '#EDF5E1';
ctx.arc(x, y, 100, 0, 2 * Math.PI);
ctx.stroke();
ctx.rotate(10 * Math.PI / 180);
tour = tour + 10;
if (tour > 7200) {
return;
}
if (tour % 360 === 0) {
x += 7;
y += 7;
}
}
draw();
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Rosace canvas</title>
<style>
* {
margin: 0;
padding: 0;
}
html, body {
width: 100%;
height: 100%;
}
canvas {
display: block;
background: #282828;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script src='app.js'></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment