Skip to content

Line

Lines are drawn between a starting point (x1, y1) and an ending point (x2, y2).

Creating a Line

You can create a Line using the following functions:

line = Line(x1, y1, x2, y2)
Line(x1, y1, x2, y2, color, thickness, rotation, visibility)
Parameter Type Default Description
x1 int or float required The horizontal position of one end, in pixels.
y1 int or float required The vertical position of one end, in pixels.
x2 int or float required The horizontal position of the other end, in pixels.
y2 int or float required The vertical position of the other end, in pixels.
color Color Color.BLACK The color.
thickness int 1 The line thickness, in pixels.
rotation int or float 0 How far to turn the line, in degrees, counter-clockwise.
visibility int 100 How visible the line is, from 0 (invisible) to 100 (fully visible).

For example,

line = Line(100, 100, 200, 200)

Once created, you can add it to a Display using the Display's add() function.

Functions

Once a Line line has been created, the following functions are available:

Position

Function Description
line.getPosition() Return the object's position, the top-left corner of its bounding box.
line.getX() Return the object's horizontal position.
line.getY() Return the object's vertical position.
line.getCenter() Return the object's center point.
line.getCenterX() Return the object's horizontal center.
line.getCenterY() Return the object's vertical center.
line.setPosition(x, y) Move the object so the top-left corner of its bounding box sits at the given point.
line.setX(x) Set the object's horizontal position.
line.setY(y) Set the object's vertical position.
line.setCenter(x, y) Move the object so its center sits at the given point.
line.setCenterX(x) Set the object's horizontal center.
line.setCenterY(y) Set the object's vertical center.
line.move(x, y) Move the object to a new position.

Size

Function Description
line.getLength() Return the line's length.
line.getSize() Return the object's width and height.
line.getWidth() Return the object's width.
line.getHeight() Return the object's height.
line.setLength(length) Set the line's length.
line.setSize(width, height) Set the object's width and height.
line.setWidth(width) Set the object's width.
line.setHeight(height) Set the object's height.

Rotation

Function Description
line.getRotation() Return how far the object is turned.
line.setRotation(rotation) Turn the object to a given angle.
line.rotate(angle) Turn the object by an additional angle.

Visibility

Function Description
line.getVisibility() Return how visible the object is.
line.setVisibility(visibility) Set how visible the object is.

Color

Function Description
line.getColor() Return the shape's color.
line.getFill() Report whether the shape is filled in.
line.getThickness() Return the shape's outline thickness.
line.setColor() Set the shape's color.
line.setFill(fill) Set whether the shape is filled in.
line.setThickness(thickness) Set the shape's outline thickness.

Information

Function Description
line.getEndpoints() Return the object's endpoints.
line.getBoundingBox() Return the smallest upright box that surrounds the object.
line.getGroup() Return the Group this object belongs to.
line.getDisplay() Return the Display this object is on.
line.setToolTipText() Set the hover text shown over the object.

Hit Testing

Function Description
line.contains(x, y) Report whether a point lies on the line.
line.intersects(other) Report whether this object overlaps another.
line.encloses(other) Report whether this object completely contains another.

Events

Function Description
line.onMouseClick(action) Set up a function to call when the mouse is clicked on this object.
line.onMouseDown(action) Set up a function to call when the mouse button is pressed on this object.
line.onMouseUp(action) Set up a function to call when the mouse button is released over this object.
line.onMouseMove(action) Set up a function to call when the mouse moves over this object.
line.onMouseDrag(action) Set up a function to call when the mouse is dragged over this object.
line.onMouseEnter(action) Set up a function to call when the mouse moves onto this object.
line.onMouseExit(action) Set up a function to call when the mouse moves off this object.
line.onKeyType(action) Set up a function to call when a key is typed (pressed and released).
line.onKeyDown(action) Set up a function to call when a key is pressed down.
line.onKeyUp(action) Set up a function to call when a key is released.