Created
March 27, 2023 15:59
-
-
Save Yumshot/8c528e71e4e802f4c70ffc92d82862b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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