Arcade Package API

This page documents the Application Programming Interface (API) for the Python Arcade library.

For example code, see Example Code.

Submodules

Window Commands Module

This submodule has functions that control opening, closing, rendering, and otherwise managing windows. It also has commands for scheduling pauses and scheduling interval functions.

arcade.window_commands.close_window()[source]

Closes the current window, and then runs garbage collection. The garbage collection is necessary to prevent crashing when opening/closing windows rapidly (usually during unit tests).

arcade.window_commands.finish_render()[source]

Swap buffers and displays what has been drawn. If programs use derive from the Window class, this function is automatically called.

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.RED)
>>> arcade.start_render()
>>> # All the drawing commands go here
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.window_commands.get_viewport() -> (<class 'float'>, <class 'float'>, <class 'float'>, <class 'float'>)[source]

Get the current viewport settings.

arcade.window_commands.get_window() → Union[pyglet.window.BaseWindow, NoneType][source]

Return a handle to the current window.

Param:None
Return window:Handle to the current window.
Raises:None
arcade.window_commands.open_window(width: numbers.Number, height: numbers.Number, window_title: str, resizable: bool = False)[source]

This function opens a window. For ease-of-use we assume there will only be one window, and the programmer does not need to keep a handle to the window. This isn’t the best architecture, because the window handle is stored in a global, but it makes things easier for programmers if they don’t have to track a window pointer.

Args:
window_title:Title of the window.
width:Width of the window.
height:Height of the window.
resizable:Whether the window can be user-resizable.

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.quick_run(0.25)
arcade.window_commands.pause(seconds: numbers.Number)[source]

Pause for the specified number of seconds. This is a convenience function that just calls time.sleep()

Parameters:seconds (float) – Time interval to pause in seconds.
>>> import arcade
>>> arcade.pause(0.25) # Pause 1/2 second
arcade.window_commands.quick_run(time_to_pause: numbers.Number)[source]

Only run the application for the specified time in seconds. Useful for unit testing or continuous integration (CI) testing where there is no user interaction.

Args:
time_to_pause:Number of seconds to pause before automatically closing.
arcade.window_commands.run()[source]

Run the main loop. After the window has been set up, and the event hooks are in place, this is usually one of the last commands on the main program.

arcade.window_commands.schedule(function_pointer: Callable, interval: numbers.Number)[source]

Schedule a function to be automatically called every interval seconds.

Args:
function_pointer:
 Pointer to the function to be called.
interval:Interval to call the function.
Returns:
None
Raises:
None
arcade.window_commands.set_background_color(color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]])[source]

This specifies the background color of the window.

Args:
color (tuple):List of 3 or 4 bytes in RGB/RGBA format.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.RED)
>>> arcade.start_render()
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.window_commands.set_viewport(left: numbers.Number, right: numbers.Number, bottom: numbers.Number, top: numbers.Number)[source]

This sets what coordinates the window will cover.

By default, the lower left coordinate will be (0, 0) and the top y coordinate will be the height of the window in pixels, and the right x coordinate will be the width of the window in pixels.

If a program is making a game where the user scrolls around a larger world, this command can help out.

Note: It is recommended to only set the view port to integer values that line up with the pixels on the screen. Otherwise if making a tiled game the blocks may not line up well, creating rectangle artifacts.

Args:
left:Left-most (smallest) x value.
right:Right-most (largest) x value.
bottom:Bottom (smallest) y value.
top:Top (largest) y value.
Returns:
None
Raises:
None
Example:
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> set_viewport(-1, 1, -1, 1)
>>> arcade.quick_run(0.25)
arcade.window_commands.set_window(window: pyglet.window.BaseWindow)[source]

Set a handle to the current window.

Args:
window:Handle to the current window.
arcade.window_commands.start_render()[source]

Get set up to render. Required to be called before drawing anything to the screen.

Draw Commands Module

This module contains commands for basic graphics drawing commands. (Drawing primitives.)

Many of these commands are slow, because they load everything to the graphics card each time a shape is drawn. For faster drawing, see the Buffered Draw Commands.

class arcade.draw_commands.Texture(texture_id: int, width: float, height: float)[source]

Bases: object

Class that represents a texture. Usually created by the load_texture or load_textures commands.

Attributes:
id:ID of the texture as assigned by OpenGL
width:Width of the texture image in pixels
height:Height of the texture image in pixels
arcade.draw_commands.create_text(text: str, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], font_size: float = 12, width: int = 2000, align='left', font_name=('Calibri', 'Arial'), bold: bool = False, italic: bool = False, anchor_x='left', anchor_y='baseline')[source]

Create text to be rendered later. This operation takes a while, so it is better to hold it between frames when the text does not change.

>>> import arcade
>>> arcade.open_window(800, 600, "Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> my_text = arcade.create_text("Text Example", arcade.color.BLACK, 10)
>>> arcade.render_text(my_text, 250, 300, 45)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_arc_filled(center_x: float, center_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], start_angle: float, end_angle: float, tilt_angle: float = 0)[source]

Draw a filled in arc. Useful for drawing pie-wedges, or Pac-Man.

Args:
center_x:x position that is the center of the arc.
center_y:y position that is the center of the arc.
width:width of the arc.
height:height of the arc.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
start_angle:start angle of the arc in degrees.
end_angle:end angle of the arc in degrees.
tilt_angle:angle the arc is tilted.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_arc_filled(150, 144, 15, 36, arcade.color.BOTTLE_GREEN, 90, 360, 45)
>>> color = (255, 0, 0, 127)
>>> arcade.draw_arc_filled(150, 154, 15, 36, color, 90, 360, 45)
>>> arcade.finish_render()
>>> arcade.close_window()
arcade.draw_commands.draw_arc_outline(center_x: float, center_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], start_angle: float, end_angle: float, border_width: float = 1, tilt_angle: float = 0)[source]

Draw the outside edge of an arc. Useful for drawing curved lines.

Args:
center_x:x position that is the center of the arc.
center_y:y position that is the center of the arc.
width:width of the arc.
height:height of the arc.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
start_angle:start angle of the arc in degrees.
end_angle:end angle of the arc in degrees.
border_width:width of line in pixels.
angle:angle the arc is tilted.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_arc_outline(150, 81, 15, 36, arcade.color.BRIGHT_MAROON, 90, 360)
>>> transparent_color = (255, 0, 0, 127)
>>> arcade.draw_arc_outline(150, 71, 15, 36, transparent_color, 90, 360)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_circle_filled(center_x: float, center_y: float, radius: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]])[source]

Draw a filled-in circle.

Args:
center_x:x position that is the center of the circle.
center_y:y position that is the center of the circle.
radius:width of the circle.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
num_segments (int):
 float of triangle segments that make up this circle. Higher is better quality, but slower render time.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_circle_filled(420, 285, 18, arcade.color.GREEN)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_circle_outline(center_x: float, center_y: float, radius: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw the outline of a circle.

Args:
center_x:x position that is the center of the circle.
center_y:y position that is the center of the circle.
radius:width of the circle.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
border_width:Width of the circle outline in pixels.
num_segments:float of triangle segments that make up this circle. Higher is better quality, but slower render time.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_circle_outline(300, 285, 18, arcade.color.WISTERIA, 3)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_ellipse_filled(center_x: float, center_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], tilt_angle: float = 0, num_segments=128)[source]

Draw a filled in ellipse.

Args:
center_x:x position that is the center of the circle.
center_y:y position that is the center of the circle.
height:height of the ellipse.
width:width of the ellipse.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
angle:Angle in degrees to tilt the ellipse.
num_segments:float of triangle segments that make up this circle. Higher is better quality, but slower render time.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_ellipse_filled(60, 81, 15, 36, arcade.color.AMBER)
>>> color = (127, 0, 127, 127)
>>> arcade.draw_ellipse_filled(60, 144, 15, 36, color, 45)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_ellipse_outline(center_x: float, center_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0)[source]

Draw the outline of an ellipse.

Args:
center_x:x position that is the center of the circle.
center_y:y position that is the center of the circle.
height:height of the ellipse.
width:width of the ellipse.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
border_width:Width of the circle outline in pixels.
tilt_angle:Angle in degrees to tilt the ellipse.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_ellipse_outline(540, 273, 15, 36, arcade.color.AMBER, 3)
>>> color = (127, 0, 127, 127)
>>> arcade.draw_ellipse_outline(540, 336, 15, 36, color, 3, 45)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_line(start_x: float, start_y: float, end_x: float, end_y: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a line.

Args:
start_x:x position of line starting point.
start_y:y position of line starting point.
end_x:x position of line ending point.
end_y:y position of line ending point.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
border_width:Width of the line in pixels.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_line(270, 495, 300, 450, arcade.color.WOOD_BROWN, 3)
>>> color = (127, 0, 127, 127)
>>> arcade.draw_line(280, 495, 320, 450, color, 3)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_line_strip(point_list: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a line strip. A line strip is a set of continuously connected line segments.

Args:
point_list:List of points making up the line. Each point is in a list. So it is a list of lists.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
border_width:Width of the line in pixels.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> point_list = ((510, 450), (570, 450), (510, 480), (570, 480), (510, 510), (570, 510))
>>> arcade.draw_line_strip(point_list, arcade.color.TROPICAL_RAIN_FOREST, 3)
>>> color = (127, 0, 127, 127)
>>> point_list = ((510, 455), (570, 455), (510, 485), (570, 485), (510, 515), (570, 515))
>>> arcade.draw_line_strip(point_list, color, 3)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_lines(point_list: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a set of lines.

Draw a line between each pair of points specified.

Args:
point_list:List of points making up the lines. Each point is in a list. So it is a list of lists.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
border_width:Width of the line in pixels.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> point_list = ((390, 450), (450, 450), (390, 480), (450, 480), (390, 510), (450, 510))
>>> arcade.draw_lines(point_list, arcade.color.BLUE, 3)
>>> arcade.start_render()
>>> point_list = ((390, 450), (550, 450), (490, 480), (550, 480), (490, 510), (550, 510))
>>> arcade.draw_lines(point_list, (0, 0, 255, 127), 3)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_lrtb_rectangle_filled(left: float, right: float, top: float, bottom: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]])[source]

Draw a rectangle by specifying left, right, top, and bottom edges.

Args:
left:The x coordinate of the left edge of the rectangle.
right:The x coordinate of the right edge of the rectangle.
top:The y coordinate of the top of the rectangle.
bottom:The y coordinate of the rectangle bottom.
color:The color of the rectangle.
border_width:The width of the border in pixels. Defaults to one.
Returns:
None
Raises:
AttributeErrror:
 Raised if left > right or top < bottom.
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.start_render()
>>> arcade.draw_lrtb_rectangle_filled(1, 2, 3, 1, arcade.color.BLACK)
>>> arcade.draw_lrtb_rectangle_filled(2, 1, 3, 1, arcade.color.BLACK)
Traceback (most recent call last):
    ...
AttributeError: Left coordinate 2 must be less than or equal to the right coordinate 1
>>> arcade.draw_lrtb_rectangle_filled(1, 2, 3, 4, arcade.color.BLACK)
Traceback (most recent call last):
    ...
AttributeError: Bottom coordinate 4 must be less than or equal to the top coordinate 3
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_lrtb_rectangle_outline(left: float, right: float, top: float, bottom: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a rectangle by specifying left, right, top, and bottom edges.

Args:
left:The x coordinate of the left edge of the rectangle.
right:The x coordinate of the right edge of the rectangle.
top:The y coordinate of the top of the rectangle.
bottom:The y coordinate of the rectangle bottom.
color:The color of the rectangle.
border_width:The width of the border in pixels. Defaults to one.
Returns:
None
Raises:
AttributeErrror:
 Raised if left > right or top < bottom.
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.start_render()
>>> arcade.draw_lrtb_rectangle_outline(100, 100, 100, 100,         arcade.color.BLACK, 5)
>>> arcade.draw_lrtb_rectangle_outline(190, 180, 100, 100,         arcade.color.BLACK, 5)
Traceback (most recent call last):
    ...
AttributeError: Left coordinate must be less than or equal to the right coordinate
>>> arcade.draw_lrtb_rectangle_outline(170, 180, 100, 200,         arcade.color.BLACK, 5)
Traceback (most recent call last):
    ...
AttributeError: Bottom coordinate must be less than or equal to the top coordinate
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_parabola_filled(start_x: float, start_y: float, end_x: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], tilt_angle: float = 0)[source]

Draws a filled in parabola.

Args:
start_x:The starting x position of the parabola
start_y:The starting y position of the parabola
end_x:The ending x position of the parabola
height:The height of the parabola
color:The color of the parabola
tilt_angle:The angle of the tilt of the parabola
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_parabola_filled(150, 150, 200, 50, arcade.color.BOTTLE_GREEN)
>>> color = (255, 0, 0, 127)
>>> arcade.draw_parabola_filled(160, 160, 210, 50, color)
>>> arcade.finish_render()
>>> arcade.close_window()
arcade.draw_commands.draw_parabola_outline(start_x: float, start_y: float, end_x: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0)[source]

Draws the outline of a parabola.

Args:
start_x:The starting x position of the parabola
start_y:The starting y position of the parabola
end_x:The ending x position of the parabola
height:The height of the parabola
color:The color of the parabola
border_width:The width of the parabola
tile_angle:The angle of the tilt of the parabola
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_parabola_outline(150, 150, 200, 50, arcade.color.BOTTLE_GREEN, 10, 15)
>>> color = (255, 0, 0, 127)
>>> arcade.draw_parabola_outline(160, 160, 210, 50, color, 20)
>>> arcade.finish_render()
>>> arcade.close_window()
arcade.draw_commands.draw_point(x: float, y: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], size: float)[source]

Draw a point.

Args:
x:x position of point.
y:y position of point.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
size:Size of the point in pixels.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_point(60, 495, arcade.color.RED, 10)
>>> arcade.draw_point(70, 495, (255, 0, 0, 127), 10)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_points(point_list: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], size: float = 1)[source]

Draw a set of points.

Args:
point_list:List of points Each point is in a list. So it is a list of lists.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
size:Size of the point in pixels.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> point_list = ((165, 495), (165, 480), (165, 465), (195, 495), (195, 480), (195, 465))
>>> arcade.draw_points(point_list, arcade.color.ZAFFRE, 10)
>>> arcade.draw_points(point_list, make_transparent_color(arcade.color.ZAFFRE, 127), 10)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_polygon_filled(point_list: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]])[source]

Draw a polygon that is filled in.

Args:
point_list:List of points making up the lines. Each point is in a list. So it is a list of lists.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
Returns:
None
Raises:
None
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> point_list = ((150, 240), (165, 240), (180, 255), (180, 285), (165, 300), (150, 300))
>>> arcade.draw_polygon_filled(point_list, arcade.color.SPANISH_VIOLET)
>>> arcade.draw_polygon_filled(point_list, make_transparent_color(arcade.color.SPANISH_VIOLET, 127))
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_polygon_outline(point_list: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a polygon outline. Also known as a “line loop.”

Args:
point_list:List of points making up the lines. Each point is in a list. So it is a list of lists.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
border_width:Width of the line in pixels.
Returns:
None
Raises:
None
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> point_list = ((30, 240), (45, 240), (60, 255), (60, 285), (45, 300), (30, 300))
>>> arcade.draw_polygon_outline(point_list, arcade.color.SPANISH_VIOLET, 3)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_rectangle_filled(center_x: float, center_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], tilt_angle: float = 0)[source]

Draw a filled-in rectangle.

Args:
center_x:x coordinate of rectangle center.
center_y:y coordinate of rectangle center.
width:width of the rectangle.
height:height of the rectangle.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
angle:rotation of the rectangle. Defaults to zero.

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_rectangle_filled(390, 150, 45, 105, arcade.color.BLUSH)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_rectangle_outline(center_x: float, center_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0)[source]

Draw a rectangle outline.

Args:
x:x coordinate of top left rectangle point.
y:y coordinate of top left rectangle point.
width:width of the rectangle.
height:height of the rectangle.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.
border_width:width of the lines, in pixels.
angle:rotation of the rectangle. Defaults to zero.
Returns:
None
Raises:
None

Example:

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_rectangle_outline(278, 150, 45, 105, arcade.color.BRITISH_RACING_GREEN, 2)
>>> arcade.draw_rectangle_outline(278, 150, 45, 105, (100, 200, 100, 255))
>>> arcade.draw_rectangle_outline(278, 150, 45, 105, arcade.color.BRITISH_RACING_GREEN, 5, 45)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_text(text: str, start_x: float, start_y: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], font_size: float = 12, width: int = 2000, align='left', font_name=('Calibri', 'Arial'), bold: bool = False, italic: bool = False, anchor_x='left', anchor_y='baseline', rotation=0)[source]
Args:
text:Text to display.
start_x:x coordinate of top left text point.
start_y:y coordinate of top left text point.
color:color, specified in a list of 3 or 4 bytes in RGB or RGBA format.

Example:

>>> import arcade
>>> arcade.open_window(800, 600, "Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_text("Text Example", 250, 300, arcade.color.BLACK, 10)
>>> arcade.draw_text("Text Example", 250, 300, (0, 0, 0, 100), 10)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_texture_rectangle(center_x: float, center_y: float, width: float, height: float, texture: arcade.draw_commands.Texture, angle: float = 0, alpha: float = 1, transparent: bool = True)[source]

Draw a textured rectangle on-screen.

Args:
center_x:x coordinate of rectangle center.
center_y:y coordinate of rectangle center.
width:width of the rectangle.
height:height of the rectangle.
texture:identifier of texture returned from load_texture() call
angle:rotation of the rectangle. Defaults to zero.
alpha:Transparency of image.
Returns:
None
Raises:
None
Example:
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> arcade.draw_text("draw_bitmap", 483, 3, arcade.color.BLACK, 12)
>>> name = "arcade/examples/images/playerShip1_orange.png"
>>> texture = arcade.load_texture(name)
>>> scale = .6
>>> arcade.draw_texture_rectangle(540, 120, scale * texture.width, scale * texture.height, texture, 0)
>>> arcade.draw_texture_rectangle(540, 60, scale * texture.width, scale * texture.height, texture, 90)
>>> arcade.draw_texture_rectangle(540, 60, scale * texture.width, scale * texture.height, texture, 90, 1, False)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_triangle_filled(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]])[source]

Draw a filled in triangle.

Args:
x1:x value of first coordinate.
y1:y value of first coordinate.
x2:x value of second coordinate.
y2:y value of second coordinate.
x3:x value of third coordinate.
y3:y value of third coordinate.
color:Color of triangle.
Returns:
None
Raises:
None
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.start_render()
>>> arcade.draw_triangle_filled(1, 2, 3, 4, 5, 6, arcade.color.BLACK)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_triangle_outline(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a the outline of a triangle.

Args:
x1:x value of first coordinate.
y1:y value of first coordinate.
x2:x value of second coordinate.
y2:y value of second coordinate.
x3:x value of third coordinate.
y3:y value of third coordinate.
color:Color of triangle.
border_width:Width of the border in pixels. Defaults to 1.
Returns:
None
Raises:
None
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.start_render()
>>> arcade.draw_triangle_outline(1, 2, 3, 4, 5, 6, arcade.color.BLACK, 5)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_xywh_rectangle_filled(top_left_x: float, top_left_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]])[source]

Draw a rectangle by specifying left, right, top, and bottom edges.

Args:
top_left_x:The x coordinate of the left edge of the rectangle.
top_left_y:The y coordinate of the top of the rectangle.
width:The width of the rectangle.
height:The height of the rectangle.
color:The color of the rectangle.
border_width:The width of the border in pixels. Defaults to one.
Returns:
None
Raises:
None
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.start_render()
>>> arcade.draw_xywh_rectangle_filled(1, 2, 3, 4, arcade.color.BLACK)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_xywh_rectangle_outline(top_left_x: float, top_left_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a rectangle by specifying left, right, top, and bottom edges.

Args:
top_left_x:The x coordinate of the left edge of the rectangle.
top_left_y:The y coordinate of the top of the rectangle.
width:The width of the rectangle.
height:The height of the rectangle.
color:The color of the rectangle.
border_width:The width of the border in pixels. Defaults to one.
Returns:
None
Raises:
None
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.start_render()
>>> arcade.draw_xywh_rectangle_outline(1, 2, 10, 10, arcade.color.BLACK, 5)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.draw_xywh_rectangle_textured(top_left_x: float, top_left_y: float, width: float, height: float, texture: arcade.draw_commands.Texture)[source]
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.start_render()
>>> name = "arcade/examples/images/meteorGrey_big1.png"
>>> texture1 = load_texture(name, 1, 1, 50, 50)
>>> arcade.draw_xywh_rectangle_textured(1, 2, 10, 10, texture1)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.draw_commands.load_texture(file_name: str, x: float = 0, y: float = 0, width: float = 0, height: float = 0, mirrored: bool = False, flipped: bool = False, scale: float = 1) → arcade.draw_commands.Texture[source]

Load image from disk and create a texture.

Args:
filename (str):Name of the file to that holds the texture.
x (float):X position of the crop area of the texture.
y (float):Y position of the crop area of the texture.
width (float):Width of the crop area of the texture.
height (float):Height of the crop area of the texture.
scale (float):Scale factor to apply on the new texture.
Returns:
The new texture.
Raises:
None
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> name = "arcade/examples/images/meteorGrey_big1.png"
>>> texture1 = load_texture(name, 1, 1, 50, 50)
>>> texture2 = load_texture(name, 1, 1, 50, 50)
>>> texture = load_texture(name, 200, 1, 50, 50)
Traceback (most recent call last):
...
ValueError: Can't load texture starting at an x of 200 when the image is only 101 across.
>>> texture = load_texture(name, 1, 50, 50, 50)
Traceback (most recent call last):
...
ValueError: Can't load texture ending at an y of 100 when the image is only 84 high.
>>> texture = load_texture(name, 1, 150, 50, 50)
Traceback (most recent call last):
...
ValueError: Can't load texture starting at an y of 150 when the image is only 84 high.
>>> texture = load_texture(name, 0, 0, 400, 50)
Traceback (most recent call last):
...
ValueError: Can't load texture ending at an x of 400 when the image is only 101 wide.
>>> arcade.close_window()
arcade.draw_commands.load_textures(file_name: str, image_location_list: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], mirrored: bool = False, flipped: bool = False, scale: float = 1) → List[_ForwardRef('Texture')][source]

Load a set of textures off of a single image file.

Args:
file_name:Name of the file.
image_location_list:
 List of image locations. Each location should be a list of four floats. [x, y, width, height].
mirrored=False:If set to true, the image is mirrored left to right.
flipped=False:If set to true, the image is flipped upside down.
Returns:
list:List of textures loaded.
Raises:
SystemError:
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> image_location_list = [[591, 5, 64, 93],
...                        [655, 10, 75, 88],
...                        [730, 7, 54, 91],
...                        [784, 3, 59, 95],
...                        [843, 6, 56, 92]]
>>> texture_info_list = arcade.load_textures("arcade/examples/images/character_sheet.png", image_location_list)
>>> image_location_list = [[5600, 0, 0, 0]]
>>> texture_info_list = arcade.load_textures("arcade/examples/images/character_sheet.png", image_location_list)
Traceback (most recent call last):
...
ValueError: Texture has a width of 0, must be > 0.
>>> image_location_list = [[2000, 0, 20, 20]]
>>> texture_info_list = arcade.load_textures("arcade/examples/images/character_sheet.png", image_location_list)
Traceback (most recent call last):
...
ValueError: Can't load texture starting at an x of 2000 when the image is only 1377 across.
>>> image_location_list = [[500, 500, 20, 20]]
>>> texture_info_list = arcade.load_textures("arcade/examples/images/character_sheet.png", image_location_list)
Traceback (most recent call last):
...
ValueError: Can't load texture starting at an y of 500 when the image is only 98 high.
>>> image_location_list = [[1300, 0, 100, 20]]
>>> texture_info_list = arcade.load_textures("arcade/examples/images/character_sheet.png", image_location_list)
Traceback (most recent call last):
...
ValueError: Can't load texture ending at an x of 1400 when the image is only 1377 wide.
>>> image_location_list = [[500, 50, 50, 50]]
>>> texture_info_list = arcade.load_textures("arcade/examples/images/character_sheet.png", image_location_list)
Traceback (most recent call last):
...
ValueError: Can't load texture ending at an y of 100 when the image is only 98 high.
>>> image_location_list = [[0, 0, 50, 50]]
>>> texture_info_list = arcade.load_textures("arcade/examples/images/character_sheet.png", image_location_list, mirrored=True, flipped=True)
>>> arcade.close_window()
arcade.draw_commands.make_transparent_color(color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], transparency: float)[source]

Given a RGB color, along with an alpha, returns a RGBA color tuple.

arcade.draw_commands.render_text(text: pyglet.text.Label, start_x: float, start_y: float, rotation=0)[source]

Render text created by the create_text function.

arcade.draw_commands.rotate_point(x: float, y: float, cx: float, cy: float, angle: float) -> (<class 'float'>, <class 'float'>)[source]

Rotate a point around a center.

>>> x, y = rotate_point(1, 1, 0, 0, 90)
>>> print("x = {:.1f}, y = {:.1f}".format(x, y))
x = -1.0, y = 1.0
arcade.draw_commands.trim_image(image: <module 'PIL.Image' from 'c:\\program files (x86)\\python36\\lib\\site-packages\\PIL\\Image.py'>) → <module 'PIL.Image' from 'c:\\program files (x86)\\python36\\lib\\site-packages\\PIL\\Image.py'>[source]

Returns an image with extra whitespace cropped out.

>>> name = "arcade/examples/images/playerShip1_orange.png"
>>> source_image = PIL.Image.open(name)
>>> cropped_image = trim_image(source_image)
>>> print(source_image.height, cropped_image.height)
75 75

Buffered Draw Commands Module

Drawing commands that use the VBOs.

This module contains commands for basic graphics drawing commands, but uses Vertex Buffer Objects. This keeps the vertices loaded on the graphics card for much faster render times.

class arcade.buffered_draw_commands.ShapeElementList[source]

Bases: typing.Generic

A program can put multiple drawimg primitives in a ShapeElementList, and then move and draw them as one. Do this when you want to create a more complex object out of simpler primitives. This also speeds rendering as all objects are drawn in one operation.

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> my_list = ShapeElementList()
>>> my_shape = arcade.create_ellipse_outline(50, 50, 20, 20, arcade.color.RED, 45)
>>> my_list.append(my_shape)
>>> my_shape = arcade.create_ellipse_filled(50, 50, 20, 20, arcade.color.RED, 2, 45)
>>> my_list.append(my_shape)
>>> my_shape = arcade.create_rectangle_filled(250, 50, 20, 20, arcade.color.RED, 45)
>>> my_list.append(my_shape)
>>> my_shape = arcade.create_rectangle_outline(450, 50, 20, 20, (127, 0, 27, 127), 2, 45)
>>> my_list.append(my_shape)
>>> my_shape = arcade.create_lines_with_colors(([0, 400], [700, 400]), ((127, 0, 27, 127), arcade.color.GREEN), 2)
>>> my_list.append(my_shape)
>>> my_list.move(5, 5)
>>> arcade.start_render()
>>> my_list.draw()
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
append(item: T)[source]

Add a new shape to the list.

draw()[source]

Draw everything in the list.

move(change_x: float, change_y: float)[source]

Move all the shapes ion the list :param change_x: Amount to move on the x axis :param change_y: Amount to move on the y axis

remove(item: T)[source]

Remove a specific shape from the list.

class arcade.buffered_draw_commands.VertexBuffer(vbo_vertex_id: ctypes.c_ulong, size: float, draw_mode: int, vbo_color_id: ctypes.c_ulong = None)[source]

Bases: object

This class represents a vertex buffer object for internal library use. Clients of the library probably don’t need to use this.

Attributes:
vbo_id:ID of the vertex buffer as assigned by OpenGL
size:
width:
height:
color:
arcade.buffered_draw_commands.create_ellipse(center_x: float, center_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 0, tilt_angle: float = 0, num_segments=32, filled=True) → arcade.buffered_draw_commands.VertexBuffer[source]

This creates an ellipse vertex buffer object (VBO). It can later be drawn with render_ellipse_filled. This method of drawing an ellipse is much faster than calling draw_ellipse_filled each frame.

Note: This can’t be unit tested on Appveyor because its support for OpenGL is poor.

>>> import arcade
>>> arcade.open_window(800, 600, "Drawing Example")
>>> arcade.start_render()
>>> rect = arcade.create_ellipse(50, 50, 20, 20, arcade.color.RED, 2, 45)
>>> arcade.render(rect)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.buffered_draw_commands.create_ellipse_filled(center_x: float, center_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], tilt_angle: float = 0, num_segments=128) → arcade.buffered_draw_commands.VertexBuffer[source]

Create a filled ellipse. Or circle if you use the same width and height.

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> my_shape = arcade.create_ellipse_filled(300, 300, 50, 100, (0, 255, 255, 64), 45, 64)
>>> arcade.render(my_shape)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.buffered_draw_commands.create_ellipse_filled_with_colors(center_x: float, center_y: float, width: float, height: float, outside_color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], inside_color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], tilt_angle: float = 0, num_segments=32) → arcade.buffered_draw_commands.VertexBuffer[source]
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> point_list = [(0, 0), (100, 0), (100, 100)]
>>> color_list = [arcade.color.RED, arcade.color.BLUE, arcade.color.GREEN]
>>> my_shape = arcade.create_ellipse_filled_with_colors(100, 100, 50, 50, arcade.color.AFRICAN_VIOLET, arcade.color.ALABAMA_CRIMSON, tilt_angle=45)
>>> my_shape_list = ShapeElementList()
>>> my_shape_list.append(my_shape)
>>> my_shape_list.draw()
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.buffered_draw_commands.create_ellipse_outline(center_x: float, center_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0, num_segments=128) → arcade.buffered_draw_commands.VertexBuffer[source]

Create an outline of an ellipse.

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> my_shape = arcade.create_ellipse_outline(300, 300, 50, 100, (0, 255, 255), 45, 64)
>>> arcade.render(my_shape)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.buffered_draw_commands.create_filled_rectangles(point_list, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]]) → arcade.buffered_draw_commands.VertexBuffer[source]

This function creates multiple rectangle/quads using a vertex buffer object. Creating the rectangles, and then later drawing it with render is faster than calling draw_rectangle.

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> point_list = [0, 0, 100, 0, 100, 100, 0, 100]
>>> my_rect = arcade.create_filled_rectangles(point_list, (0, 255, 0))
>>> arcade.render(my_rect)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.buffered_draw_commands.create_line(start_x: float, start_y: float, end_x: float, end_y: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], line_width: float = 1)[source]

Create a line to be rendered later. This works faster than draw_line because the vertexes are only loaded to the graphics card once, rather than each frame.

Example:
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.start_render()
>>> line1 = arcade.create_line(0, 0, 100, 100, (255, 0, 0), 2)
>>> arcade.render(line1)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.buffered_draw_commands.create_line_generic(draw_type: int, point_list: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], line_width: float = 1)[source]

This function is used by create_line_strip and create_line_loop, just changing the OpenGL type for the line drawing.

arcade.buffered_draw_commands.create_line_loop(point_list: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], line_width: float = 1)[source]

Create a multi-point line loop to be rendered later. This works faster than draw_line because the vertexes are only loaded to the graphics card once, rather than each frame.

Example:
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.start_render()
>>> point_list = [[0, 0], [100, 100], [50, 0]]
>>> line1 = arcade.create_line_loop(point_list, (255, 0, 0), 2)
>>> arcade.render(line1)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.buffered_draw_commands.create_line_strip(point_list: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], line_width: float = 1)[source]

Create a multi-point line to be rendered later. This works faster than draw_line because the vertexes are only loaded to the graphics card once, rather than each frame.

Example:
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.start_render()
>>> point_list = [[0, 0], [100, 100], [50, 0]]
>>> line1 = arcade.create_line_strip(point_list, (255, 0, 0), 2)
>>> arcade.render(line1)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.buffered_draw_commands.create_lines(point_list: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], line_width: float = 1)[source]

Create a multi-point line loop to be rendered later. This works faster than draw_line because the vertexes are only loaded to the graphics card once, rather than each frame.

Example:
>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.start_render()
>>> point_list = [[0, 0], [100, 100], [50, 0], [50, 100]]
>>> line1 = arcade.create_lines(point_list, (255, 0, 0), 2)
>>> arcade.render(line1)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.buffered_draw_commands.create_lines_with_colors(point_list: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color_list, line_width: float = 1) → arcade.buffered_draw_commands.VertexBuffer[source]
arcade.buffered_draw_commands.create_polygon(point_list: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1)[source]

Draw a convex polygon. This will NOT draw a concave polygon. Because of this, you might not want to use this function.

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> arcade.start_render()
>>> point_list = [[0, 0], [100, 100], [50, 0]]
>>> line1 = arcade.create_polygon(point_list, (255, 0, 0), 2)
>>> arcade.render(line1)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.buffered_draw_commands.create_rectangle(center_x: float, center_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 0, tilt_angle: float = 0, filled=True) → arcade.buffered_draw_commands.VertexBuffer[source]

This function creates a rectangle using a vertex buffer object. Creating the rectangle, and then later drawing it with render_rectangle is faster than calling draw_rectangle.

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> my_rect = arcade.create_rectangle(200, 200, 50, 50, (0, 255, 0), 3, 45)
>>> arcade.render(my_rect)
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.buffered_draw_commands.create_rectangle_filled(center_x: float, center_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], tilt_angle: float = 0) → arcade.buffered_draw_commands.VertexBuffer[source]

Create a filled rectangle.

arcade.buffered_draw_commands.create_rectangle_outline(center_x: float, center_y: float, width: float, height: float, color: Union[typing.Tuple[int, int, int], typing.List[int], typing.Tuple[int, int, int, int]], border_width: float = 1, tilt_angle: float = 0) → arcade.buffered_draw_commands.VertexBuffer[source]

Create a rectangle outline.

arcade.buffered_draw_commands.create_rectangles_filled_with_colors(point_list, color_list) → arcade.buffered_draw_commands.VertexBuffer[source]

This function creates multiple rectangle/quads using a vertex buffer object. Creating the rectangles, and then later drawing it with render is faster than calling draw_rectangle.

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> point_list = [(0, 0), (100, 0), (100, 100), (0, 100)]
>>> color_list = [arcade.color.RED, arcade.color.BLUE, arcade.color.GREEN, arcade.color.AFRICAN_VIOLET]
>>> my_shape = arcade.create_rectangles_filled_with_colors(point_list, color_list)
>>> my_shape_list = ShapeElementList()
>>> my_shape_list.append(my_shape)
>>> my_shape_list.draw()
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.buffered_draw_commands.create_triangles_filled_with_colors(point_list, color_list) → arcade.buffered_draw_commands.VertexBuffer[source]

This function creates multiple rectangle/quads using a vertex buffer object. Creating the rectangles, and then later drawing it with render is faster than calling draw_rectangle.

>>> import arcade
>>> arcade.open_window(800,600,"Drawing Example")
>>> point_list = [(0, 0), (100, 0), (100, 100)]
>>> color_list = [arcade.color.RED, arcade.color.BLUE, arcade.color.GREEN]
>>> my_shape = arcade.create_triangles_filled_with_colors(point_list, color_list)
>>> my_shape_list = ShapeElementList()
>>> my_shape_list.append(my_shape)
>>> my_shape_list.draw()
>>> arcade.finish_render()
>>> arcade.quick_run(0.25)
arcade.buffered_draw_commands.get_rectangle_points(center_x: float, center_y: float, width: float, height: float, tilt_angle: float = 0)[source]

Utility function that will return all four coordinate points of a rectangle given the x, y center, width, height, and rotation.

arcade.buffered_draw_commands.render(shape: arcade.buffered_draw_commands.VertexBuffer)[source]

Render an shape previously created with a create function.

arcade.buffered_draw_commands.stripped_render(shape: arcade.buffered_draw_commands.VertexBuffer)[source]

Render an shape previously created with a create function. Used by ShapeElementList.draw() for drawing several shapes in a batch.

arcade.buffered_draw_commands.stripped_render_with_colors(shape: arcade.buffered_draw_commands.VertexBuffer)[source]

Render an shape previously created with a create function. Used by ShapeElementList.draw() for drawing several shapes in a batch. This version also assumes there is a color list as part of the VBO.

Application Class Module

The main window class that all object-oriented applications should derive from.

class arcade.application.Window(width: float = 800, height: float = 600, title: str = 'Arcade Window', fullscreen: bool = False, resizable: bool = False)[source]

Bases: pyglet.window.Window

Window class

>>> import arcade
>>> window = arcade.Window(200, 100, resizable=True)
>>> window.set_update_rate(1/20)
>>> window.set_mouse_visible(True)
>>> window.on_mouse_motion(0, 0, 0, 0)
>>> window.on_mouse_press(0, 0, 0, 0)
>>> window.on_mouse_release(0, 0, 0, 0)
>>> window.on_key_press(0, 0)
>>> window.on_key_release(0, 0)
>>> window.on_mouse_drag(0, 0, 1, 1, 1, 0)
>>> window.on_mouse_scroll(1, 1, 1, 1)
>>> window.on_draw()
>>> window.on_resize(500, 500)
>>> window.set_size(500, 500)
>>> window.update(1/20)
>>> window.set_visible(True)
>>> window.close()
get_location() → Tuple[int, int][source]

Return the X/Y coordinates of the window

get_size()[source]

Get the size of the window.

get_viewport() -> (<class 'float'>, <class 'float'>, <class 'float'>, <class 'float'>)[source]

Get the viewport. (What coordinates we can see.)

on_draw()[source]

Override this function to add your custom drawing code.

on_key_press(symbol: int, modifiers: int)[source]

Override this function to add key press functionality.

on_key_release(symbol: int, modifiers: int)[source]

Override this function to add key release functionality.

on_mouse_drag(x: float, y: float, dx: float, dy: float, buttons: int, modifiers: int)[source]

Override this function to add mouse button functionality.

on_mouse_motion(x: float, y: float, dx: float, dy: float)[source]

Override this function to add mouse functionality.

on_mouse_press(x: float, y: float, button: int, modifiers: int)[source]

Override this function to add mouse button functionality.

on_mouse_release(x: float, y: float, button: int, modifiers: int)[source]

Override this function to add mouse button functionality.

on_mouse_scroll(x: int, y: int, scroll_x: int, scroll_y: int)[source]

User moves the scroll wheel.

on_resize(width, height)[source]

Override this function to add custom code to be called any time the window is resized.

set_max_size(width: float, height: float)[source]

Wrap the Pyglet window call to set maximum size

Args:
width:width in pixels.
height:height in pixels.
Returns:
None
Raises:
ValueError

Example:

>>> import arcade
>>> window = arcade.Window(200, 100, resizable=True)
>>> window.set_max_size(200, 200)
>>> window.close()
set_min_size(width: float, height: float)[source]

Wrap the Pyglet window call to set minimum size

Args:
width:width in pixels.
height:height in pixels.

Example:

>>> import arcade
>>> window = arcade.Window(200, 100, resizable=True)
>>> window.set_min_size(200, 200)
>>> window.close()
set_mouse_visible(visible=True)[source]

If true, user can see the mouse cursor while it is over the window. Set false, the mouse is not visible. Default is true.

set_size(width: float, height: float)[source]

Ignore the resizable flag and set the size

set_update_rate(rate: float)[source]

Set how often the screen should be updated. For example, self.set_update_rate(1 / 20) will set the update rate to 60 fps

set_viewport(left: numbers.Number, right: numbers.Number, bottom: numbers.Number, top: numbers.Number)[source]

Set the viewport. (What coordinates we can see. Used to scale and/or scroll the screen.)

set_visible(visible=True)[source]

Set if the window is visible or not. Normally, a program’s window is visible.

update(delta_time: float)[source]

Move everything.

Args:
dt (float):Time interval since the last time the function was called.

Geometry Module

Functions for calculating geometry.

arcade.geometry.are_polygons_intersecting(poly_a: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]], poly_b: Union[typing.Tuple[typing.Union[typing.Tuple[float, float], typing.List[float]], ...], typing.List[typing.Union[typing.Tuple[float, float], typing.List[float]]]]) → bool[source]

Return True if two polygons intersect.

Args:
poly_a (tuple):List of points that define the first polygon.
poly_b (tuple):List of points that define the second polygon.
Returns:
bool
Raises:
None
Example:
>>> import arcade
>>> poly1 = ((0.1, 0.1), (0.2, 0.1), (0.2, 0.2), (0.1, 0.2))
>>> poly2 = ((0.15, 0.1), (0.25, 0.1), (0.25, 0.25), (0.15, 0.25))
>>> poly3 = ((0.3, 0.1), (0.4, 0.1), (0.4, 0.2), (0.3, 0.2))
>>> test1 = arcade.are_polygons_intersecting(poly1, poly2)
>>> test2 = arcade.are_polygons_intersecting(poly2, poly3)
>>> test3 = arcade.are_polygons_intersecting(poly1, poly3)
>>> print(test1, test2, test3)
True False False
arcade.geometry.check_for_collision(sprite1: arcade.sprite.Sprite, sprite2: arcade.sprite.Sprite) → bool[source]

Check for a collision between two sprites.

>>> import arcade
>>> scale = 1
>>> filename = "arcade/examples/images/meteorGrey_big1.png"
>>> sprite_1 = arcade.Sprite(filename, scale)
>>> sprite_1.center_x = 0
>>> sprite_1.center_y = 0
>>> sprite_2 = arcade.Sprite(filename, scale)
>>> sprite_2.center_x = 40
>>> sprite_2.center_y = 40
>>> result = check_for_collision(sprite_1, sprite_2)
>>> sprite_3 = arcade.Sprite(filename, scale)
>>> sprite_3.center_x = 90
>>> sprite_3.center_y = 90
>>> result_1 = check_for_collision(sprite_1, sprite_2)
>>> result_2 = check_for_collision(sprite_2, sprite_3)
>>> result_3 = check_for_collision(sprite_1, sprite_3)
>>> print(result_1, result_2, result_3)
True True False
arcade.geometry.check_for_collision_with_list(sprite1: arcade.sprite.Sprite, sprite_list: arcade.sprite.SpriteList) → List[arcade.sprite.Sprite][source]

Check for a collision between a sprite, and a list of sprites.

>>> import arcade
>>> scale = 1
>>> sprite_list = arcade.SpriteList()
>>> filename = "arcade/examples/images/meteorGrey_big1.png"
>>> main_sprite = arcade.Sprite(filename, scale)
>>> main_sprite.center_x = 0
>>> main_sprite.center_y = 0
>>> sprite = arcade.Sprite(filename, scale)
>>> sprite.center_x = 40
>>> sprite.center_y = 40
>>> sprite_list.append(sprite)
>>> sprite = arcade.Sprite(filename, scale)
>>> sprite.center_x = 100
>>> sprite.center_y = 100
>>> sprite_list.append(sprite)
>>> collision_list = arcade.check_for_collision_with_list(main_sprite, sprite_list)
>>> print(len(collision_list))
1

Sprite Module

This module manages all of the code around Sprites.

class arcade.sprite.AnimatedTimeSprite(scale: float = 1, image_x: float = 0, image_y: float = 0, center_x: float = 0, center_y: float = 0)[source]

Bases: arcade.sprite.Sprite

Sprite for platformer games that supports animations.

>>> import arcade
>>> my_sprite = arcade.AnimatedTimeSprite()
>>> my_texture = arcade.Texture(1, 10, 10)
>>> my_sprite.append_texture(my_texture)
>>> my_sprite.update_animation()
update_animation()[source]

Logic for selecting the proper texture to use.

class arcade.sprite.AnimatedWalkingSprite(scale: float = 1, image_x: float = 0, image_y: float = 0, center_x: float = 0, center_y: float = 0)[source]

Bases: arcade.sprite.Sprite

Sprite for platformer games that supports animations.

>>> my_sprite = AnimatedWalkingSprite()
>>> my_texture1 = Texture(1, 10, 10)
>>> my_texture2 = Texture(1, 10, 10)
>>> my_sprite.stand_right_textures = my_texture1, my_texture2
>>> my_sprite.update_animation()
update_animation()[source]

Logic for selecting the proper texture to use.

class arcade.sprite.Sprite(filename: str = None, scale: float = 1, image_x: float = 0, image_y: float = 0, image_width: float = 0, image_height: float = 0, center_x: float = 0, center_y: float = 0)[source]

Bases: object

Class that represents a ‘sprite’ on-screen.

Attributes:
scale:Scale the sprite. Default is 1. Setting to 0.5 would halve the width and height.
center_x:x coordinate of the sprite’s center.
center_y:y coordinate of the sprite’s center.
angle:Angle at which the sprite is drawn. 0 is default, 180 is upside-down.
change_x:Movement vector, in the x direction.
change_y:Movement vector, in the y direction.
change_angle:Change in rotation.
alpha:Transparency. 1 is solid, 0 is fully transparent (invisible).
transparent:Set to True if this sprite can be transparent.
sprite_lists:List of all the sprite lists this sprite is part of.
textures:List of textures associated with this sprite.
cur_texture_index:
 Index of current texture being used.
Example:
>>> import arcade
>>> arcade.open_window(800,600,"Sprite Example")
>>> SCALE = 1
>>> # Test creating an empty sprite
>>> empty_sprite = arcade.Sprite()
>>> # Create a sprite with an image
>>> filename = "arcade/examples/images/playerShip1_orange.png"
>>> ship_sprite = arcade.Sprite(filename, SCALE)
>>> # Draw the sprite
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> ship_sprite.draw()
>>> arcade.finish_render()
>>> # Move the sprite
>>> ship_sprite.change_x = 1
>>> ship_sprite.change_y = 1
>>> ship_sprite.angle = 45
>>> ship_sprite.update() # Move/update the ship
>>> # Remove the sprite
>>> ship_sprite.kill()
>>> ship_sprite = arcade.Sprite(filename, SCALE, image_height=-1)
Traceback (most recent call last):
...
ValueError: Height entered is less than zero. Height must be a positive float.
>>> ship_sprite = arcade.Sprite(filename, SCALE, image_width=-1)
Traceback (most recent call last):
...
ValueError: Width of image can't be less than zero.
>>> ship_sprite = arcade.Sprite(filename, SCALE, image_width=0, image_height=1)
Traceback (most recent call last):
...
ValueError: Width can't be zero.
>>> ship_sprite = arcade.Sprite(filename, SCALE, image_height=0, image_width=1)
Traceback (most recent call last):
...
ValueError: Height can't be zero.
>>> arcade.quick_run(0.25)
angle

Get the angle of the sprite’s rotation.

append_texture(texture: arcade.draw_commands.Texture)[source]

Appends a new texture to the list of textures that can be applied to this sprite.

>>> import arcade
>>> empty_sprite = arcade.Sprite()
>>> my_texture = Texture(1, 10, 10)
>>> empty_sprite.append_texture(my_texture)
bottom

Return the y coordinate of the bottom of the sprite.

>>> import arcade
>>> arcade.open_window(800,600,"Sprite Example")
>>> scale = 1.0
>>> ship_sprite = arcade.Sprite("arcade/examples/images/playerShip1_orange.png", scale)
>>> ship_sprite.center_y = 0.0
>>> print(ship_sprite.bottom)
-37.5
>>> ship_sprite.bottom = 1.0
>>> print(ship_sprite.bottom)
1.0
>>> arcade.quick_run(0.25)
center_x

Get the center x coordinate of the sprite.

center_y

Get the center y coordinate of the sprite.

change_x

Get the velocity in the x plane of the sprite.

change_y

Get the velocity in the y plane of the sprite.

collision_radius

Get the collision radius. Note: Final collision checking is done via geometry that was set in get_points/set_points. These points are used in the check_for_collision function. This collision_radius variable is used as a “pre-check.” We do a super-fast check with collision_radius and see if the sprites are close. If they are, then we look at the geometry and figure if they really are colliding.

>>> import arcade
>>> empty_sprite = arcade.Sprite()
>>> empty_sprite.width = 3
>>> empty_sprite.height = 4
>>> empty_sprite.collision_radius
4
draw()[source]

Draw the sprite.

get_points() → Tuple[Tuple[float, float]][source]

Get the corner points for the rect that makes up the sprite.

>>> import arcade
>>> empty_sprite = arcade.Sprite()
>>> my_points = (0,0),(1,1),(0,1),(1,0)
>>> empty_sprite.set_points(my_points)
>>> empty_sprite.get_points()
((0, 0), (1, 1), (0, 1), (1, 0))
get_texture() → int[source]

This returns the index of which texture is being displayed.

>>> import arcade
>>> empty_sprite = arcade.Sprite()
>>> my_texture = Texture(1, 10, 10)
>>> empty_sprite.append_texture(my_texture)
>>> empty_sprite.get_texture()
0
kill()[source]

Remove the sprite from all sprite lists.

left

Left-most coordinate.

Example:
>>> import arcade
>>> arcade.open_window(800,600,"Sprite Example")
>>> scale = 1.0
>>> ship_sprite = arcade.Sprite("arcade/examples/images/playerShip1_orange.png", scale)
>>> ship_sprite.center_x = 0.0
>>> print(ship_sprite.left)
-49.5
>>> ship_sprite.left = 1.0
>>> print(ship_sprite.left)
1.0
>>> arcade.quick_run(0.25)
points

Get the corner points for the rect that makes up the sprite.

>>> import arcade
>>> empty_sprite = arcade.Sprite()
>>> my_points = (0,0),(1,1),(0,1),(1,0)
>>> empty_sprite.set_points(my_points)
>>> empty_sprite.get_points()
((0, 0), (1, 1), (0, 1), (1, 0))
register_sprite_list(new_list)[source]

Register this sprite as belonging to a list. We will automatically remove ourselves from the the list when kill() is called.

right

Return the x coordinate of the right-side of the sprite.

Example:
>>> import arcade
>>> arcade.open_window(800,600,"Sprite Example")
>>> scale = 1.0
>>> ship_sprite = arcade.Sprite("arcade/examples/images/playerShip1_orange.png", scale)
>>> ship_sprite.center_x = 0.0
>>> print(ship_sprite.right)
49.5
>>> ship_sprite.right = 1.0
>>> print(ship_sprite.right)
1.0
>>> arcade.quick_run(0.25)
set_points(points: Sequence[Sequence[float]])[source]

Set a sprite’s position

>>> import arcade
>>> empty_sprite = arcade.Sprite()
>>> my_points = (0,0),(1,1),(0,1),(1,0)
>>> empty_sprite.set_points(my_points)
set_position(center_x: float, center_y: float)[source]

Set a sprite’s position

>>> import arcade
>>> empty_sprite = arcade.Sprite()
>>> empty_sprite.set_position(10, 10)
set_texture(texture_no: int)[source]

Assuming ‘texture’ is a list of textures, this sets which texture index should be displayed. It also resets the width and height based on the scale of the texture.

>>> import arcade
>>> empty_sprite = arcade.Sprite()
>>> my_texture = Texture(1, 10, 10)
>>> empty_sprite.append_texture(my_texture)
>>> empty_sprite.set_texture(0)
texture

Return the texture that the sprite uses.

top

Return the y coordinate of the top of the sprite.

>>> import arcade
>>> arcade.open_window(800,600,"Sprite Example")
>>> scale = 1.0
>>> ship_sprite = arcade.Sprite("arcade/examples/images/playerShip1_orange.png", scale)
>>> ship_sprite.center_y = 0.0
>>> print(ship_sprite.top)
37.5
>>> ship_sprite.top = 1.0
>>> print(ship_sprite.top)
1.0
>>> ship_sprite.angle = 90
>>> arcade.quick_run(0.25)
update()[source]

Update the sprite.

update_animation()[source]

Override this to add code that will change what image is shown, so the sprite can be animated.

class arcade.sprite.SpriteList(is_static=False)[source]

Bases: typing.Generic

List of sprites.

Unit Test:
>>> import arcade
>>> import random
>>> import os
>>> arcade.open_window(600,600,"Sprite Example")
>>> scale = 1
>>> meteor_list = arcade.SpriteList()
>>> filename = "arcade/examples/images/meteorGrey_big1.png"
>>> for i in range(100):
...     meteor = arcade.Sprite(filename, scale)
...     meteor.center_x = random.random() * 2 - 1
...     meteor.center_y = random.random() * 2 - 1
...     meteor_list.append(meteor)
>>> meteor_list.remove(meteor) # Remove last meteor, just to test
>>> m = meteor_list.pop() # Remove another meteor, just to test
>>> meteor_list.update() # Call update on all items
>>> print(len(meteor_list))
98
>>> arcade.set_background_color(arcade.color.WHITE)
>>> arcade.start_render()
>>> meteor_list.draw(fast=False)
>>> if 'APPVEYOR' not in os.environ or os.environ['APPVEYOR'] != 'TRUE':
...     meteor_list.draw()
>>> meteor_list.move(0, -1)
>>> arcade.finish_render()
>>> for meteor in meteor_list:
...     meteor.kill()
>>> arcade.quick_run(0.25)
append(item: T)[source]

Add a new sprite to the list.

draw(fast: bool = True)[source]

Call the draw() method on each sprite in the list.

move(change_x: float, change_y: float)[source]
pop() → arcade.sprite.Sprite[source]

Pop off the last sprite in the list.

remove(item: T)[source]

Remove a specific sprite from the list.

update()[source]

Call the update() method on each sprite in the list.

update_animation()[source]

Call the update_animation() method on each sprite in the list.

Physics Engines Module

Physics engines for top-down or platformers.

class arcade.physics_engines.PhysicsEnginePlatformer(player_sprite: arcade.sprite.Sprite, platforms: arcade.sprite.SpriteList, gravity_constant: float = 0.5)[source]

Bases: object

This class will move everything, and take care of collisions.

>>> import arcade
>>> player = arcade.Sprite()
>>> player.change_y = -1
>>> player.change_x = -1
>>> walls = SpriteList()
>>> wall = arcade.Sprite()
>>> wall.change_x = 1
>>> wall.change_y = 1
>>> walls.append(wall)
>>> engine = PhysicsEnginePlatformer(player, walls)
>>> engine.can_jump()
False
>>> engine.update()
can_jump() → bool[source]

Method that looks to see if there is a floor under the player_sprite. If there is a floor, the player can jump and we return a True.

update()[source]

Move everything and resolve collisions.

class arcade.physics_engines.PhysicsEngineSimple(player_sprite: arcade.sprite.Sprite, walls: arcade.sprite.SpriteList)[source]

Bases: object

This class will move everything, and take care of collisions.

>>> import arcade
>>> player = arcade.Sprite()
>>> player.change_y = -1
>>> player.change_x = -1
>>> walls = SpriteList()
>>> wall = Sprite()
>>> walls.append(wall)
>>> engine = PhysicsEngineSimple(player, walls)
>>> engine.update()
update()[source]

Move everything and resolve collisions.

Sound Module

Sound library.

From https://github.com/TaylorSMarks/playsound/blob/master/playsound.py

exception arcade.sound.PlaysoundException[source]

Bases: Exception

arcade.sound.load_sound(filename: str) → Any[source]

Ok, this doesn’t do anything yet.

>>> import arcade
>>> my_sound = arcade.load_sound("arcade/examples/sounds/rockHit2.wav")
>>> arcade.play_sound(my_sound)
arcade.sound.play_sound(sound)

Utilizes windll.winmm. Tested and known to work with MP3 and WAVE on Windows 7 with Python 2.7. Probably works with more file formats. Probably works on Windows XP thru Windows 10. Probably works with all versions of Python. Inspired by (but not copied from) Michael Gundlach <gundlach@gmail.com>’s mp3play: https://github.com/michaelgundlach/mp3play I never would have tried using windll.winmm without seeing his code.