JSFiddle - React, Tailwind, and code Playground

by m1erickson

HTML

<canvas id="canvas" width=300 height=300></canvas>

JavaScript

var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");


var cx=150;
var cy=150;
var rectWidth=15;
var rectHeight=10;
var rotation=0;

requestAnimationFrame(animate);


function animate(){
    requestAnimationFrame(animate);
    
    ctx.clearRect(0,0,canvas.width,canvas.height);
    ctx.beginPath();
    ctx.arc(cx,cy,10,0,Math.PI*2);
    ctx.closePath();
    ctx.fill();
    ctx.save();
    ctx.translate(cx,cy);
    ctx.rotate(rotation);
    ctx.strokeRect(-rectWidth/2+20,-rectHeight/2,rectWidth,rectHeight);
    ctx.restore();
    
    rotation+=Math.PI/180;
}