line()#

Draws a line (a direct path between two points) to the screen.

Examples#

example picture for line()
1def setup():
2    py5.line(30, 20, 85, 75)
example picture for line()
1def setup():
2    py5.line(30, 20, 85, 20)
3    py5.stroke(126)
4    py5.line(85, 20, 85, 75)
5    py5.stroke(255)
6    py5.line(85, 75, 30, 75)
example picture for line()
1def setup():
2    py5.size(100, 100, py5.P3D)
3    # drawing lines in 3D requires P3D
4    # as a parameter to size()
5    py5.line(30, 20, 0, 85, 20, 15)
6    py5.stroke(126)
7    py5.line(85, 20, 15, 85, 75, 0)
8    py5.stroke(255)
9    py5.line(85, 75, 0, 30, 75, -50)

Description#

Draws a line (a direct path between two points) to the screen. The version of line() with four parameters draws the line in 2D. To color a line, use the stroke() function. A line cannot be filled, therefore the fill() function will not affect the color of a line. 2D lines are drawn with a width of one pixel by default, but this can be changed with the stroke_weight() function. The version with six parameters allows the line to be placed anywhere within XYZ space. Drawing this shape in 3D with the z parameter requires the P3D parameter in combination with size() as shown in the third example.

Underlying Processing method: line

Syntax#

line(x1: float, y1: float, x2: float, y2: float, /) -> None
line(x1: float, y1: float, z1: float, x2: float, y2: float, z2: float, /) -> None

Parameters#

  • x1: float - x-coordinate of the first point

  • x2: float - x-coordinate of the second point

  • y1: float - y-coordinate of the first point

  • y2: float - y-coordinate of the second point

  • z1: float - z-coordinate of the first point

  • z2: float - z-coordinate of the second point

Updated on November 12, 2021 11:30:58am UTC