JSFiddle - React, Tailwind, and code Playground
by Yaroslav Samardak
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<canvas id="canvas" width="400" height="400"></canvas>
</body>
</html>
CSS
body {
margin: 0;
display: flex;
width: 100vw;
height: 100vh;
align-items: center;
justify-content: center;
background-color: #F0F0F0;
}
canvas {
background: #FFF;
width: 200px;
height: 200px;
border: 1px solid black;
border-radius: 4px;
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}
JavaScript
window.onload = () => {
const c = document.getElementById('canvas').getContext('2d');
c.lineWidth = 2;
let r = 0.2, dr = -0.01;
const draw = () => {
c.clearRect(0, 0, 400, 400);
c.beginPath();
c.moveTo(200, 200);
c.arc(200, 200, 100, r * Math.PI, Math.PI * (2 - r), false);
c.lineTo(200, 200);
r += dr;
if (r <= 0.05 || r >= 0.2) dr = -dr;
c.stroke();
window.requestAnimationFrame(draw);
}
draw();
}