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)
| 605 | * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] |
| 606 | * @memberof Draw */ |
| 607 | function 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 |