Draw connected lines between a series of points * @param {Array } points * @param {number} [width] * @param {Color} [color=WHITE] * @param {boolean} [wrap] - Should the last point connect to the first? * @param {Vector2} [pos=vec2()] - Offset to apply * @param {number} [angle
(points, width=.1, color=WHITE, wrap=false, pos=vec2(), angle=0, useWebGL=glEnable, screenSpace=false, context)
| 533 | * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context] |
| 534 | * @memberof Draw */ |
| 535 | function drawLineList(points, width=.1, color=WHITE, wrap=false, pos=vec2(), angle=0, useWebGL=glEnable, screenSpace=false, context) |
| 536 | { |
| 537 | ASSERT(isArray(points), 'points must be an array'); |
| 538 | ASSERT(isNumber(width), 'width must be a number'); |
| 539 | ASSERT(isColor(color), 'color is invalid'); |
| 540 | ASSERT(isVector2(pos), 'pos must be a vec2'); |
| 541 | ASSERT(isNumber(angle), 'angle must be a number'); |
| 542 | ASSERT(!context || !useWebGL, 'context only supported in canvas 2D mode'); |
| 543 | |
| 544 | if (useWebGL && glEnable) |
| 545 | { |
| 546 | ASSERT(!!glContext, 'WebGL is not enabled!'); |
| 547 | let size = vec2(1); |
| 548 | if (screenSpace) |
| 549 | [pos, size, angle] = screenToWorldTransform(pos, size, angle); |
| 550 | glDrawOutlineTransform(points, color.rgbaInt(), width, pos.x, pos.y, size.x, size.y, angle, wrap); |
| 551 | } |
| 552 | else |
| 553 | { |
| 554 | // normal canvas 2D rendering method (slower) |
| 555 | ++drawCount; |
| 556 | ++primitiveCount; |
| 557 | drawCanvas2D(pos, vec2(1), angle, false, (context)=> |
| 558 | { |
| 559 | context.strokeStyle = color.toString(); |
| 560 | context.lineWidth = width; |
| 561 | context.beginPath(); |
| 562 | for (let i=0; i<points.length; ++i) |
| 563 | { |
| 564 | const point = points[i]; |
| 565 | context.lineTo(point.x, point.y); |
| 566 | } |
| 567 | wrap && context.closePath(); |
| 568 | context.stroke(); |
| 569 | }, screenSpace, context); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | /** Draw colored line between two points |
| 574 | * @param {Vector2} posA |
no test coverage detected