Skip to content

Instantly share code, notes, and snippets.

@Yumshot
Created March 27, 2023 15:59
Show Gist options
  • Save Yumshot/8c528e71e4e802f4c70ffc92d82862b1 to your computer and use it in GitHub Desktop.
Save Yumshot/8c528e71e4e802f4c70ffc92d82862b1 to your computer and use it in GitHub Desktop.
const canvas = document.querySelector<HTMLCanvasElement>('#myCanvas')!
const ctx: CanvasRenderingContext2D | null = canvas.getContext("2d");
export function drawBoundingBox() {
if (!ctx) return;
const side = Math.min(canvas.width, canvas.height);
const centerX = canvas.width / 2;
const centerY = canvas.height / 2;
const radius = side / 2;
ctx.beginPath();
ctx.moveTo(centerX + radius, centerY);
for (let i = 1; i <= 7; i++) {
const angle = i * Math.PI / 4;
const x = centerX + radius * Math.cos(angle);
const y = centerY + radius * Math.sin(angle);
ctx.lineTo(x, y);
}
ctx.closePath();
ctx.stroke();
}
const main = () => drawBoundingBox();
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment