MCPcopy
hub / github.com/KilledByAPixel/LittleJS / drawRegularPoly

Function drawRegularPoly

src/engineDraw.js:607–621  ·  view source on GitHub ↗

Draw colored regular polygon using passed in number of sides * @param {Vector2} pos * @param {Vector2} [size=vec2(1)] * @param {number} [sides] * @param {Color} [color=WHITE] * @param {number} [lineWidth] * @param {Color} [lineColor=BLACK] * @param {number} [angle] * @param {b

(pos, size=vec2(1), sides=3, color=WHITE, lineWidth=0, lineColor=BLACK, angle=0, useWebGL=glEnable, screenSpace=false, context)

Source from the content-addressed store, hash-verified

605 * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
606 * @memberof Draw */
607function drawRegularPoly(pos, size=vec2(1), sides=3, color=WHITE, lineWidth=0, lineColor=BLACK, angle=0, useWebGL=glEnable, screenSpace=false, context)
608{
609 ASSERT(isVector2(size), 'size must be a vec2');
610 ASSERT(isNumber(sides), 'sides must be a number');
611
612 // build regular polygon points
613 const points = [];
614 const sizeX = size.x/2, sizeY = size.y/2;
615 for (let i=sides; i--;)
616 {
617 const a = (i/sides)*PI*2;
618 points.push(vec2(sin(a)*sizeX, cos(a)*sizeY));
619 }
620 drawPoly(points, color, lineWidth, lineColor, pos, angle, useWebGL, screenSpace, context);
621}
622
623/** Draw colored polygon using passed in points
624 * @param {Array<Vector2>} points - Array of Vector2 points

Callers 2

drawEllipseFunction · 0.85
gameRenderFunction · 0.85

Calls 5

vec2Function · 0.85
isVector2Function · 0.85
isNumberFunction · 0.85
drawPolyFunction · 0.85
ASSERTFunction · 0.70

Tested by

no test coverage detected