line
line(x1: number, y1: number, x2: number, y2: number) => void
Draws a straight line between two points.
Parameters
x1: First point x-coordinatey1: First point y-coordinatex2: Second point x-coordinatey2: Second point y-coordinate
Example
// Basic line
K.line(10, 10, 90, 90)
// Styled line
K.strokeColor("red")
K.strokeWidth(5)
K.line(100, 200, 300, 100)
// In JSX component
const draw = (K: KlintContext) => {
K.strokeColor("blue")
K.strokeWidth(3)
K.line(50, 50, K.width-50, K.height-50)
}
Notes
- Uses current stroke style and width
- No effect if stroke is disabled via
K.noStroke() - For best performance with many lines or lines that needs to make shapes, use
K.beginShape()andK.vertex()