Skip to content

Polyline

Polylines are a series of connected lines, drawn using two parallel lists of x and y coordinates. Unlike a Polygon, the path is open (the last corner is not joined back to the first).

Creating a Polyline

You can create a Polyline using the following functions:

Polyline(xPoints, yPoints)
Polyline(xPoints, yPoints, color, thickness, rotation, visibility)
Parameter Type Default Description
xPoints list[int or float] required The horizontal positions of the corners, in pixels.
yPoints list[int or float] required The vertical positions of the corners, 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 shape, in degrees, counter-clockwise.
visibility int 100 How visible the shape is, from 0 (invisible) to 100 (fully visible).

For example,

polyline = Polyline([312, 366, 510, 443], [244, 210, 312, 346])

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

Functions

Once a Polyline polyline has been created, the following functions are available:

Position

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

Size

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

Rotation

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

Visibility

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

Color

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

Information

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

Hit Testing

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

Events

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