Draw colored polygon using passed in points * @param {Array } points - Array of Vector2 points * @param {Color} [color=WHITE] * @param {number} [lineWidth] * @param {Color} [lineColor=BLACK] * @param {Vector2} [pos=vec2()] - Offset to apply * @param {number} [angle] - Angle
(points, color=WHITE, lineWidth=0, lineColor=BLACK, pos=vec2(), angle=0, useWebGL=glEnable, screenSpace=false, context=undefined)
| 632 | * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] |
| 633 | * @memberof Draw */ |
| 634 | function drawPoly(points, color=WHITE, lineWidth=0, lineColor=BLACK, pos=vec2(), angle=0, useWebGL=glEnable, screenSpace=false, context=undefined) |
| 635 | { |
| 636 | ASSERT(isVector2(pos), 'pos must be a vec2'); |
| 637 | ASSERT(isArray(points), 'points must be an array'); |
| 638 | ASSERT(isColor(color) && isColor(lineColor), 'color is invalid'); |
| 639 | ASSERT(isNumber(lineWidth), 'lineWidth must be a number'); |
| 640 | ASSERT(isNumber(angle), 'angle must be a number'); |
| 641 | ASSERT(!context || !useWebGL, 'context only supported in canvas 2D mode'); |
| 642 | |
| 643 | if (useWebGL && glEnable) |
| 644 | { |
| 645 | ASSERT(!!glContext, 'WebGL is not enabled!'); |
| 646 | let size = vec2(1); |
| 647 | if (screenSpace) |
| 648 | [pos, size, angle] = screenToWorldTransform(pos, size, angle); |
| 649 | glDrawPointsTransform(points, color.rgbaInt(), pos.x, pos.y, size.x, size.y, angle); |
| 650 | if (lineWidth > 0) |
| 651 | glDrawOutlineTransform(points, lineColor.rgbaInt(), lineWidth, pos.x, pos.y, size.x, size.y, angle); |
| 652 | } |
| 653 | else |
| 654 | { |
| 655 | drawCanvas2D(pos, vec2(1), angle, false, context=> |
| 656 | { |
| 657 | context.fillStyle = color.toString(); |
| 658 | context.beginPath(); |
| 659 | for (const point of points) |
| 660 | context.lineTo(point.x, point.y); |
| 661 | context.closePath(); |
| 662 | context.fill(); |
| 663 | if (lineWidth) |
| 664 | { |
| 665 | context.strokeStyle = lineColor.toString(); |
| 666 | context.lineWidth = lineWidth; |
| 667 | context.stroke(); |
| 668 | } |
| 669 | }, screenSpace, context); |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | /** Draw colored ellipse using passed in point |
| 674 | * @param {Vector2} pos |
no test coverage detected