Line
A brief reference to the Line class.
Line contains some methods also found in Renderable, but is not a Renderable, as it does not possess a width and height.

Initialization

You can initialize a Line in a few different ways:
1
line = Line(screen, x1, y1, x2, y2) # Pass two points
2
line = Line(screen, (x1, y1), (x2, y2)) # Two points as tuples
3
line = Line(screen, location1, location2) # Two points as Locations
Copied!

Movement

You can move the Line using slightly modified methods from Object:
We can translate by a specified amount with:
1
line.move(dx, dy) # Move both points by dx, dy
2
line.move(dx, dy, point=1) # Move only the first point by dx, dy
Copied!
We can move both positions to new locations with:
1
line.moveto(x1, y1, x2, y2)
2
line.moveto((x1, y1), (x2, y2))
3
line.moveto(location1, location2)
Copied!
We can change only one of the positions with either:
1
line.pos1(location)
Copied!
1
line.pos2(location)
Copied!
Most methods in Line are able to take numbers, tuples, or Locations because Lines deal with more coordinates than Renderables.

Location

Retrieve both positions in a tuple using the familiar:
1
line.location() # Returns both endpoints positions as a tuple (pos1, pos2)
Copied!

Rotation

You can rotate lines just as you would expect:
1
line.rotation() # Get the current rotation
2
line.rotation(rotation) # Set a new angle
Copied!
1
line.rotate(angle_change) # Change angle by angle_change
Copied!
Or we can pass a location in for the line to look at:
1
line.lookat(location) # Look at the passed location (moves second endpoint)
2
line.lookat(location, point=1) # Move the first point instead
Copied!

Color

You can change the Color of a Line just like a Renderable:
1
line.color() # Retrieve the current Color
2
line.color(color) # Set a new Color
Copied!

Thickness

You can modify the thickness of the line in pixels with:
1
line.thickness(thickness)
Copied!

Dashes

You may decide to change the line to a dotted line with:
1
line.dashes(3) # Add dashes 3px in length with 3px between them
2
line.dashes((3, 2)) # Specify dash length and distance separately.
Copied!

Length

You can get the length of the line by calling:
1
line.length()
Copied!

Visibility

Visibility is accessed exactly as it is in Renderable:
1
line.visible(False)
Copied!

Transform and Cloning

Transforms and cloning work as in Renderable:
1
line.transform() # (pos1, pos2, angle)
Copied!
Line's transform is a tuple with both positions and current angle.
Cloning works as expected:
1
line2 = line.clone() # new line that's the same!
Copied!

Intersects (Overlaps)

The Line's version of Renderable's overlaps() is intersects(). It can take any Renderable or Line and will check if the line intersects with any of their lines.
1
line.intersects(line2)
2
line.intersects(rectangle)
Copied!
Last modified 6mo ago