Renderable
Renderable serves as the base class for any object with a width and height (most notably excluding lines and dots). The Renderable class does extend the Object class which tracks location and updates.
Quick Reference can help with simple issues or give you a basic understanding of the methods available, but it can never replace full documentation which is available here.
Initialization
We can initialize the default 3 shapes by calling their respective constructors:
The constructor has more arguments that are optional:
It's crucial to note that all Renderables are rendered from the top-left. So the passed (x, y) for a Rectangle would be its top left corner.
Types
There are a few different Renderables that can be created:
Although Text is classified as a Renderable, it is not directly resizable and has specific methods unique to Text: Reference.
Movement
Moving any Renderable is alike to moving a Location:
We can also make a Renderable move forward at its current heading/angle via:
Note that these methods utilize the Renderables rotation.
Location
You can also retrieve the Location with:
Center
You can get the Location of the center of any Renderable:
Note: This calculates the center by default (except for CustomPolygons), but you can get the centroid of the shape by setting centroid=True
in the method arguments.
You can also use this method to move the Renderable to place its center in a certain location:
Rotation
You can get or modify the rotation of a Renderable like so:
You can also just make a Renderable look at a Location or Renderable:
You can also check the angle of the Renderable against any Object or Location:
Size
You can retrieve or modify the size of the Renderable like so:
Note: Width and Height refer to the width and height of the original shape, regardless of rotation.
Color
All Renderables have a default Color of black; the color can be retrieved or set via:
Border and Fill
Renderables also have an optional border that is set to Color.NONE by default. You can set or retrieve the border like so:
You can get or set the border_width
seperately with:
Fill exists (as seen above) to create Framed Renderables with ease. Fill can be toggled without calling the border()
method like so:
Visibility
You can make any Object in pyDraw invisible with:
Ordering
You can move objects to the front or back of layers with:
Distance
You can get the distance between a Renderable and another Renderable, or Location like so:
Transform and Cloning
A transform is a data structure that represents the width, height, and rotation. You can copy the transform of a Renderable and set it to another transform:
You should only set the transform to other transforms retrieved from Renderables, however, it is possible to create one yourself:
You can also clone a Renderable by calling the aptly named:
Vertices
For those who want to perform more advanced mathematics with their shapes, you can retrieve a (copy) list of vertices:
Vertices usually will begin at the top left and work clockwise.
Bounds
You can get the location and dimensions of a bounding box calculated by pyDraw around any Renderable:
Contains and Overlaps
You can check if a point is contained in any Renderable like so:
Or you can check if two Renderables are overlapping:
Last updated