goopylib - games, graphics, and GUI

Downloads PyPI PyPI - Python Version PyPI - Wheel GitHub

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 coordinates

  • height (int) – in screen coordinates

  • title (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 coordinates

  • height (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 coordinates

  • ypos (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

  • ValueErrormin_width and min_height must be greater than or equal to 0. max_width and max_height must be greater than or equal min_width and min_height

Return type

None

set_min_size(min_width: int, min_height: int) None

Sets the minimum resizable dimensions of the window.

Raises
  • TypeErrormin_width and min_height must be integers

  • ValueErrormin_width and min_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
  • TypeErrormax_width and max_height must be integers or None

  • ValueErrormax_width and max_height must be greater than or equal to min_width and min_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) – an int corresponding to the keycode

Returns

bool – whether the specified key is being pressed

check_mouse_button(button: int) bool
Parameters

button (int) – an int 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

get_camera() Camera
Returns

Camera – the Camera object associated with the window

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:

Window.resize_callback

Callback executed when the window is resized.

Window.close_callback

Callback executed when the window is attempted to be closed.

Window.destroy_callback

Callback executed when the window is destroyed.

Window.position_callback

Callback executed when the window is moved.

Window.minimize_callback

Callback executed when the window is minimized.

Window.maximize_callback

Callback executed when the window is maximized.

Window.focus_callback

Callback executed when the window gains input focus.

Window.refresh_callback

Callback executed when the window needs refreshing.

Window.content_scale_callback

Callback executed when the window's content scale changes.

Window.framebuffer_size_callback

Callback executed when the window's framebuffer size changes.

Window.mouse_motion_callback

Callback executed when the mouse moves.

Window.mouse_enter_callback

Callback executed when the mouse enters/exits the window.

Window.scroll_callback

Callback executed when the mouse scrolls.

Window.left_click_callback

Callback executed when the left mouse button is clicked.

Window.middle_click_callback

Callback executed when the middle mouse button is clicked.

Window.right_click_callback

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

Line(p1, p2)

An object representing a line connecting 2 points together.

Triangle(p1, p2, p3)

An object representing a triangle with 3 vertices.

Quad(p1, p2, p3, p4)

An object representing a quad with 4 vertices.

Ellipse(p1, *args)

An object representing an ellipse or oval

Image(path, p1, *args)

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

Renderable

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 coordinates

  • y (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 coordinates

  • dy (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 coordinates

  • height (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

is_hidden() bool
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 coordinates

  • y (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 coordinates

  • y (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 plane

  • right (float) – right clipping plane

  • bottom (float) – bottom clipping plane

  • top (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 plane

  • right (float) – right clipping plane

  • bottom (float) – bottom clipping plane

  • top (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 position

  • dy (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 up

  • left (int) – key to use for moving left

  • down (int) – key to use for moving down

  • right (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 rotation

  • anticlockwise (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 in

  • zoomout (int) – key to use for zooming out

Raises

TypeError – arguments must be keys

Return type

None

goopylib.color

Color

Create colors by passing RGB arguments or a hexstring.

ColorRGB

Create an RGB color by passing RGB arguments with an optional alpha parameter.

ColorHex

Create a Hexadecimal color by passing a hexstring with an optional alpha parameter.

ColorCMYK

Create a CMYK color by passing cyan, magenta, yellow, key and optionally, alpha.

ColorHSV

Create an HSV color by passing hue (0-360), saturation (0-1), value (0-1) and optionally, alpha (0-1)

ColorHSL

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.

random_rgb() ColorRGB
Returns

ColorRGB – a random RGB color

random_hex() ColorHex
Returns

ColorHex – a random Hexadecimal color

random_cmyk() ColorCMYK
Returns

ColorCMYK – a random CMYK color

random_hsv() ColorHSV
Returns

ColorHSV – a random HSV color

random_hsl() ColorHSL
Returns

ColorHSL – a random HSL color

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 255

  • green (int) – between 0 and 255

  • blue (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 1

  • magenta (float) – between 0 and 1

  • yellow (float) – between 0 and 1

  • key (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 360

  • saturation (float) – between 0 and 1

  • value (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 360

  • saturation (float) – between 0 and 1

  • luminance (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

ease_linear

Returns a linear ease

ease_poly

Returns a polynomial ease

ease_quad

Returns a quadratic ease

ease_cubic

Returns a cubic ease

ease_quart

Returns a quartic ease

ease_quint

Returns a quintic ease

ease_sin

Returns a sine ease

ease_exp

Returns an exponential ease

ease_circle

Returns a circular ease

ease_back

Returns a back ease

ease_elastic

Returns an elastic ease

ease_bounce

Returns a bounce ease


Easing Function Graphs

_images/all.png

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 for t values above 0.5

Parameters
  • easing1 (EasingType) – the 1st easing function for t < 0.5

  • easing2 (EasingType) – the 2nd easing function for t ≥ 0.5

Raises

TypeErroreasing1 and easing2 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]

_images/combine_easing.png

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.

KEY_RIGHT

262

KEY_LEFT

263

KEY_DOWN

264

KEY_UP

265

KEY_0

48

KEY_1

49

KEY_2

50

KEY_3

51

KEY_4

52

KEY_5

53

KEY_6

54

KEY_7

55

KEY_8

56

KEY_9

57

KEY_A

65

KEY_B

66

KEY_C

67

KEY_D

68

KEY_E

69

KEY_F

70

KEY_G

71

KEY_H

72

KEY_I

73

KEY_J

74

KEY_K

75

KEY_L

76

KEY_M

77

KEY_N

78

KEY_O

79

KEY_P

80

KEY_Q

81

KEY_R

82

KEY_S

83

KEY_T

84

KEY_U

85

KEY_V

86

KEY_W

87

KEY_X

88

KEY_Y

89

KEY_Z

90

KEY_ESCAPE

256

KEY_ENTER

257

KEY_TAB

258

KEY_BACKSPACE

259

KEY_INSERT

260

KEY_DELETE

261

KEY_SPACE

32

KEY_APOSTROPHE

39

KEY_COMMA

44

KEY_MINUS

45

KEY_PERIOD

46

KEY_SLASH

47

KEY_SEMICOLON

59

KEY_EQUAL

61

KEY_LEFT_BRACKET

91

KEY_RIGHT_BRACKET

93

KEY_BACKSLASH

92

KEY_GRAVE_ACCENT

96

KEY_WORLD_1

161

KEY_WORLD_2

162

KEY_PAGE_UP

266

KEY_PAGE_DOWN

267

KEY_HOME

268

KEY_END

269

KEY_CAPS_LOCK

280

KEY_SCROLL_LOCK

281

KEY_NUM_LOCK

282

KEY_PRINT_SCREEN

283

KEY_PAUSE

284

KEY_KP_0

320

KEY_KP_1

321

KEY_KP_2

322

KEY_KP_3

323

KEY_KP_4

324

KEY_KP_5

325

KEY_KP_6

326

KEY_KP_7

327

KEY_KP_8

328

KEY_KP_9

329

KEY_MENU

348

KEY_F1

290

KEY_F2

291

KEY_F3

292

KEY_F4

293

KEY_F5

294

KEY_F6

295

KEY_F7

296

KEY_F8

297

KEY_F9

298

KEY_F10

299

KEY_F11

300

KEY_F12

301

KEY_F13

302

KEY_F14

303

KEY_F15

304

KEY_F16

305

KEY_F17

306

KEY_F18

307

KEY_F19

308

KEY_F20

309

KEY_F21

310

KEY_F22

311

KEY_F23

312

KEY_F24

313

KEY_F25

314

KEY_KP_DECIMAL

330

KEY_KP_DIVIDE

331

KEY_KP_MULTIPLY

332

KEY_KP_SUBTRACT

333

KEY_KP_ADD

334

KEY_KP_ENTER

335

KEY_KP_EQUAL

336

KEY_LEFT_SHIFT

340

KEY_LEFT_CONTROL

341

KEY_LEFT_ALT

342

KEY_LEFT_SUPER

343

KEY_RIGHT_SHIFT

344

KEY_RIGHT_CONTROL

345

KEY_RIGHT_ALT

346

KEY_RIGHT_SUPER

347

Mouse Button IDs

This is a list of all the valid mouse buttons IDs that can be used with the goopylib Window to set callbacks, check for mouse events, and more.

MOUSE_LEFT_BUTTON

0

MOUSE_RIGHT_BUTTON

1

MOUSE_MIDDLE_BUTTON

2

MOUSE_BUTTON_4

3

MOUSE_BUTTON_5

4

MOUSE_BUTTON_6

5

MOUSE_BUTTON_7

6

MOUSE_BUTTON_8

7