goopylib.objects
|
An object representing a line connecting 2 points together. |
|
An object representing a triangle with 3 vertices. |
|
An object representing a quad with 4 vertices. |
|
An object representing an ellipse or oval |
|
An object representing a textured rectangle - an image |
- class Renderable
This is the base class from which all goopylib objects are derived. The methods provided can be called by any other goopylib objects.
- Raises
NotImplementedError – cannot directly initialize a Renderable
- draw(window: Window) Renderable
Draws the object to a window
- Parameters
window (
Window
) – the Window to draw to- Raises
TypeError – argument must be a Window
- Return type
- destroy() None
Destroys and undraws the object
- Return type
None
- is_drawn() bool
- Returns
bool
– whether the object has been drawn
- set_anchor(x: float, y: float) None
Sets the anchor (center) of the object to the specified coordinates
- Parameters
x (
float
) – in world coordinatesy (
float
) – in world coordinates
- Raises
TypeError – x and y must be numbers
- Return type
None
- reset_anchor() None
Resets the anchor of the object to its center (average of its vertices)
- Return type
None
- move(dx: float, dy: float) None
Moves (translates) the object across the screen
- Parameters
dx (
float
) – in world coordinatesdy (
float
) – in world coordinates
- Raises
TypeError – dx and dy must be numbers
- Return type
None
- rotate(angle: float) None
Rotates the object
- Parameters
angle (
float
) – in degrees- Raises
TypeError – angle must be a number
- Return type
None
- scale(*args: float) None
Scales the object
- Parameters
*args (
float
) – a float representing the scale amount. 2 floats to scale the x and y components individually.- Raises
TypeError – scale factor must be numbers
- Return type
None
- set_size(width: float, height: float) None
Sets the dimensions of the object by resizing it
- Parameters
width (
float
) – in world coordinatesheight (
float
) – in world coordinates
- Raises
TypeError – width and height must be numbers
- Return type
None
- property x: float
The x-position of the object’s anchor in world coordinates
- Raises
TypeError – value must be a number
- Return type
float
- property y: float
The y-position of the object’s anchor in world coordinates
- Raises
TypeError – value must be a number
- Return type
float
- property position: tuple[float, float]
The position of the object’s anchor in world coordinates
- Returns
a tuple
(x, y)
with the position- Raises
TypeError – value must be a tuple of x, y numbers
- property rotation: float
The rotation of the object in degrees
- Raises
TypeError – value must be a number
- Return type
float
- property xscale: float
The x-scale of the object in %
- Raises
TypeError – value must be a number
- Return type
float
- property yscale: float
The y-scale of the object in %
- Raises
TypeError – value must be a number
- Return type
float
- property width: float
The width of the object in world coordinates
- Raises
TypeError – value must be a number
- Return type
float
- property height: float
The height of the object in world coordinates
- Raises
TypeError – value must be a number
- Return type
float
- hide(hide=True) None
Hides the object from the window
- Parameters
hide (default:
True
) – whether to hide or show- Raises
TypeError – hide must be a boolean
- Return type
None
- show() None
Unhides the object if it was hidden
- Return type
None
- Returns
bool
– whether the object is hidden
- box_contains(x: float, y: float) None
Checks if the object’s rectangular bounding box contains a point
- Parameters
x (
float
) – in world coordinatesy (
float
) – in world coordinates
- Raises
TypeError – x and y must be numbers
- Return type
None
- contains(x: float, y: float) None
Checks if the object’s bounding box contains a point
- Parameters
x (
float
) – in world coordinatesy (
float
) – in world coordinates
- Raises
TypeError – x and y must be numbers
- Return type
None