MCPcopy Create free account
hub / github.com/dashrobotco/robot-components / drawRoundedTriangle

Function drawRoundedTriangle

app/nodegrid/page.tsx:2422–2457  ·  view source on GitHub ↗
(ctx: CanvasRenderingContext2D, size: number, radius: number)

Source from the content-addressed store, hash-verified

2420
2421 // Draw rounded triangle
2422 const drawRoundedTriangle = (ctx: CanvasRenderingContext2D, size: number, radius: number) => {
2423 const h = size * 0.866; // height factor
2424 const points = [
2425 { x: 0, y: -size },
2426 { x: -h, y: size * 0.5 },
2427 { x: h, y: size * 0.5 }
2428 ];
2429
2430 ctx.beginPath();
2431 for (let i = 0; i < 3; i++) {
2432 const curr = points[i];
2433 const next = points[(i + 1) % 3];
2434 const prev = points[(i + 2) % 3];
2435
2436 // Direction vectors
2437 const dx1 = curr.x - prev.x;
2438 const dy1 = curr.y - prev.y;
2439 const dx2 = next.x - curr.x;
2440 const dy2 = next.y - curr.y;
2441
2442 const len1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
2443 const len2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
2444
2445 // Points offset from corner
2446 const offset = Math.min(radius, len1 / 2, len2 / 2);
2447 const p1x = curr.x - (dx1 / len1) * offset;
2448 const p1y = curr.y - (dy1 / len1) * offset;
2449 const p2x = curr.x + (dx2 / len2) * offset;
2450 const p2y = curr.y + (dy2 / len2) * offset;
2451
2452 if (i === 0) ctx.moveTo(p1x, p1y);
2453 else ctx.lineTo(p1x, p1y);
2454 ctx.quadraticCurveTo(curr.x, curr.y, p2x, p2y);
2455 }
2456 ctx.closePath();
2457 };
2458
2459 // Draw rounded square
2460 const drawRoundedSquare = (ctx: CanvasRenderingContext2D, size: number, radius: number) => {

Callers 2

drawParticleFunction · 0.85
drawBouncyParticleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected