What is it?
goopylib is powerful game, graphics, and GUI library for Python and C++ to build cross-platform applications. It allows you to unlock the potential of OpenGL and low-level graphics with a high-level, simple-yet-powerful API.
Find the source code on GitHub.
Key Features:
Cross-Platform & Powerful
Fast! Built-in batch-rendering & optimizations
Accessible through Python & C++
Simple code to create, transform, & animate images, quads, triangles, circles, and more
Automatic 2D Orthographic Camera & Camera Controller
Window & Mouse events: key & button presses, several callbacks, etc.
- In Development:
Text Rendering
GUI Elements
Animation Engine
Texture Factory
Low-Level API Access
- Future Plans:
2D Rigid-Body Physics Engine
Sound & Lighting Engine
Profiling Tools
Build & Distribution Tools
Installation
Requires Python ≥ 3.8. To install goopylib on Windows or MacOS, use the Python Package Index (PyPI):
pip install goopylib
See the Installation Guide for more details.
Contributions
Contributions to goopylib are absolutely welcome! Please reach out to me if you have an idea or feature request or submit a pull request yourself. I’d love to hear if you’ve used goopylib for a project - maybe we could even add some screenshots to a gallery.
goopylib is licensed under the Mozilla Public License Version 2.0 which essentially enables you use and modify goopylib (commercially or otherwise) as long as you attribute the project! See choosealicense.com for more details.
Contents
Installation Guide
To install goopylib on Windows or MacOS, use the Python Package Index (PyPI):
pip install goopylib
Wheels for Linux are not currently supported but coming as soon as I can build them!
Warning
The minimum required Python version is Python 3.8.
Building goopylib using CMake
To build goopylib from source, you will first need to download or compile the GLFW library. Pre-built binaries are available for Windows 64-bit or 32-bit systems and Apple Intel/Apple Silicon here. Follow this guide to compile GLFW yourself.
Next, download goopylib’s source distribution from GitHub or clone it using git:
git clone https://github.com/BhavyeMathur/goopylib.git goopylib
Then, build the library using CMake:
mkdir build
cd build
cmake ..
cmake --build
Finally, you can build the Python/C++ extensions by running the following commands in the goopylib directory:
python setup_extensions.py build
Getting Started
API Reference
goopylib is powerful game, graphics, and GUI library for Python and C++ to build cross-platform applications. It allows you to unlock the potential of OpenGL and low-level graphics with a high-level, simple-yet-powerful API.
The library includes a few key components such as the window, colors, and renderable objects as well as helper classes such as camera controllers, easing functions, and more!
To begin, import the library, set-up a controller, and begin drawing objects:
import goopylib as gp
window = gp.Window(600, 400, "Here's a window!")
controller = gp.CameraController(window)
circle = gp.Circle((0, 0), 30).draw(window)
while window.is_open():
controller.update() # use WASD to move around, QE to rotate, +- to zoom
gp.update()
gp.terminate() # make sure to terminate the library once you're done
Explore the key submodules:
goopylib.core
This is goopylib’s most important module. It defines core and miscellaneous functions that allow you to configure and use the library. The module is automatically imported and initializes the underlying API.
It can be used to configure global settings, initialize/terminate the library, and gather runtime or compilation information about goopylib.
- init() None
Initializes goopylib internally. This function is automatically called when goopylib is imported.
- Raises
RuntimeError – if the initialization fails
- Return type
None
- terminate() None
Terminates goopylib internally and destroys all open windows. You should call this function before the program ends.
Note
goopylib can be reinitialized using
gp.init()
- Return type
None
- update() None
Updates goopylib and its windows.
Examples
The following is a standard goopylib mainloop:
window = gp.Window(500, 500) while window.is_open(): gp.update()
- Return type
None
- update_on_event() None
Updates goopylib every time an event occurs. These can be key presses, cursor movement, window resizing, or others.
- Return type
None
- update_timeout(timeout: float = 0) None
Updates goopylib after a duration has passed.
- Parameters
timeout (
float
, default:0
) – the duration (seconds) to wait between updates.- Raises
ValueError – if timeout is less than 0
- Return type
None
- set_buffer_swap_interval(interval: int) None
Sets the rate of swapping window buffers.
- Parameters
interval (
int
) – the number of refreshes to wait before swapping buffers.- Raises
TypeError – if a non-integer value is passed.
ValueError – if interval is less than 0
- Return type
None
- get_refresh_rate() int
Returns the refresh rate of the primary monitor.
- Returns
int
– the refresh rate in Hertz- Raises
RuntimeError – if goopylib has not been initialized
- get_screen_width() int
Returns the width of the primary monitor.
- Returns
int
– the screen width in screen coordinates- Raises
RuntimeError – if goopylib has not been initialized
- get_screen_height() int
Returns the height of the primary monitor.
- Returns
int
– the screen height in screen coordinates- Raises
RuntimeError – if goopylib has not been initialized
- number_of_monitors() int
Returns the number of monitors connected.
- Raises
RuntimeError – if goopylib has not been initialized
- Return type
int
- glfw_compiled_version() str
Returns the version of GLFW that goopylib was compiled with.
- Return type
str
- glfw_current_version() str
Returns the version of GLFW that is currently running.
- Return type
str
- opengl_version() str
Returns the version of OpenGL being used.
- Return type
str
goopylib.window
- class Window(width: int, height: int, title: str = 'goopylib Window')
Creates a window that can be used to draw graphics and widgets.
- Parameters
width (
int
) – in screen coordinatesheight (
int
) – in screen coordinatestitle (
str
, default:'goopylib Window'
) – displayed in the title bar
- is_closed() bool
- Returns
bool
– whether the window is closed.
- is_open() bool
- Returns
bool
– whether the window is open.
- is_destroyed() bool
- Returns
bool
– whether the window has been destroyed.
- update() None
Refreshes the window.
- Return type
None
- destroy() None
Destroys & closes the window.
Warning
Once the window is destroyed, accessing its attributes or calling its methods is undefined.
- Return type
None
Window Attributes
Window
instances have many attributes that can be modified to configure the look of the Window. Here is a list:Window.width
The width of the window.
Window.height
The height of the window.
Window.title
The title of the window.
Window.xpos
The x position of the window.
Window.ypos
The y position of the window.
Window.background
The background color of the window.
Window.min_width
The minimum width of the window.
Window.min_height
The minimum height of the window.
Window.max_width
The maximum width of the window.
Window.max_height
The maximum height of the window.
Window.resizable
Whether the window is resizable by the user or not.
Window.decorated
Whether the window has window decorations.
Window.floating
Whether the window is always on top.
Window.auto_minimized
Whether the window is automatically minimized when it loses focus.
Window.focused_on_show
Whether the window gains input focus when it is shown.
- set_size(width: int, height: int) None
Sets the size of the window.
- Parameters
width (
int
) – in screen coordinatesheight (
int
) – in screen coordinates
- Raises
TypeError – width and height must be integers
ValueError – width and height must be greater than 0
- Return type
None
- set_position(xpos: int, ypos: int) None
Sets the position of the top-left of the window on the screen.
- Parameters
xpos (
int
) – in screen coordinatesypos (
int
) – in screen coordinates
- Raises
TypeError – xpos and ypos must be integers
- Return type
None
- get_frame_size() tuple[int, int, int, int]
Gets the size, in screen coordinates, of the window frame.
Decorated windows have title bars and window frames around them. You can retrieve the sizes of these using this method. The returned values are the distances, in screen coordinates, from the edges of the content area to the corresponding edges of the full window. As they are distances and not coordinates, they are always zero or positive.
- Returns
The size of the window’s frame in order
(left, top, right, bottom)
- get_content_scale() tuple[float, float]
Gets the scale of the content on the window.
The content scale is the ratio between the current DPI and the platform’s default DPI.
- Returns
A tuple representing the content scale as
(xscale, yscale)
- get_framebuffer_size() tuple[int, int]
The size of the framebuffer for the window.
- Returns
A tuple
(width, height)
representing the dimensions, in pixels, of the framebuffer
Note
These methods only apply to
resizable
Windows- set_size_limits(min_width: int, min_height: int, max_width: int, max_height: int) None
Sets the minimum and maximum resizable dimensions of the window.
- Raises
TypeError – All the parameters must be integers or
None
ValueError –
min_width
andmin_height
must be greater than or equal to 0.max_width
andmax_height
must be greater than or equalmin_width
andmin_height
- Return type
None
- set_min_size(min_width: int, min_height: int) None
Sets the minimum resizable dimensions of the window.
- Raises
TypeError –
min_width
andmin_height
must be integersValueError –
min_width
andmin_height
must be greater than or equal to 0
- Return type
None
- set_max_size(max_width: int, max_height: int) None
Sets the maximum resizable dimensions of the window.
- Raises
TypeError –
max_width
andmax_height
must be integers orNone
ValueError –
max_width
andmax_height
must be greater than or equal tomin_width
andmin_height
.
- Return type
None
- get_aspect_ratio() tuple[int, int]
Gets the current aspect ratio of the window.
- Returns
A tuple representing the aspect ratio as
(numerator, denominator)
- set_aspect_ratio(numerator: int, denominator: int) None
Sets the aspect ratio of the window.
The aspect ratio is specified as a numerator and denominator, corresponding to the width and height, respectively. If you want a window to maintain its current aspect ratio, use its current size as the ratio.
Set both arguments to
None
to remove any aspect ratio configuration.- Raises
TypeError – numerator and denominator must be integers or
None
ValueError – numerator and denominator must be greater than 0
- Return type
None
Window State Methods
- restore() None
Restores a minimized, maximized, or fullscreen window back to normal.
- Return type
None
- fullscreen() None
Makes the window enter fullscreen mode.
- Return type
None
- is_fullscreen() bool
- Returns
bool
– whether the window is in fullscreen mode.
- minimize() None
Minimizes the window.
- Return type
None
- is_minimized() bool
- Returns
bool
– whether the window is in minimized mode.
- maximize() None
Maximizes the window.
- Return type
None
- is_maximized() bool
- Returns
bool
– whether the window is in maximized mode.
- show() None
Makes the window visible to the user.
- Return type
None
- hide(hide: bool = True) None
Makes the window invisible to the user.
- Parameters
hide (
bool
, default:True
) – whether to hide/show the window- Return type
None
- is_visible() bool
- Returns
bool
– whether the window is visible to the user.
- focus() None
Gives the window input focus and brings it to the front.
- Return type
None
- has_focus() bool
- Returns
bool
– whether the window has input focus.
- request_attention() None
Requests for the user’s attention to the window.
The system will highlight the window, or on platforms where this is not supported, the application as a whole. Once the user has given it attention, the system will automatically end the request.
- Return type
None
Window Events
- is_mouse_hovering() bool
- Returns
bool
– whether the mouse is hovering over the window.
- get_mouse_position() tuple[float, float]
- Returns
a tuple
(xpos, ypos)
with the position of the mouse cursor
- set_cursor_mode(mode: str) None
- Normal:
makes the cursor visible and behave normally.
- Hidden:
hides the cursor when it is over the window.
- Disabled:
hides and grabs the cursor, providing virtual and unlimited cursor movement.
- Parameters
mode (
str
) – one of “Normal”, “Disabled”, or “Hidden”- Return type
None
- check_shift_key() bool
- Returns
bool
– whether the shift key is being pressed
- check_control_key() bool
- Returns
bool
– whether the control key is being pressed
- check_alt_key() bool
- Returns
bool
– whether the alt key is being pressed
- check_super_key() bool
- Returns
bool
– whether the super key is being pressed
- check_key(keycode: int) bool
- Parameters
keycode (
int
) – anint
corresponding to the keycode- Returns
bool
– whether the specified key is being pressed
- check_mouse_button(button: int) bool
- Parameters
button (
int
) – anint
corresponding to the mouse button- Returns
bool
– whether the specified mouse button is being pressed
- check_left_click() bool
- Returns
bool
– whether the left mouse button is being pressed
- check_middle_click() bool
- Returns
bool
– whether the middle mouse button is being pressed
- check_right_click() bool
- Returns
bool
– whether the right mouse button is being pressed
Camera & Projection
- to_world(x: float, y: float) tuple[float, float]
Converts coordinates in screen space to world space.
(0, 0) is the upper-left of the window in screen space
(width, height) is the lower-right in screen space
- Returns
a tuple
(x, y)
in world coordinates
- to_screen(x: float, y: float) tuple[float, float]
Converts coordinates in world space to screen space.
With the default camera projection,
(0, 0)
is the center in world space.- Returns
a tuple
(x, y)
in screen coordinates
Static Methods
- static update_all() None
Updates all the windows currently active.
- Return type
None
- static destroy_all() None
Destroys all active windows.
- Return type
None
Callback Functions
The Window
class provides several callback functions that can be set to execute code whenever certain events take place:
Callback executed when the window is resized. |
|
Callback executed when the window is attempted to be closed. |
|
Callback executed when the window is destroyed. |
|
Callback executed when the window is moved. |
|
Callback executed when the window is minimized. |
|
Callback executed when the window is maximized. |
|
Callback executed when the window gains input focus. |
|
Callback executed when the window needs refreshing. |
|
Callback executed when the window's content scale changes. |
|
Callback executed when the window's framebuffer size changes. |
|
Callback executed when the mouse moves. |
|
Callback executed when the mouse enters/exits the window. |
|
Callback executed when the mouse scrolls. |
|
Callback executed when the left mouse button is clicked. |
|
Callback executed when the middle mouse button is clicked. |
|
Callback executed when the right mouse button is clicked. |
These can be accessed and set like so:
def callback_function():
print("Window has been destroyed")
print(window.destroy_callback) # default value is None
window.destroy_callback = callback_function
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
goopylib.scene
- class Camera(left: float, right: float, bottom: float, top: float)
An orthographic camera associated with a Window.
- Parameters
left (
float
) – left clipping planeright (
float
) – right clipping planebottom (
float
) – bottom clipping planetop (
float
) – top clipping plane
- Raises
TypeError – arguments must be numbers
- set_projection(left: float, right: float, bottom: float, top: float) None
Sets an orthographic projection for the camera
- Parameters
left (
float
) – left clipping planeright (
float
) – right clipping planebottom (
float
) – bottom clipping planetop (
float
) – top clipping plane
- Raises
TypeError – arguments must be numbers
- Return type
None
- move(dx: float, dy: float) None
Moves (translate) the camera’s position
- Parameters
dx (
float
) – change in x positiondy (
float
) – change in y position
- Raises
TypeError – arguments must be numbers
- Return type
None
- rotate(angle: float) None
Rotates the camera
- Parameters
angle (
float
) – in degrees- Raises
TypeError – angle must be a number
- Return type
None
- zoomin(value: float) None
Zooms the camera in. A value less than 1 zooms the camera out.
- Parameters
value (
float
) – zoom amount- Raises
TypeError – zoom must be a number
- Return type
None
- property x: float
The x-position of the camera
- Raises
TypeError – value must be a number
- Return type
float
- property y: float
The y-position of the camera
- Raises
TypeError – value must be a number
- Return type
float
- property position: float
The position of the camera as an
(x, y)
tuple- Raises
TypeError – value must be a tuple of numbers
- Return type
float
- property rotation: float
The rotation of the camera in degrees
- Raises
TypeError – value must be a number
- Return type
float
- property zoom: float
The zoom amount of the camera in %
- Raises
TypeError – value must be a number
- Return type
float
Camera Controller
- class CameraController(window: Window)
Controller class that automatically manages camera movement, rotation, and zoom.
This is a helper class that wraps around a Window’s camera and provides basic but quick functionality
- Parameters
window (
Window
) – the window to use
- Raises
TypeError: window must be a goopylib Window
- update() None
Updates the controller. Call this method in the mainloop.
- Return type
None
- enable_movement(value: bool) None
Enables automatic camera movement when the control keys are pressed.
- Parameters
value (
bool
) – whether to enable or disable movement- Raises
TypeError – value must be a boolean
- Return type
None
- enable_rotation(value: bool) None
Enables automatic camera rotation when the control keys are pressed.
- Parameters
value (
bool
) – whether to enable or disable rotation- Raises
TypeError – value must be a boolean
- Return type
None
- enable_zoom(value: bool) None
Enables automatic camera zooming when the control keys are pressed.
- Parameters
value (
bool
) – whether to enable or disable zooming- Raises
TypeError – value must be a boolean
- Return type
None
- invert_movement(value: bool) None
Inverts camera movement.
- Parameters
value (
bool
) – whether to invert the movement- Raises
TypeError – value must be a boolean
- Return type
None
- invert_rotation(value: bool) None
Inverts camera rotation.
- Parameters
value (
bool
) – whether to invert the rotation- Raises
TypeError – value must be a boolean
- Return type
None
- property horizontal_speed: float
The horizontal movement speed of the camera.
- Returns
float
– the horizontal movement speed- Raises
TypeError – speed must be a number
- property vertical_speed: float
The vertical movement speed of the camera.
- Returns
float
– the vertical movement speed- Raises
TypeError – speed must be a number
- property rotate_speed: float
The rotational speed of the camera.
- Returns
float
– the rotation speed- Raises
TypeError – speed must be a number
- property zoom_speed: float
The zoom speed of the camera.
- Returns
float
– the zoom speed- Raises
TypeError – speed must be a number
- use_wasd() None
Binds the WASD keys for camera movement.
- Return type
None
- use_arrows() None
Binds the arrow keys for camera movement.
- Return type
None
- set_movement_keys(up: int, left: int, down: int, right: int) None
Sets the keys used for camera movement.
- Parameters
up (
int
) – key to use for moving upleft (
int
) – key to use for moving leftdown (
int
) – key to use for moving downright (
int
) – key to use for moving right
- Raises
TypeError – arguments must be keys
- Return type
None
- set_rotation_keys(clockwise: int, anticlockwise: int) None
Sets the keys used for camera rotation.
- Parameters
clockwise (
int
) – key to use for clockwise rotationanticlockwise (
int
) – key to use for anticlockwise rotation
- Raises
TypeError – arguments must be keys
- Return type
None
- set_zoom_keys(zoomin: int, zoomout: int) None
Sets the keys used for camera zooming.
- Parameters
zoomin (
int
) – key to use for zooming inzoomout (
int
) – key to use for zooming out
- Raises
TypeError – arguments must be keys
- Return type
None
goopylib.color
Create colors by passing RGB arguments or a hexstring. |
|
Create an RGB color by passing RGB arguments with an optional alpha parameter. |
|
Create a Hexadecimal color by passing a hexstring with an optional alpha parameter. |
|
Create a CMYK color by passing cyan, magenta, yellow, key and optionally, alpha. |
|
Create an HSV color by passing hue (0-360), saturation (0-1), value (0-1) and optionally, alpha (0-1) |
|
Create an HSL color by passing hue (0-360), saturation (0-1), luminance (0-1) and optionally, alpha (0-1) |
Random Colors
Use this module for simple random color generation in different formats.
RGB Conversions
- rgb_to_hex(red: int, green: int, blue: int) str
Converts a color from RGB to a Hexadecimal string
- Parameters
red (
int
) – between 0 and 255green (
int
) – between 0 and 255blue (
int
) – between 0 and 255
- Returns
str
– a hexstring in the format"#rrggbb"
- Raises
ValueError – if the inputs are outside their bounds
- rgb_to_cmyk(red: int, green: int, blue: int) tuple[float, float, float, float]
Converts a color from RGB to CMYK
- Parameters
red – between 0 and 255
green – between 0 and 255
blue – between 0 and 255
- Returns
a tuple of CMYK values between 0 and 1
- Raises
ValueError – if the inputs are outside their bounds
- rgb_to_hsv(red: int, green: int, blue: int) tuple[int, float, float]
Converts a color from RGB to HSV
- Parameters
red – between 0 and 255
green – between 0 and 255
blue – between 0 and 255
- Returns
a tuple of HSV values
- Raises
ValueError – if the inputs are outside their bounds
- rgb_to_hsl(red: int, green: int, blue: int) tuple[int, float, float]
Converts a color from RGB to HSL
- Parameters
red – between 0 and 255
green – between 0 and 255
blue – between 0 and 255
- Returns
a tuple of HSL values
- Raises
ValueError – if the inputs are outside their bounds
Hex Conversions
- hex_to_rgb(hexstring: str) tuple[int, int, int]
Converts a color hexstring to RGB
- Parameters
hexstring – a valid color hexadecimal string
- Returns
a tuple of RGB values between 0 and 255
- Raises
ValueError – if the hexstring is invalid
- hex_to_cmyk(hexstring: str) tuple[float, float, float, float]
Converts a color hexstring to CMYK
- Parameters
hexstring – a valid color hexadecimal string
- Returns
a tuple of CMYK values between 0 and 1
- Raises
ValueError – if the hexstring is invalid
- hex_to_hsv(hexstring: str) tuple[int, float, float]
Converts a color hexstring to HSV
- Parameters
hexstring – a valid color hexadecimal string
- Returns
a tuple of HSV values
- Raises
ValueError – if the hexstring is invalid
- hex_to_hsl(hexstring: str) tuple[int, float, float]
Converts a color hexstring to HSL
- Parameters
hexstring – a valid color hexadecimal string
- Returns
a tuple of HSL values
- Raises
ValueError – if the hexstring is invalid
CMYK Conversions
- cmyk_to_rgb(cyan: float, magenta: float, yellow: float, key: float) tuple[int, int, int]
Converts a color from CMYK to RGB
- Parameters
cyan – between 0 and 1
magenta – between 0 and 1
yellow – between 0 and 1
key – between 0 and 1
- Returns
a tuple of RGB values between 0 and 255
- Raises
ValueError – if the inputs are outside their bounds
- cmyk_to_hex(cyan: float, magenta: float, yellow: float, key: float) str
Converts a color from CMYK to a Hexadecimal String
- Parameters
cyan (
float
) – between 0 and 1magenta (
float
) – between 0 and 1yellow (
float
) – between 0 and 1key (
float
) – between 0 and 1
- Returns
str
– a hexstring in the format"#rrggbb"
- Raises
ValueError – if the inputs are outside their bounds
- cmyk_to_hsv(cyan: float, magenta: float, yellow: float, key: float) tuple[int, float, float]
Converts a color from CMYK to HSV
- Parameters
cyan – between 0 and 1
magenta – between 0 and 1
yellow – between 0 and 1
key – between 0 and 1
- Returns
a tuple of HSV values
- Raises
ValueError – if the inputs are outside their bounds
- cmyk_to_hsl(cyan: float, magenta: float, yellow: float, key: float) tuple[int, float, float]
Converts a color from CMYK to HSL
- Parameters
cyan – between 0 and 1
magenta – between 0 and 1
yellow – between 0 and 1
key – between 0 and 1
- Returns
a tuple of HSL values
- Raises
ValueError – if the inputs are outside their bounds
HSV Conversions
- hsv_to_rgb(hue: int, saturation: float, value: float) tuple[int, int, int]
Converts a color from HSV to RGB
- Parameters
hue – between 0 and 360
saturation – between 0 and 1
value – between 0 and 1
- Returns
a tuple of RGB values between 0 and 255
- Raises
ValueError – if the inputs are outside their bounds
- hsv_to_hex(hue: int, saturation: float, value: float) str
Converts a color from HSV to a Hexadecimal string
- Parameters
hue (
int
) – between 0 and 360saturation (
float
) – between 0 and 1value (
float
) – between 0 and 1
- Returns
str
– a hexstring in the format"#rrggbb"
- Raises
ValueError – if the inputs are outside their bounds
- hsv_to_cmyk(hue: int, saturation: float, value: float) tuple[float, float, float, float]
Converts a color from HSV to CMYK
- Parameters
hue – between 0 and 360
saturation – between 0 and 1
value – between 0 and 1
- Returns
a tuple of CMYK values between 0 and 1
- Raises
ValueError – if the inputs are outside their bounds
- hsv_to_hsl(hue: int, saturation: float, value: float) tuple[int, float, float]
Converts a color from HSV to HSL
- Parameters
hue – between 0 and 360
saturation – between 0 and 1
value – between 0 and 1
- Returns
a tuple of HSL values
- Raises
ValueError – if the inputs are outside their bounds
HSL Conversions
- hsl_to_rgb(hue: int, saturation: float, luminance: float) tuple[int, int, int]
Converts a color from HSL to RGB
- Parameters
hue – between 0 and 360
saturation – between 0 and 1
luminance – between 0 and 1
- Returns
a tuple of RGB values between 0 and 255
- Raises
ValueError – if the inputs are outside their bounds
- hsl_to_hex(hue: int, saturation: float, luminance: float) str
Converts a color from HSL to a Hexadecimal string
- Parameters
hue (
int
) – between 0 and 360saturation (
float
) – between 0 and 1luminance (
float
) – between 0 and 1
- Returns
str
– a hexstring in the format"#rrggbb"
- Raises
ValueError – if the inputs are outside their bounds
- hsl_to_cmyk(hue: int, saturation: float, luminance: float) tuple[float, float, float, float]
Converts a color from HSL to CMYK
- Parameters
hue – between 0 and 360
saturation – between 0 and 1
luminance – between 0 and 1
- Returns
a tuple of CMYK values between 0 and 1
- Raises
ValueError – if the inputs are outside their bounds
- hsl_to_hsv(hue: int, saturation: float, luminance: float) tuple[int, float, float]
Converts a color from HSL to HSV
- Parameters
hue – between 0 and 360
saturation – between 0 and 1
luminance – between 0 and 1
- Returns
a tuple of HSV values
- Raises
ValueError – if the inputs are outside their bounds
Easing Functions
Returns a linear ease |
|
Returns a polynomial ease |
|
Returns a quadratic ease |
|
Returns a cubic ease |
|
Returns a quartic ease |
|
Returns a quintic ease |
|
Returns a sine ease |
|
Returns an exponential ease |
|
Returns a circular ease |
|
Returns a back ease |
|
Returns an elastic ease |
|
Returns a bounce ease |
Easing Function Graphs

Combine Easing Functions
- combine_easing(easing1: EasingType, easing2: EasingType) Callable[[float], float]
Combines 2 easing functions together.
The 1st easing function is used for
t
values below 0.5 and the 2nd easing function is used fort
values above 0.5- Parameters
easing1 (
EasingType
) – the 1st easing function fort
< 0.5easing2 (
EasingType
) – the 2nd easing function fort
≥ 0.5
- Raises
TypeError –
easing1
andeasing2
must be easing functions
Examples
>>> ease1 = gp.ease_elastic_in() >>> ease2 = gp.ease_bounce_out() >>> new_ease = combine_easing(ease1, ease2)
- Return type
Callable
[[float
],float
]

Keyboard Key IDs
This is a list of all the valid keyboard key IDs that can be used with the goopylib Window to set callbacks, check for key events, and more.
|
262 |
|
263 |
|
264 |
|
265 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
32 |
|
39 |
|
44 |
|
45 |
|
46 |
|
47 |
|
59 |
|
61 |
|
91 |
|
93 |
|
92 |
|
96 |
|
161 |
|
162 |
|
266 |
|
267 |
|
268 |
|
269 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 |
|
327 |
|
328 |
|
329 |
|
348 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |