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

Function drawLine

src/engineDraw.js:584–593  ·  view source on GitHub ↗

Draw colored line between two points * @param {Vector2} posA * @param {Vector2} posB * @param {number} [width] * @param {Color} [color=WHITE] * @param {Vector2} [pos=vec2()] - Offset to apply * @param {number} [angle] - Angle to rotate by * @param {boolean} [useWebGL=glEnable] *

(posA, posB, width=.1, color=WHITE, pos=vec2(), angle=0, useWebGL=glEnable, screenSpace=false, context)

Source from the content-addressed store, hash-verified

582 * @param {CanvasRenderingContext2D|OffscreenCanvasRenderingContext2D} [context]
583 * @memberof Draw */
584function drawLine(posA, posB, width=.1, color=WHITE, pos=vec2(), angle=0, useWebGL=glEnable, screenSpace=false, context)
585{
586 const halfDelta = vec2((posB.x - posA.x)/2, (posB.y - posA.y)/2);
587 const size = vec2(width, halfDelta.length()*2);
588 pos = pos.add(posA.add(halfDelta));
589 if (screenSpace)
590 halfDelta.y *= -1; // flip angle Y if screen space
591 angle += halfDelta.angle();
592 drawRect(pos, size, color, angle, useWebGL, screenSpace, context);
593}
594
595/** Draw colored regular polygon using passed in number of sides
596 * @param {Vector2} pos

Callers 12

debugRenderFunction · 0.85
drawFixtureMethod · 0.85
setupDebugDrawFunction · 0.85
gameRenderPostFunction · 0.85
renderMethod · 0.85
gameRenderPostFunction · 0.85
gameRenderPostFunction · 0.85
gameRenderFunction · 0.85
gameRenderFunction · 0.85
gameRenderFunction · 0.85
drawArrowFunction · 0.85
gameRenderFunction · 0.85

Calls 5

vec2Function · 0.85
drawRectFunction · 0.85
lengthMethod · 0.80
addMethod · 0.45
angleMethod · 0.45

Tested by

no test coverage detected