References

Package Summary

System init and close

close_graph
init_graph

API Details

class easygraphics.Color

These are the predefined Color constants.

BLACK

Black color

BLUE

Blue

BROWN = '#A8A800'

brown

CYAN

cyan

DARK_BLUE

dark blue

DARK_CYAN

dark cyan

DARK_GRAY

Dark Gray color

DARK_GREEN

dark green

DARK_MAGENTA

dark magenta

DARK_RED

dark red

DARK_YELLOW

dark yellow

GREEN

Green

LIGHT_BLUE = 5526780

Light blue

LIGHT_CYAN = 5569788

light cyan

LIGHT_GRAY = 11053224

Light Gray

LIGHT_GREEN = 5569620

Light green

LIGHT_MAGENTA = 16536828

light magenta

LIGHT_RED = 16536660

light red

LIGHT_YELLOW = 16579668

light yellow

MAGENTA = 11010216

magenta

RED

red

TRANSPARENT

Transparent

Values = (<sphinx.ext.autodoc.importer._MockObject object>, <sphinx.ext.autodoc.importer._MockObject object>, <sphinx.ext.autodoc.importer._MockObject object>, <sphinx.ext.autodoc.importer._MockObject object>, <sphinx.ext.autodoc.importer._MockObject object>, 11010216, '#A8A800', 11053224, <sphinx.ext.autodoc.importer._MockObject object>, 5526780, 5569620, 5569788, 16536660, 16536828, <sphinx.ext.autodoc.importer._MockObject object>, <sphinx.ext.autodoc.importer._MockObject object>, 16579668, <sphinx.ext.autodoc.importer._MockObject object>, <sphinx.ext.autodoc.importer._MockObject object>, <sphinx.ext.autodoc.importer._MockObject object>, <sphinx.ext.autodoc.importer._MockObject object>, <sphinx.ext.autodoc.importer._MockObject object>, <sphinx.ext.autodoc.importer._MockObject object>)
WHITE

White

YELLOW

yellow

class easygraphics.FillStyle

These are the fill style used by draw and fill functions.

BKSLASH_FILL

Used by autodoc_mock_imports.

CLOSE_DOT_FILL

Used by autodoc_mock_imports.

HATCH_FILL

Used by autodoc_mock_imports.

LINE_FILL

Fill with horizontal lines.

LTBKSLASH_FILL

File with diagonal lines.

LTSLASH_FILL

Used by autodoc_mock_imports.

NULL_FILL

Not fill at all. For example, draw_circle() will not fill.

SLASH_FILL

File with diagonal lines.

SOLID_FILL

Fill with solid color. see set_fill_color().

WIDE_DOT_FILL

Used by autodoc_mock_imports.

XHATCH_FILL

Used by autodoc_mock_imports.

class easygraphics.LineStyle

These are the line styles that can be drawn. The styles are:

qpen-solid qpen-dash qpen-dot
LineStyle.SOLID_LINE LineStyle.DASH_LINE LineStyle.DOT_LINE
qpen-dashdot qpen-dashdotdot  
LineStyle.DASH_DOT_LINE LineStyle.DASH_DOT_DOT_LINE LineStyle.NO_PEN
DASH_DOT_DOT_LINE

One dash, two dots, one dash, two dots.

DASH_DOT_LINE

Alternate dots and dashes.

DASH_LINE

Dashes separated by a few pixels.

DOT_LINE

Dots separated by a few pixels.

NO_PEN

no line at all. For example, draw_circle fills but does not draw any boundary line.

SOLID_LINE

A plain line

class easygraphics.RenderMode

These are the graphics window render mode.

RENDER_AUTO = 0

The graphics window is updated after each drawn.

RENDER_MANUAL = 1

The graphics window only updated after functions that wait or delay.

class easygraphics.CompositionMode

Defines the modes supported for digital image compositing.

Composition modes are used to specify how the pixels in one image, the source, are merged with the pixel in another image, the destination.

Please note that the bitwise operation modes are not supported for pens and brushes with alpha components.

CLEAR

(Alpha Composition) The pixels in the destination are cleared (set to fully transparent) independent of the source.

CLEAR_DEST

(Raster Op) The pixels in the destination are cleared (set to 0) independent of the source.

COLOR_BURN

(Blend mode) The destination color is darkened to reflect the source color. A white source color leaves the destination color unchanged.

COLOR_DODGE

(Blend mode) The destination color is brightened to reflect the source color. A black source color leaves the destination color unchanged.

DARKEN

(Blend mode) The darker of the source and destination colors is selected.

DESTINATION

(Alpha Composition) The output is the destination pixel. This means that the blending has no effect.

DESTINATION_AT_TOP

(Alpha Composition) The destination pixel is blended on top of the source, with the alpha of the destination pixel is reduced by the alpha of the source pixel.

DESTINATION_IN

(Alpha Composition) The output is the destination, where the alpha is reduced by that of the source.

DESTINATION_OUT

(Alpha Composition) The output is the destination, where the alpha is reduced by the inverse of the source.

DESTINATION_OVER

(Alpha Composition) The alpha of the destination is used to blend it on top of the source pixels.

DIFFERENCE

(Blend mode) Subtracts the darker of the colors from the lighter. Painting with white inverts the destination color, whereas painting with black leaves the destination color unchanged.

EXCLUSION

(Blend mode) Similar to DIFFERENCE, but with a lower contrast. Painting with white inverts the destination color, whereas painting with black leaves the destination color unchanged.

HARD_LIGHT

(Blend mode) Multiplies or screens the colors depending on the source color. A light source color will lighten the destination color, whereas a dark source color will darken the destination color.

LIGHTEN

(Blend mode) The lighter of the source and destination colors is selected.

MULTIPLY

(Blend mode) The output is the source color multiplied by the destination. Multiplying a color with white leaves the color unchanged, while multiplying a color with black produces black.

NOT_DEST

(Raster Op) Does a bitwise operation where the destination pixels are inverted (NOT dst).

NOT_SRC

(Raster Op) Does a bitwise operation where the source pixels are inverted (NOT src).

NOT_SRC_AND_DEST

(Raster Op) Does a bitwise operation where the source is inverted and then AND’ed with the destination ((NOT src) AND dst).

NOT_SRC_AND_NOT_DEST

(Raster Op) Does a bitwise NOR operation on the source and destination pixels ((NOT src) AND (NOT dst)).

NOT_SRC_OR_DEST

(Raster Op) Does a bitwise operation where the source is inverted and then OR’ed with the destination ((NOT src) OR dst).

NOT_SRC_OR_NOT_DEST

(Raster Op) Does a bitwise NAND operation on the source and destination pixels ((NOT src) OR (NOT dst)).

NOT_SRC_XOR_DEST

(Raster Op) Does a bitwise operation where the source pixels are inverted and then XOR’ed with the destination ((NOT src) XOR dst).

OVERLAY

(Blend mode) Multiplies or screens the colors depending on the destination color. The destination color is mixed with the source color to reflect the lightness or darkness of the destination.

Plus

(Blend mode) Both the alpha and color of the source and destination pixels are added together.

SCREEN

(Blend mode) The source and destination colors are inverted and then multiplied. Screening a color with white produces white, whereas screening a color with black leaves the color unchanged.

SET_DEST

(Raster Op) The pixels in the destination are set (set to 1) independent of the source.

SOFT_LIGHT

(Blend mode) Darkens or lightens the colors depending on the source color. Similar to HARD_LIGHT.

SOURCE

(Alpha Composition) The output is the source pixel.

SOURCE_AT_TOP

(Alpha Composition) The source pixel is blended on top of the destination, with the alpha of the source pixel reduced by the alpha of the destination pixel.

SOURCE_IN

(Alpha Composition) The output is the source, where the alpha is reduced by that of the destination.

SOURCE_OUT

(Alpha Composition) The output is the source, where the alpha is reduced by the inverse of destination.

SOURCE_OVER

(Alpha Composition) This is the default mode. The alpha of the source is used to blend the pixel on top of the destination.

SRC_AND_DEST

(Raster Op) Does a bitwise AND operation on the source and destination pixels (src AND dst).

SRC_AND_NOT_DEST

(Raster Op) Does a bitwise operation where the source is AND’ed with the inverted destination pixels (src AND (NOT dst)).

SRC_OR_DEST

(Raster Op) Does a bitwise OR operation on the source and destination pixels (src OR dst).

SRC_OR_NOT_DEST

(Raster Op) Does a bitwise operation where the source is OR’ed with the inverted destination pixels (src OR (NOT dst)).

SRC_XOR_DEST

(Raster Op) Does a bitwise XOR operation on the source and destination pixels (src XOR dst).

XOR

(Alpha Composition) The source, whose alpha is reduced with the inverse of the destination alpha, is merged with the destination, whose alpha is reduced by the inverse of the source alpha. CompositionMode_Xor is not the same as the bitwise Xor.

class easygraphics.TextFlags

These are the text drawing flags.

ALIGN_BOTTOM

Aligns with the bottom.

ALIGN_CENTER

Centers in both dimensions.

ALIGN_HCENTER

Centers horizontally in the available space.

ALIGN_JUSTIFY

Justifies the text in the available space.

ALIGN_LEFT

Aligns with the left edge.

ALIGN_RIGHT

Aligns with the right edge.

ALIGN_TOP

Aligns with the top.

ALIGN_VCENTER

Centers vertically in the available space.

TEXT_DONT_CLIP

If it’s impossible to stay within the given bounds, it prints outside.

TEXT_EXPAND_TABS

Makes the U+0009 (ASCII tab) character move to the next tab stop.

TEXT_SINGLE_LINE

Treats all whitespace as spaces and prints just one line.

TEXT_WORD_WRAP

Breaks lines at appropriate points, e.g. at word boundaries.

class easygraphics.MouseMessageType

These are the mouse message types.

DOUBLE_CLICK_MESSAGE = 3
NO_MESSAGE = 0
PRESS_MESSAGE = 1
RELEASE_MESSAGE = 2
class easygraphics.FillRule

The Rule for fill polygons.

ODD_EVEN_FILL

Specifies that the region is filled using the odd even fill rule.

WINDING_FILL

Specifies that the region is filled using the non zero winding rule.

class easygraphics.ShapeMode

This flag controls how shapes will be drawn. The framework’s default value is RADIUS.

CENTER = 2
CORNER = 1
CORNERS = 0
RADIUS = 3
class easygraphics.VertexType

These are the type of shape defined by a vertex list.

LINES = 2
POINTS = 1
POLY_LINE = 0
QUADS = 6
QUAD_STRIP = 7
TRIANGLES = 3
TRIANGLE_FAN = 4
TRIANGLE_STRIP = 5
easygraphics.set_line_style(line_style, image: easygraphics.image.Image = None)

Set line style of the specified image.

The line style will be used when drawing lines and shape outlines. Possible value is one of the consts defined in LineStyle.

Parameters:
  • line_style – line style
  • image – the target image whose line style is to be set. None means it is the default target image (see set_target() and get_target())
easygraphics.get_line_style(image: easygraphics.image.Image = None) → int

Get line style of the specified image.

The line style will be used when drawing lines or shape outlines.

Parameters:image – the target image whose line style is to be gotten. None means it is the target image (see set_target() and get_target())
Returns:line style used by the specified image
easygraphics.set_line_width(width: float, image: easygraphics.image.Image = None)

Set line width (thickness) of the specified image.

It will be used when drawing lines or shape outlines

Parameters:
  • width – line width (line thickness)
  • image – the target image whose line width is to be set. None means it is the target image (see set_target() and get_target())
easygraphics.get_line_width(image: easygraphics.image.Image = None) → float

Get line width (thinkness) of the specified image.

It will be used when drawing lines or shape outlines

Parameters:image – the target image whose line width is to be gotten. None means it is the target image (see set_target() and get_target())
Returns:line width (line thickness) of the specified image
easygraphics.get_color(image: easygraphics.image.Image = None) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>

Get the foreground (drawing) color of the specified image.

it will be used when drawing lines or shape outlines

Parameters:image – the target image whose foreground color is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:foreground color of the specified image
easygraphics.set_color(color, image: easygraphics.image.Image = None)

Set the foreground (drawing) color of the specified image.

it will be used when drawing lines or shape outlines.

the possible color could be consts defined in Color class, or the color created by rgb() function, or PyQt5’s QColor , QGradient object or Qt.GlobalColor consts (see the pyqt reference).

Parameters:
  • color – the foreground color
  • image – the target image whose foreground color is to be set. None means it is the target image (see set_target() and get_target()).
easygraphics.get_fill_color(image: easygraphics.image.Image = None) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>

Get the fill color of the specified image.

it will be used when drawing and fill shapes.

Parameters:image – the target image whose fill color is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:fill color of the specified image
easygraphics.set_fill_color(color, image: easygraphics.image.Image = None)

Set the fill (drawing) color of the specified image.

It will be used when drawing and fill shapes.

the possible color could be consts defined in Color class, or the color created by rgb() function, or PyQt5’s QColor , QGradient object or Qt.GlobalColor consts (see the pyqt reference).

Parameters:
  • color – the fill color
  • image – the target image whose fill color is to be set. None means it is the target image (see set_target() and get_target()).
easygraphics.get_fill_style(image: easygraphics.image.Image = None) → int

Get fill style of the specified image.

it will be used when drawing and fill shapes.

Parameters:image – the target image whose fill style is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:fill style of the specified image
easygraphics.set_fill_style(style, image: easygraphics.image.Image = None)
Set fill style of the specified image.

it will be used when drawing and fill shapes. Valid values are the consts defined in FillStyle

Parameters:
  • style – fill style
  • image – the target image whose fill style is to be set. None means it is the target image (see set_target() and get_target()).
Returns:

easygraphics.get_background_color(image: easygraphics.image.Image = None) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>

Get the background color of the image.

Parameters:image – the target image whose background color is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:background color of the specified image
easygraphics.set_background_color(color, image: easygraphics.image.Image = None)

Set and change the background color.

the possible color could be consts defined in Color class, or the color created by rgb() function, or PyQt5’s QColor , QGradient object or Qt.GlobalColor consts (see the pyqt reference).

Parameters:
  • color – the background color
  • image – the target image whose background color is to be set. None means it is the target image (see set_target() and get_target()).
easygraphics.set_font(font: <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>, image: easygraphics.image.Image = None)

Set font of the specified image.

Parameters:
  • font – the font will be used
  • image – the target image whose font is to be set. None means it is the target image (see set_target() and get_target()).
easygraphics.get_font(image: easygraphics.image.Image = None) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>

Get font of the specified image.

Parameters:image – the target image whose font is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:the font used by the specified image
easygraphics.set_font_size(size: int, image: easygraphics.image.Image = None)

Set font size of the specified image.

Parameters:
  • size – font size of the specified image
  • image – the target image whose write mode is to be gotten. None means it is the target image (see set_target() and get_target()).
easygraphics.get_font_size(image: easygraphics.image.Image = None) → int

Get font size of the specified image.

Parameters:image – the target image whose write mode is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:font size of the specified image
easygraphics.set_composition_mode(mode, image: easygraphics.image.Image = None)

Set composition mode of the specified image.

Composition modes are used to specify how the pixels in the source (image/pen/brush), are merged with the pixel in the destination image.

Parameters:
  • mode – composition mode
  • image – the target image whose composition mode is to be set. None means it is the target image (see set_target() and get_target()).
easygraphics.get_composition_mode(image: easygraphics.image.Image = None) → int

Get composition mode of the specified image.

When drawing ,the composition mode will decide how the result pixel color will be computed (using source color and color of the destination)

Parameters:image – the target image whose composition mode is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:composition mode
easygraphics.get_drawing_x(image: easygraphics.image.Image = None) → float

Get the x coordinate value of the current drawing position (x,y).

Some drawing functions will use the current pos to draw.(see line_to(),line_rel(),move_to(),move_rel()).

Parameters:image – the target image whose drawing pos is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:the x coordinate value of the current drawing position
easygraphics.get_drawing_y(image: easygraphics.image.Image = None) → float

Get the y coordinate value of the current drawing position (x,y).

Some drawing functions will use the current pos to draw.(see line_to(),line_rel(),move_to(),move_rel()).

Parameters:image – the target image whose drawing pos is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:the y coordinate value of the current drawing position
easygraphics.set_view_port(left: int, top: int, right: int, bottom: int, clip: bool = True, image: easygraphics.image.Image = None)

Set the view port of the the specified image.

View port is the drawing zone on the image.

>>> from easygraphics import *
>>> init_graph(800,600)
>>> draw_rect(100,100,300,300)
>>> set_view_port(100,100,300,300)
>>> circle(100,100,50)
>>> circle(100,100,100)
>>> circle(100,100,120)
>>> pause()
>>> close_graph()
Parameters:
  • left – left of the view port rectangle
  • top – top of the view port rectangle
  • right – right of the view port rectangle
  • bottom – bottom of the view port rectangle
  • clip – if True, drawings outside the port rectangle will be clipped
  • image – the target image whose view port is to be gotten. None means it is the target image (see set_target() and get_target()).
easygraphics.reset_view_port(image: easygraphics.image.Image = None)

Reset the view port setting.

Parameters:image – the target image whose view port is to be reset. None means it is the target image (see set_target() and get_target()).
easygraphics.set_origin(offset_x: float, offset_y: float, image: easygraphics.image.Image = None)

Translates the coordinate system by the given offset; i.e.the given offset is added to points.

Parameters:
  • offset_x – offset on the x coordinate
  • offset_y – offset on the y coordinate
  • image – the target image to be translated. None means it is the target image (see set_target() and get_target()).
easygraphics.get_fill_rule(image: easygraphics.image.Image = None) → int

Get the fill rule (algorithm) for filling polygons.

Parameters:image – the target image whose fill rule is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:the rule used for filling polygons
easygraphics.set_fill_rule(rule, image: easygraphics.image.Image = None)

Set the fill rule (algorithm) for filling polygons.

Parameters:
  • rule – the rule to be used for filling polygons
  • image – the target image whose fill rule is to be set. None means it is the target image (see set_target() and get_target()).
Returns:

easygraphics.set_render_mode(mode: int)

Set render mode of the graphics window.

This mode will control how the graphics window is updated.

possible values:

  • RenderMode.RENDER_AUTO (default) update the window immediately after every drawing
  • RenderMode.MANUAL only update the window after pause()/delay()/delay_fps()/delay_jfps() is called.

RenderMode.MANUAL is used for animations

Parameters:mode – render mode
easygraphics.get_render_mode()

Set render mode of the graphics window.

This mode will control how the graphics window is updated. See set_render_mode()

Returns:render mode
easygraphics.get_drawing_pos(image: easygraphics.image.Image = None) -> (<class 'float'>, <class 'float'>)

Get the current drawing position (x,y).

Some drawing functions will use the current pos to draw.(see line_to(),line_rel(),move_to(),move_rel()).

Parameters:image – the target image whose drawing pos is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:the current drawing position (x,y)
easygraphics.set_clip_rect(left: int, top: int, right: int, bottom: int, image: easygraphics.image.Image = None)

Set the clip rect.

Drawings outside the clip rect will be clipped.

Parameters:
  • left – left of the clip rectangle
  • top – top of the clip rectangle
  • right – right of the clip rectangle
  • bottom – bottom of the clip rectangle
  • image – the target image whose clip rect is to be gotten. None means it is the target image (see set_target() and get_target()).
easygraphics.set_clipping(clipping: bool, image: easygraphics.image.Image = None)

Set clipping.

Use set_clip_rect() to set the clip rectangle.

Parameters:
  • clipping – True will turn on clipping, False will turn off clipping
  • image – the target image whose clip rect is to be disabled. None means it is the target image (see set_target() and get_target()).
easygraphics.set_window(left: int, top: int, width: int, height: int, image: easygraphics.image.Image = None)

Set the logical drawing window.

All your drawing is first drawing on the logical window, then mapping to view port (see set_view_port()). The logical window’s 4 corner points to streched to match the view port.

If your view port is 200x200,and you use set_window(-50,-50,100,100) to get a 100x100 logical window with the left-top corner at (-50,-50) , then the logical window’s left corner (-50,-50) is set to view port’s (0,0), and right-bottom corner (50,50) is set to view port’s right bottom corner (200,200). All logical points is mapping accordingly.

If you just want to transform the drawing, use set_origin()/translate()/rotate()/scale().

The drawing outside the logical window is not clipped. If you want to clip it, use set_clip_rect().

Parameters:
  • left – x pos of the logical window’s left-top corner
  • top – y pos of the logical window’s left-top corner
  • width – width of the logical window
  • height – height of the logical window
  • image – the target image whose logical window is to be set. None means it is the target image (see set_target() and get_target()).
easygraphics.reset_window(image: easygraphics.image.Image = None)

Reset/remove the logical window.

See set_window().

Parameters:image – the target image whose logical window is to be reset. None means it is the target image (see set_target() and get_target()).
easygraphics.translate(offset_x: float, offset_y: float, image: easygraphics.image.Image = None)

Translates the coordinate system by the given offset; i.e.the given offset is added to points.

Parameters:
  • offset_x – offset on the x coordinate
  • offset_y – offset on the y coordinate
  • image – the target image to be translated. None means it is the target image (see set_target() and get_target()).
easygraphics.rotate(degree: float, x: float = 0, y: float = 0, image: easygraphics.image.Image = None)

Rotates the coordinate system around the point (x,y) with the given angle (in degree) clockwise.

Parameters:
  • degree – the rotate angle (in degree)
  • x – the x coordinate of the rotation center
  • y – the y coordinate of the rotation center
  • image – the target image to be rotated. None means it is the target image (see set_target() and get_target()).
easygraphics.scale(sx: float, sy: float, image: easygraphics.image.Image = None)

Scales the coordinate system by (sx, sy).

Parameters:
  • sx – scale factor on x axis.
  • sy – scale factor on y axis.
  • image – the target image to be scaled. None means it is the target image (see set_target() and get_target()).
easygraphics.skew(sh: float, sv: float, x: float = 0, y: float = 0, image: easygraphics.image.Image = None)

Shear (skew) the coordinates around the point (x,y) by sh,sv.

Parameters:
  • sh – shear ratio on the x-axis
  • sv – shear ratio on the y-axis
  • x – the x coordinate of the skew center
  • y – the y coordinate of the skew center
  • image – the target image to be sheared. None means it is the target image (see set_target() and get_target()).
easygraphics.shear(sh: float, sv: float, x: float = 0, y: float = 0, image: easygraphics.image.Image = None)

Shear (skew) the coordinates around the point (x,y) by sh,sv.

Parameters:
  • sh – shear ratio on the x-axis
  • sv – shear ratio on the y-axis
  • x – the x coordinate of the skew center
  • y – the y coordinate of the skew center
  • image – the target image to be sheared. None means it is the target image (see set_target() and get_target()).
easygraphics.set_flip_y(flip_y: bool, image: easygraphics.image.Image = None) → None

Reflect without texts using the x-axis as the axis (image upside down).

Texts will not get flipped.

Don’t translate the origin to other points (but you can translate and then translate back) before drawing any text. Or the text position’s calculation will get wrong! So if you want to set the origin to the image/image’s center, call set_flip_y() after the set_origin() or translate()!

Note: Use this functions instead of the reflect()/flip()/mirror(),if you only want to draw on an ordinary coordinate system with y-axis grows bottom-up.

Parameters:
  • flip_y – True to turn on the flip, False to turn off.
  • image – the target image to be flipped. None means it is the target image (see set_target() and get_target()).
easygraphics.reflect(x: float, y: float, x1: float = 0, y1: float = 0, image: easygraphics.image.Image = None)

Reflect the coordinates against the line passing (x1,y1) and (x,y).

Note that all things will get reflected, including text! If you just want to draw on a normal coordinate system with the y-axis grows bottom up, use set_flip_y().

Parameters:
  • x – x coordinate value
  • y – y coordinate value
  • x1 – the x coordinate of the second point
  • y1 – the y coordinate of the second point
  • image – the target image to be reflected. None means it is the target image (see set_target() and get_target()).
easygraphics.flip(x: float, y: float, x1: float = 0, y1: float = 0, image: easygraphics.image.Image = None)

Reflect the coordinates against the line passing (x1,y1) and (x,y).

Note that all things will get reflected, including text! If you just want to draw on a normal coordinate system with the y-axis grows bottom up, use set_flip_y().

Parameters:
  • x – x coordinate value
  • y – y coordinate value
  • x1 – the x coordinate of the second point
  • y1 – the y coordinate of the second point
  • image – the target image to be reflected. None means it is the target image (see set_target() and get_target()).
easygraphics.mirror(x: float, y: float, x1: float = 0, y1: float = 0, image: easygraphics.image.Image = None)

Reflect the coordinates against the line passing (x1,y1) and (x,y).

Note that all things will get reflected, including text! If you just want to draw on a normal coordinate system with the y-axis grows bottom up, use set_flip_y().

Parameters:
  • x – x coordinate value
  • y – y coordinate value
  • x1 – the x coordinate of the second point
  • y1 – the y coordinate of the second point
  • image – the target image to be reflected. None means it is the target image (see set_target() and get_target()).
easygraphics.reset_transform(image: easygraphics.image.Image = None)

Reset all transforms (translate/rotate/scale).

Parameters:image – the target image to be reset. None means it is the target image (see set_target() and get_target()).
easygraphics.save_settings(image: easygraphics.image.Image = None)

Save current drawing settings.

See restore_settings().

Note: background_color and current position won’t be saved and restored.

Parameters:image – the target image whose drawing settings is to be saved. None means it is the target image (see set_target() and get_target()).
easygraphics.restore_settings(image: easygraphics.image.Image = None)

Restore previously saved drawing settings.

See save_settings().

Note: background_color and current position won’t be saved and restored.

Parameters:image – the target image whose drawing settings is to be restored. None means it is the target image (see set_target() and get_target()).
easygraphics.get_width(image: easygraphics.image.Image = None) → int

Get width of the specified image.

Parameters:image – the target image whose width is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:width of the specified image
easygraphics.get_height(image: easygraphics.image.Image = None) → int

Get height of the specified image.

Parameters:image – the target image whose width is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:height of the specified image
easygraphics.get_write_mode(image: easygraphics.image.Image = None) → int

Get composition mode of the specified image.

When drawing ,the composition mode will decide how the result pixel color will be computed (using source color and color of the destination)

Parameters:image – the target image whose composition mode is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:composition mode
easygraphics.set_write_mode(mode, image: easygraphics.image.Image = None)

Set composition mode of the specified image.

Composition modes are used to specify how the pixels in the source (image/pen/brush), are merged with the pixel in the destination image.

Parameters:
  • mode – composition mode
  • image – the target image whose composition mode is to be set. None means it is the target image (see set_target() and get_target()).
easygraphics.get_transform(image: easygraphics.image.Image = None) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>

Get transform matrix of the image.

Parameters:image – the target image whose transform matrix is to be gotten. None means it is the target image (see set_target() and get_target()).
Returns:the transform matrix
easygraphics.set_transform(transform: <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>, image: easygraphics.image.Image = None)

Set image’s transform matrix.

Parameters:
  • transform – the transform matrix to set
  • image – the target image whose transform matrix is to be gotten. None means it is the target image (see set_target() and get_target()).
easygraphics.push_transform(image: easygraphics.image.Image = None)

Push (save) the current transform to the transform stack.

easygraphics.pop_transform(image: easygraphics.image.Image = None)

Pop the last saved transform from the transform stack, and use it as the current transform.

easygraphics.set_rect_mode(mode, image: easygraphics.image.Image = None)
easygraphics.get_rect_mode(image: easygraphics.image.Image = None) → int
easygraphics.set_ellipse_mode(mode, image: easygraphics.image.Image = None)
easygraphics.get_ellipse_mode(image: easygraphics.image.Image = None) → int
easygraphics.set_antialiasing(anti: bool = True, image: easygraphics.image.Image = None) → None

Set Anti Aliasing

Parameters:
  • anti – if antialiasing should be set
  • image – the image to set anti aliasing. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_point(x: float, y: float, image: easygraphics.image.Image = None)

Draw a point at (x,y) on the specified image.

Parameters:
  • x – x coordinate value of the drawing point
  • y – y coordinate value of the drawing point
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.put_pixel(x: int, y: int, color, image: easygraphics.image.Image = None)

Set a pixel’s color on the specified image.

Parameters:
  • x – x coordinate value of the pixel
  • y – y coordinate value of the pixel
  • color – the color
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.get_pixel(x: int, y: int, image: easygraphics.image.Image = None) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>

Get a pixel’s color on the specified image.

Parameters:
  • x – x coordinate value of the pixel
  • y – y coordinate value of the pixel
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
Returns:

color of the pixel

easygraphics.line(x1, y1, x2, y2, image: easygraphics.image.Image = None)

Draw a line from (x1,y1) to (x2,y2) on the specified image.

It’s the same with line().

Parameters:
  • x1 – x coordinate value of the start point
  • y1 – y coordinate value of the start point
  • x2 – x coordinate value of the end point
  • y2 – y coordinate value of the start point
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_line(x1, y1, x2, y2, image: easygraphics.image.Image = None)

Draw a line from (x1,y1) to (x2,y2) on the specified image.

It’s the same with line().

Parameters:
  • x1 – x coordinate value of the start point
  • y1 – y coordinate value of the start point
  • x2 – x coordinate value of the end point
  • y2 – y coordinate value of the start point
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.move_to(x: float, y: float, image: easygraphics.image.Image = None)

Set the drawing position to (x,y).

The drawing position is used by line_to(), line_rel() and move_rel().

Parameters:
  • x – x coordinate value of the new drawing position
  • y – y coordinate value of the new drawing position
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.move_rel(dx: float, dy: float, image: easygraphics.image.Image = None)

Move the drawing position by (dx,dy).

If the old position is (x,y), then the new position will be (x+dx,y+dy).

The drawing position is used by line_to(), line_rel().

Parameters:
  • dx – x coordinate offset of the new drawing position
  • dy – y coordinate offset of the new drawing position
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.line_to(x: float, y: float, image: easygraphics.image.Image = None)

Draw a line from the current drawing position to (x,y), then set the drawing position is set to (x,y).

Parameters:
  • x – x coordinate value of the new drawing position
  • y – y coordinate value of the new drawing position
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.line_rel(dx: float, dy: float, image: easygraphics.image.Image = None)

Draw a line from the current drawing position (x,y) to (x+dx,y+dy), then set the drawing position is set to (x+dx,y+dy).

Parameters:
  • dx – x coordinate offset of the new drawing position
  • dy – y coordinate offset of the new drawing position
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.circle(x: float, y: float, r: float, image: easygraphics.image.Image = None)

Draw a circle outline centered at (x,y) with radius r.

The circle is not filled.

Parameters:
  • x – x coordinate value of the circle’s center
  • y – y coordinate value of the circle’s center
  • r – radius of the circle
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_circle(x: float, y: float, r: float, image: easygraphics.image.Image = None)

Draw a circle centered at (x,y) with radius r.

The circle is filled and has outline.

Parameters:
  • x – x coordinate value of the circle’s center
  • y – y coordinate value of the circle’s center
  • r – radius of the circle
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.fill_circle(x: float, y: float, r: float, image: easygraphics.image.Image = None)

Fill a circle centered at (x,y) with radius r.

The circle doesn’t has outline.

Parameters:
  • x – x coordinate value of the circle’s center
  • y – y coordinate value of the circle’s center
  • r – radius of the circle
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.ellipse(x, y, radius_x, radius_y, image: easygraphics.image.Image = None)

Draw an ellipse outline centered at (x,y) , radius on x-axis is radius_x, radius on y-axis is radius_y.

The ellipse is not filled.

Parameters:
  • x – x coordinate value of the ellipse’s center
  • y – y coordinate value of the ellipse’s center
  • radius_x – radius on x-axis of the ellipse
  • radius_y – radius on y-axis of the ellipse
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_ellipse(x, y, radius_x, radius_y, image: easygraphics.image.Image = None)

Draw an ellipse centered at (x,y) , radius on x-axis is radius_x, radius on y-axis is radius_y.

The ellipse is filled and has outline.

Parameters:
  • x – x coordinate value of the ellipse’s center
  • y – y coordinate value of the ellipse’s center
  • radius_x – radius on x-axis of the ellipse
  • radius_y – radius on y-axis of the ellipse
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.fill_ellipse(x, y, radius_x, radius_y, image: easygraphics.image.Image = None)

Fill an ellipse centered at (x,y) , radius on x-axis is radius_x, radius on y-axis is radius_y.

The ellipse doesn’t has outline.

Parameters:
  • x – x coordinate value of the ellipse’s center
  • y – y coordinate value of the ellipse’s center
  • radius_x – radius on x-axis of the ellipse
  • radius_y – radius on y-axis of the ellipse
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.arc(x: float, y: float, start_angle: float, end_angle: float, radius_x: float, radius_y: float, image: easygraphics.image.Image = None)

Draw an elliptical arc from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x – x coordinate value of the ellipse’s center
  • y – y coordinate value of the ellipse’s center
  • start_angle – start angle of the arc
  • end_angle – end angle of the arc
  • radius_x – radius on x-axis of the ellipse
  • radius_y – radius on y-axis of the ellipse
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_arc(x: float, y: float, start_angle: float, end_angle: float, radius_x: float, radius_y: float, image: easygraphics.image.Image = None)

Draw an elliptical arc from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x – x coordinate value of the ellipse’s center
  • y – y coordinate value of the ellipse’s center
  • start_angle – start angle of the arc
  • end_angle – end angle of the arc
  • radius_x – radius on x-axis of the ellipse
  • radius_y – radius on y-axis of the ellipse
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.pie(x: float, y: float, start_angle: float, end_angle: float, radius_x: float, radius_y: float, image: easygraphics.image.Image = None)

Draw an elliptical pie outline from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

The pie is not filled.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x – x coordinate value of the ellipse’s center
  • y – y coordinate value of the ellipse’s center
  • start_angle – start angle of the pie
  • end_angle – end angle of the pie
  • radius_x – radius on x-axis of the ellipse
  • radius_y – radius on y-axis of the ellipse
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_pie(x: float, y: float, start_angle: float, end_angle: float, radius_x: float, radius_y: float, image: easygraphics.image.Image = None)

Draw an elliptical pie from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

The pie is filled and has outline.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x – x coordinate value of the ellipse’s center
  • y – y coordinate value of the ellipse’s center
  • start_angle – start angle of the pie
  • end_angle – end angle of the pie
  • radius_x – radius on x-axis of the ellipse
  • radius_y – radius on y-axis of the ellipse
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.fill_pie(x: float, y: float, start_angle: float, end_angle: float, radius_x: float, radius_y: float, image: easygraphics.image.Image = None)

Fill an elliptical pie from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

The pie doesn’t have outline.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x – x coordinate value of the ellipse’s center
  • y – y coordinate value of the ellipse’s center
  • start_angle – start angle of the pie
  • end_angle – end angle of the pie
  • radius_x – radius on x-axis of the ellipse
  • radius_y – radius on y-axis of the ellipse
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.chord(x: float, y: float, start_angle: float, end_angle: float, radius_x: float, radius_y: float, image: easygraphics.image.Image = None)

Draw an elliptical chord outline from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

The chord is not filled.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x – x coordinate value of the ellipse’s center
  • y – y coordinate value of the ellipse’s center
  • start_angle – start angle of the chord
  • end_angle – end angle of the chord
  • radius_x – radius on x-axis of the ellipse
  • radius_y – radius on y-axis of the ellipse
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_chord(x: float, y: float, start_angle: float, end_angle: float, radius_x: float, radius_y: float, image: easygraphics.image.Image = None)

Draw an elliptical chord outline from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

The chord is filled and has outline

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x – x coordinate value of the ellipse’s center
  • y – y coordinate value of the ellipse’s center
  • start_angle – start angle of the chord
  • end_angle – end angle of the chord
  • radius_x – radius on x-axis of the ellipse
  • radius_y – radius on y-axis of the ellipse
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.fill_chord(x: float, y: float, start_angle: float, end_angle: float, radius_x: float, radius_y: float, image: easygraphics.image.Image = None)

Draw an elliptical chord outline from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

The chord doesn’t have outline.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x – x coordinate value of the ellipse’s center
  • y – y coordinate value of the ellipse’s center
  • start_angle – start angle of the chord
  • end_angle – end angle of the chord
  • radius_x – radius on x-axis of the ellipse
  • radius_y – radius on y-axis of the ellipse
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.bezier(x0: float, y0: float, x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, image: easygraphics.image.Image = None)

Draw a cubic bezier curve.

points (x0,y0),(x1,y1),(x2,y2),(x3,y3) are the control points of the curve,

>>> from easygraphics import *
>>> init_graph(600,400)
>>> points=[300,50,200,50,200,200,100,200]
>>> draw_bezier(*points)
>>> pause()
>>> close_graph()
Parameters:
  • x0 – x coordinate of the first control point
  • y0 – y coordinate of the first control point
  • x1 – x coordinate of the second control point
  • y1 – y coordinate of the second control point
  • x2 – x coordinate of the third control point
  • y2 – y coordinate of the third control point
  • x3 – x coordinate of the fourth control point
  • y3 – y coordinate of the fourth control point
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_bezier(x0: float, y0: float, x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, image: easygraphics.image.Image = None)

Draw a cubic bezier curve.

points (x0,y0),(x1,y1),(x2,y2),(x3,y3) are the control points of the curve,

>>> from easygraphics import *
>>> init_graph(600,400)
>>> points=[300,50,200,50,200,200,100,200]
>>> draw_bezier(*points)
>>> pause()
>>> close_graph()
Parameters:
  • x0 – x coordinate of the first control point
  • y0 – y coordinate of the first control point
  • x1 – x coordinate of the second control point
  • y1 – y coordinate of the second control point
  • x2 – x coordinate of the third control point
  • y2 – y coordinate of the third control point
  • x3 – x coordinate of the fourth control point
  • y3 – y coordinate of the fourth control point
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.lines(*points, image: easygraphics.image.Image = None)

Draw lines.

“points” is a 2D point pair list. It should contain even number of points, and each 2 points make a point pair. And each point have 2 coordinate values(x,y). So if you have n point pairs, the points list should have 4*n values.

For examples , if points is [50,50,550,350, 50,150,550,450, 50,250,550,550], draw_lines() will draw 3 lines: (50,50) to (550,350), (50,150) to (550,450), (50,250) to (550,550)

>>> from easygraphics import *
>>> init_graph(600,600)
>>> draw_lines(50, 50, 550, 350, 50, 150, 550, 450, 50, 250, 550, 550)
>>> pause()
>>> close_graph()
Parameters:
  • points – point value list
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_lines(*points, image: easygraphics.image.Image = None)

Draw lines.

“points” is a 2D point pair list. It should contain even number of points, and each 2 points make a point pair. And each point have 2 coordinate values(x,y). So if you have n point pairs, the points list should have 4*n values.

For examples , if points is [50,50,550,350, 50,150,550,450, 50,250,550,550], draw_lines() will draw 3 lines: (50,50) to (550,350), (50,150) to (550,450), (50,250) to (550,550)

>>> from easygraphics import *
>>> init_graph(600,600)
>>> draw_lines(50, 50, 550, 350, 50, 150, 550, 450, 50, 250, 550, 550)
>>> pause()
>>> close_graph()
Parameters:
  • points – point value list
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.poly_line(*end_points, image: easygraphics.image.Image = None)

Draw a poly line.

“end_points” is a 2D points list. Each 2 values in the list make a point. A poly line will be drawn to connect adjacent end_points defined by the the list.

For examples , if “end_points” is [50,50,550,350, 50,150,550,450, 50,250,550,550], draw_poly_line() will draw 5 lines: (50,50) to (550,350), (550,350) to (50,150), (50,150) to (550,450), (550,540) to (50,250) and(50,250) to (550,550).

>>> from easygraphics import *
>>> init_graph(600,600)
>>> draw_poly_line(50,50,550,350,50,150,550,450,50,250,550,550)
>>> pause()
>>> close_graph()
Parameters:
  • end_points – point value list
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_poly_line(*end_points, image: easygraphics.image.Image = None)

Draw a poly line.

“end_points” is a 2D points list. Each 2 values in the list make a point. A poly line will be drawn to connect adjacent end_points defined by the the list.

For examples , if “end_points” is [50,50,550,350, 50,150,550,450, 50,250,550,550], draw_poly_line() will draw 5 lines: (50,50) to (550,350), (550,350) to (50,150), (50,150) to (550,450), (550,540) to (50,250) and(50,250) to (550,550).

>>> from easygraphics import *
>>> init_graph(600,600)
>>> draw_poly_line(50,50,550,350,50,150,550,450,50,250,550,550)
>>> pause()
>>> close_graph()
Parameters:
  • end_points – point value list
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.polygon(*vertices, image: easygraphics.image.Image = None)

Draw polygon outline.

“vertices” is a 2D point list. Each 2 values in the list make a point. A polygon will be drawn to connect adjacent points defined by the the list.

For examples , if “vertices” is [50,50,550,350, 50,150], polygon() will draw a triangle with vertices at (50,50) , (550,350) and (50,150).

The polygon is not filled.

>>> from easygraphics import *
>>> init_graph(600,600)
>>> set_color(Color.RED)
>>> polygon(50,50,550,350,50,150)
>>> pause()
>>> close_graph()
Parameters:
  • vertices – point value list
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_polygon(*vertices, image: easygraphics.image.Image = None)

Draw a polygon.

“vertices” is a 2D point list. Each 2 values in the list make a point. A polygon will be drawn to connect adjacent points defined by the the list.

For examples , if “vertices” is [50,50,550,350, 50,150], draw_polygon() will draw a triangle with vertices at (50,50) , (550,350) and (50,150)

The polygon is filled and has outline.

>>> from easygraphics import *
>>> init_graph(600,600)
>>> set_color(Color.RED)
>>> set_fill_color(Color.LIGHT_MAGENTA)
>>> draw_polygon(50,50,550,350,50,150)
>>> pause()
>>> close_graph()
Parameters:
  • vertices – point value list
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.fill_polygon(*vertices, image: easygraphics.image.Image = None)

Fill a polygon.

“vertices” is a 2D point list. Each 2 values in the list make a point. A polygon will be drawn to connect adjacent points defined by the the list.

For examples , if “vertices” is [50,50,550,350, 50,150], fill_polygon() will fill a triangle with vertices at (50,50) , (550,350) and (50,150).

The polygon doesn’t have outline.

>>> from easygraphics import *
>>> init_graph(600,600)
>>> set_fill_color(Color.LIGHT_MAGENTA)
>>> fill_polygon(50,50,550,350,50,150)
>>> pause()
>>> close_graph()
Parameters:
  • vertices – point value list
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.rect(left: float, top: float, right: float, bottom: float, image: easygraphics.image.Image = None)

Draws a rectangle outline with upper left corner at (left, top) and lower right corner at (right,bottom).

The rectangle is not filled.

Parameters:
  • left – x coordinate value of the upper left corner
  • top – y coordinate value of the upper left corner
  • right – x coordinate value of the lower right corner
  • bottom – y coordinate value of the lower right corner
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_rect(left: float, top: float, right: float, bottom: float, image: easygraphics.image.Image = None)

Draws a rectangle with upper left corner at (left, top) and lower right corner at (right,bottom).

The rectangle is filled and has outline.

Parameters:
  • left – x coordinate value of the upper left corner
  • top – y coordinate value of the upper left corner
  • right – x coordinate value of the lower right corner
  • bottom – y coordinate value of the lower right corner
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.fill_rect(left: float, top: float, right: float, bottom: float, image: easygraphics.image.Image = None)

Draws a rectangle with upper left corner at (left, top) and lower right corner at (right,bottom).

The rectangle doesn’t have outline.

Parameters:
  • left – x coordinate value of the upper left corner
  • top – y coordinate value of the upper left corner
  • right – x coordinate value of the lower right corner
  • bottom – y coordinate value of the lower right corner
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.rounded_rect(left: float, top: float, right: float, bottom: float, round_x: float, round_y: float, image: easygraphics.image.Image = None)

Draws a rounded rectangle outline with upper left corner at (left, top) , lower right corner at (right,bottom). Raidus on x-axis of the corner ellipse arc is round_x, radius on y-axis of the corner ellipse arc is round_y.

The rectangle is not filled.

Parameters:
  • left – x coordinate value of the upper left corner
  • top – y coordinate value of the upper left corner
  • right – x coordinate value of the lower right corner
  • bottom – y coordinate value of the lower right corner
  • round_x – raidus on x-axis of the corner ellipse arc
  • round_y – radius on y-axis of the corner ellipse arc
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_rounded_rect(left: float, top: float, right: float, bottom: float, round_x: float, round_y: float, image: easygraphics.image.Image = None)

Draws a rounded rectangle with upper left corner at (left, top) , lower right corner at (right,bottom). raidus on x-axis of the corner ellipse arc is round_x, radius on y-axis of the corner ellipse arc is round_y.

The rectangle is filled and has outline.

Parameters:
  • left – x coordinate value of the upper left corner
  • top – y coordinate value of the upper left corner
  • right – x coordinate value of the lower right corner
  • bottom – y coordinate value of the lower right corner
  • round_x – raidus on x-axis of the corner ellipse arc
  • round_y – radius on y-axis of the corner ellipse arc
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.fill_rounded_rect(left: float, top: float, right: float, bottom: float, round_x: float, round_y: float, image: easygraphics.image.Image = None)

Fill a rounded rectangle with upper left corner at (left, top) , lower right corner at (right,bottom). raidus on x-axis of the corner ellipse arc is round_x, radius on y-axis of the corner ellipse arc is round_y.

The rectangle doesn’t have outline.

Parameters:
  • left – x coordinate value of the upper left corner
  • top – y coordinate value of the upper left corner
  • right – x coordinate value of the lower right corner
  • bottom – y coordinate value of the lower right corner
  • round_x – raidus on x-axis of the corner ellipse arc
  • round_y – radius on y-axis of the corner ellipse arc
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.flood_fill(x: int, y: int, border_color, image: easygraphics.image.Image = None)

Flood fill the image starting from(x,y) and ending at borders with border_color.

The fill region border must be closed,or the whole image will be filled!

Parameters:
  • x – x coordinate value of the start point
  • y – y coordinate value of the start point
  • border_color – color of the fill region border
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_image(x: int, y: int, src_image: easygraphics.image.Image, width: int = 0, height: int = 0, src_x: int = 0, src_y: int = 0, src_width: int = -1, src_height: int = -1, with_background=True, composition_mode=None, dst_image: easygraphics.image.Image = None)

Copy part of the source image (src_image) to the destination image (dst_image).

(x, y) specifies the top-left point in the destination image that is to be drawn onto.

(width, height) specifies the size of drawing part on the destination image.The default is (0, 0).

(src_x, src_y) specifies the top-left point of the part in the source image that is to be drawn. The default is (0, 0).

(src_width, src_height) specifies the size of the part of the source image that is to be drawn. The default, (0, 0) (and negative) means all the way to the bottom-right of the image.

if with_background is False, the source image’s background will not be copied.

The final result will depend on the composition mode and the source image’s background. In the default mode (CompositionMode.SOURCE_OVER), the transparent background in the source will not overwrite the destination.

param x:x coordinate value of the upper left point on the destination image
param y:y coordinate value of the upper left point on the destination image
param src_image:
 the source image to be copied
param width:width of the drawing part on the destination image
param height:height of the drawing part on the destination image
param src_x:x coordinate value of the top-left point of of the part to be drawn
param src_y:y coordinate value of the top-left point of of the part to be drawn
param src_width:
 witdh of the top-left point of of the part to be drawn
param src_height:
 height of the top-left point of of the part to be drawn
param with_background:
 if the background should be copied.
param composition_mode:
 if is None, use dst image’s composition mode to copy.
param dst_image:
 the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.clear_device(image: easygraphics.image.Image = None)

Clear the image to show the background.

Parameters:image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.clear_view_port(image: easygraphics.image.Image = None)

clear view port to show the background.

Parameters:image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.quadratic(x0: float, y0: float, x1: float, y1: float, x2: float, y2: float, image: easygraphics.image.Image = None)

Draw a quadratic bezier curve.

points (x0,y0),(x1,y1),(x2,y2) are the control points of the curve,

Parameters:
  • x0 – x coordinate of the first control point
  • y0 – y coordinate of the first control point
  • x1 – x coordinate of the second control point
  • y1 – y coordinate of the second control point
  • x2 – x coordinate of the third control point
  • y2 – y coordinate of the third control point
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_quadratic(x0: float, y0: float, x1: float, y1: float, x2: float, y2: float, image: easygraphics.image.Image = None)

Draw a quadratic bezier curve.

points (x0,y0),(x1,y1),(x2,y2) are the control points of the curve,

Parameters:
  • x0 – x coordinate of the first control point
  • y0 – y coordinate of the first control point
  • x1 – x coordinate of the second control point
  • y1 – y coordinate of the second control point
  • x2 – x coordinate of the third control point
  • y2 – y coordinate of the third control point
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.fill_image(color, image: easygraphics.image.Image = None)

Fill the whole image with the specified color.

Parameters:
  • color – the fill color
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.clear(image: easygraphics.image.Image = None)

Clear the image to show the background.

Parameters:image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_curve(*points, image: easygraphics.image.Image = None)

Draw a Catmull-Rom spline.

Parameters:
  • points – control points
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.curve(*points, image: easygraphics.image.Image = None)

Draw a Catmull-Rom spline.

Parameters:
  • points – control points
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.begin_shape(type=0, image: easygraphics.image.Image = None)

Begin a shape definition

Parameters:
  • type – the type of the shape. See VertexType const for more information
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.end_shape(close=False, image: easygraphics.image.Image = None)

End a shape definition

Parameters:
  • close – if the shape should be closed. Only polylines can be closed.
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.vertex(x: float, y: float, image: easygraphics.image.Image = None)

Define a vertex.

Parameters:
  • x – x pos of the vertex
  • y – y pos of the vertex
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.bezier_vertex(x1: float, y1: float, x2: float, y2: float, x3: float, y3: float, image: easygraphics.image.Image = None)

Define a cubic Bezier curve. The first control point of the curve the vertex defined last time.

Parameters:
  • x1 – x pos of the second control point
  • y1 – y pos of the second control point
  • x2 – x pos of the third control point
  • y2 – y pos of the third control point
  • x3 – x pos of the fourth control point
  • y3 – y pos of the fourth control point
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.quadratic_vertex(x1: float, y1: float, x2: float, y2: float, image: easygraphics.image.Image = None)

Define a quadratic Bezier curve vertex. The first control point of the curve the vertex defined last time.

Parameters:
  • x1 – x pos of the second control point
  • y1 – y pos of the second control point
  • x2 – x pos of the third control point
  • y2 – y pos of the third control point
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.curve_vertex(x: float, y: float, image: easygraphics.image.Image = None)

Define a Catmull-Rom curve vertex.

Parameters:
  • x – x pos of the vertex
  • y – y pos of the vertex
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.bezier_point(p0: float, p1: float, p2: float, p3: float, t: float)

Calculate the position of a point with parameter t on the cubic bezier curve.

Note that the parameter t must >=0 and <=1 .

Parameters:
  • p0 – position of the first control point
  • p1 – position of the second control point
  • p2 – position of the third control point
  • p3 – position of the forth control point
  • t – the parameter t
Returns:

position of the point

easygraphics.bezier_tangent(p0: float, p1: float, p2: float, p3: float, t: float)

Calculate the tangent of the point with parameter t on the cubic bezier curve.

Note that the parameter t must >=0 and <=1 .

Parameters:
  • p0 – position of the first control point
  • p1 – position of the second control point
  • p2 – position of the third control point
  • p3 – position of the forth control point
  • t – the parameter t
Returns:

tangent of the point

easygraphics.curve_point(p0: float, p1: float, p2: float, p3: float, t: float)

Calculate the position of the point with parameter t on a Catmull-Rom spline.

Note that the parameter t must >=0 and <=1 .

Parameters:
  • p0 – position of the first control point
  • p1 – position of the second control point
  • p2 – position of the third control point
  • p3 – position of the forth control point
  • t – the parameter t
Returns:

position of the point

easygraphics.curve_tangent(p0: float, p1: float, p2: float, p3: float, t: float)

Calculate the tangent of the point with parameter t on a Catmull-Rom spline.

Note that the parameter t must >=0 and <=1 .

Parameters:
  • p0 – position of the first control point
  • p1 – position of the second control point
  • p2 – position of the third control point
  • p3 – position of the forth control point
  • t – the parameter t
Returns:

tangent of the point

easygraphics.draw_text(x, y, *args, sep=' ', image: easygraphics.image.Image = None)

Prints the given texts beginning at the given position (x,y).

Parameters:
  • x – x coordinate value of the start point
  • y – y coordinate value of the start point
  • args – things to be printed (like print())
  • sep – seperator used to join strings
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.draw_rect_text(x: int, y: int, width: int, height: int, *args, flags=<sphinx.ext.autodoc.importer._MockObject object>, sep: str = ' ', image: easygraphics.image.Image = None)

Print the given texts in the specified rectangle area.

Flags are defined as TextFlag const.

Parameters:
  • x – x coordinate of the output rectangle’s upper left corner
  • y – y coordinate of the output rectangle’s upper left corner
  • width – width of the output rectangle
  • height – height of the output rectangle
  • args – things to be printed (like print())
  • flags – align flags
  • sep – seperator used to join strings
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.text_width(text: str, image: easygraphics.image.Image = None) → int

Return width of the text.

Parameters:
  • text – the text
  • image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
Returns:

width of the text

easygraphics.text_height(image: easygraphics.image.Image = None) → int

Return height of the text (font height).

Parameters:image – the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
Returns:height of the text (font height)
easygraphics.set_target(image: easygraphics.image.Image = None)

Set the target image for drawing on.

Parameters:image – the target image which will be painted on. None means paint on the graphics window.
easygraphics.get_target() → Optional[easygraphics.image.Image]

Get the target image for drawing on.

Returns:the target image which will be painted on. None means paint on the graphics window.
easygraphics.create_image(width, height) → easygraphics.image.Image

Create a new image.

Parameters:
  • width – width of the new image
  • height – height of the new image
Returns:

the created image

easygraphics.create_image_from_ndarray(array) → easygraphics.image.Image

Convert a ndarray (opencv 3.0 image) to an Image object

easygraphics.save_image(filename: str, with_background=True, image: easygraphics.image.Image = None)

Save image to file.

Set with_background to False to get a transparent background image.

Note that JPEG format doesn’t support transparent. Use PNG format if you want a transparent background.

Parameters:
  • filename – path of the file
  • with_background – True to save the background together. False not
  • image – the target image which will be saved. None means it is the target image (see set_target() and get_target()).
easygraphics.close_image(image: easygraphics.image.Image)

Close and clean up the specified image.

Parameters:image – the image to be closed
easygraphics.load_image(filename: str) → easygraphics.image.Image

Load a image from the file.

Parameters:filename – the image file
Returns:the loaded image
easygraphics.put_image(x: int, y: int, src_image: easygraphics.image.Image, width: int = 0, height: int = 0, src_x: int = 0, src_y: int = 0, src_width: int = -1, src_height: int = -1, with_background=True, composition_mode=None, dst_image: easygraphics.image.Image = None)

Copy part of the source image (src_image) to the destination image (dst_image).

(x, y) specifies the top-left point in the destination image that is to be drawn onto.

(width, height) specifies the size of drawing part on the destination image.The default is (0, 0).

(src_x, src_y) specifies the top-left point of the part in the source image that is to be drawn. The default is (0, 0).

(src_width, src_height) specifies the size of the part of the source image that is to be drawn. The default, (0, 0) (and negative) means all the way to the bottom-right of the image.

if with_background is False, the source image’s background will not be copied.

The final result will depend on the composition mode and the source image’s background. In the default mode (CompositionMode.SOURCE_OVER), the transparent background in the source will not overwrite the destination.

param x:x coordinate value of the upper left point on the destination image
param y:y coordinate value of the upper left point on the destination image
param src_image:
 the source image to be copied
param width:width of the drawing part on the destination image
param height:height of the drawing part on the destination image
param src_x:x coordinate value of the top-left point of of the part to be drawn
param src_y:y coordinate value of the top-left point of of the part to be drawn
param src_width:
 witdh of the top-left point of of the part to be drawn
param src_height:
 height of the top-left point of of the part to be drawn
param with_background:
 if the background should be copied.
param composition_mode:
 if is None, use dst image’s composition mode to copy.
param dst_image:
 the target image which will be painted on. None means it is the target image (see set_target() and get_target()).
easygraphics.create_image_from_file(filename: str) → easygraphics.image.Image

Load a image from the file.

Parameters:filename – the image file
Returns:the loaded image
easygraphics.capture_screen(left: int, top: int, width: int, height: int, target_img: easygraphics.image.Image)

Capture specified region on the graphics windows to target image.

Parameters:
  • left – x coordinate of the capture region’s upper left corner
  • top – y coordinate of the capture region’s upper left corner
  • width – width of the capture region
  • height – height of the capture region
  • target_img – image to save the capture
easygraphics.get_image(left: int, top: int, width: int, height: int, target_img: easygraphics.image.Image)

Capture specified region on the graphics windows to target image.

Parameters:
  • left – x coordinate of the capture region’s upper left corner
  • top – y coordinate of the capture region’s upper left corner
  • width – width of the capture region
  • height – height of the capture region
  • target_img – image to save the capture
easygraphics.pause()

Pause the program and wait for mouse clicking or keyboard hitting.

>>> from easygraphics import *
>>> init_graph(800,600)
>>> pause()
>>> close_graph()
easygraphics.delay(milliseconds: int)

Delay the program for specified milliseconds.

Parameters:milliseconds – time to delay
easygraphics.delay_fps(fps: int)

Delay the program to control fps (Frame per seconds).

Valid fps value is 1-1000, this value is not checked for speed.

This function won’t skip frames.

Parameters:fps – the desire fps
Returns:False the graphics window is closed. True otherwise.
easygraphics.delay_jfps(fps, max_skip_count=0)

Delay to control fps with frame skipping.

If we don’t have enough time to delay, we’ll skip some frames.

Parameters:
  • fps – frames per second (max is 1000)
  • max_skip_count – max num of frames to skip (0 means no limit)
Returns:

True if this frame should not be skipped

easygraphics.is_run() → bool

Test if the graphics system is running.

Returns:True if the graphics system is running.
easygraphics.has_kb_msg() → bool

See if any key hit message in the message queue.

Use it with get_key().

Returns:True if hit, False otherwise
easygraphics.has_kb_hit() → bool

See if any ascii char key hit message in the message queue.

Use it with get_char().

Returns:True if hit, False otherwise
easygraphics.has_mouse_msg() → bool

See if there is any mouse message(event) in the message queue.

Use it with get_mouse_msg().

Returns:True if any mouse message, False otherwise
easygraphics.get_key() → easygraphics.graphwin.KeyMessage

Get the key inputted by keyboard.

If not any key is pressed in last 100 ms, the program will stop and wait for the next key hitting.

Returns:key message
easygraphics.get_char() → str

Get the ascii char inputted by keyboard.

If not any char key is pressed in last 100 ms, the program will stop and wait for the next key hitting.

Returns:the character inputted by keyboard
easygraphics.get_mouse_msg() → easygraphics.graphwin.MouseMessage

Get the mouse message.

If there is not any mouse message, the program will stop and wait for it.

Returns:mouse message
easygraphics.get_cursor_pos() -> (<class 'int'>, <class 'int'>)

Get position of the mouse cursor

Returns:position’s coordinate values (x,y)
easygraphics.get_click() → easygraphics.graphwin.MouseMessage

Get the mouse click message.

If there isn’t any clicked event, the program will stop and wait for it.

Returns:mouse message
easygraphics.contains_left_button(buttons) → bool

Test if the buttons contains the left mouse button.

The “buttons” should be values returned by get_click() or get_mouse()

Parameters:buttons – the buttons to be tested
Returns:if the buttons contains the left mouse button
easygraphics.contains_right_button(buttons) → bool

Test if the buttons contains the right mouse button.

The “buttons” should be values returned by get_click() or get_mouse()

Parameters:buttons – the buttons to be tested
Returns:if the buttons contains the right mouse button
easygraphics.contains_mid_button(buttons) → bool

Test if the buttons contains the middle mouse button.

The “buttons” should be values returned by get_click() or get_mouse()

Parameters:buttons – the buttons to be tested
Returns:if the buttons contains the middle mouse button
easygraphics.clear_key_msg()

Clear all keyboard hit messages.

easygraphics.clear_char_msg(self)

Clear all char key hit messages.

easygraphics.clear_mouse_msg(self)

Clear all mouse messages.

easygraphics.contains_alt(modifiers) → bool

Test if the modifiers contains the alt key

Parameters:modifiers – the modifiers to be tested
Returns:if the modifiers contains the alt key
easygraphics.contains_ctrl(modifiers) → bool

Test if the modifiers contains the control key

Parameters:modifiers – the modifiers to be tested
Returns:if the modifiers contains the control key
easygraphics.contains_meta(modifiers) → bool

Test if the modifiers contains the meta key

Parameters:modifiers – the modifiers to be tested
Returns:if the modifiers contains the meta key
easygraphics.contains_shift(modifiers) → bool

Test if the modifiers contains the shift key

Parameters:modifiers – the modifiers to be tested
Returns:if the modifiers contains the shift key
easygraphics.init_graph(width: int = 800, height: int = 600, headless: bool = False)

Init the easygraphics system and show the graphics window.

If “headless” is True, easygraphics will run in headless mode, which means there will be no graphics window. Use this mode if you want to draw and save image to files.

Parameters:
  • width – width of the graphics window (in pixels)
  • height – height of the graphics window (in pixels)
  • headless – True to run in headless mode.
>>> from easygraphics import *
>>> init_graph(800,600) #prepare and show a 800*600 window
easygraphics.close_graph()

Close the graphics windows.

The program will exit too.

>>> from easygraphics import *
>>> init_graph(800,600)
>>> pause()
>>> close_graph()
easygraphics.set_caption(title: str)

Set the graph window’s caption

Parameters:title – caption title
easygraphics.get_graphics_window() → easygraphics.graphwin.GraphWin

Get the graphics window.

Returns:the graphics window
easygraphics.show_image(image: easygraphics.image.Image = None)

Display the image in ipython console or notebook.

Parameters:image – the target image which will be displayed. None means it is the target image (see set_target() and get_target()).
easygraphics.begin_recording()

Start recording png animation

easygraphics.save_recording(filename: str)

Save the recording animation in PNG format.

Parameters:filename – the filename of the save file.
easygraphics.add_record(image: easygraphics.image.Image = None, **options)

Add one frame to the recording animation

Parameters:image – the target image whose content will be captured. None means it is the target image (see set_target() and get_target()).
easygraphics.end_recording()

End the recording of the animation.

easygraphics.color_gray(gray: int, alpha: int = 255) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>

Create a gray color.

Parameters:
  • gray – gray value
  • alpha – alpha channel value of the color. 255 means fully opaque
Returns:

the color

easygraphics.color_rgb(red: int, green: int, blue: int, alpha: int = 255) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>

Create a color with RGB color values r,g,b.

Parameters:
  • red – red value
  • green – green value
  • blue – blue value
  • alpha – alpha channel value of the color. 255 means fully opaque
Returns:

the color

easygraphics.color_cmyk(c: int, m: int, y: int, k: int, alpha: int = 255) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>

Create a color with CMYK color values c,m,y,k.

Parameters:
  • c – cyan value
  • m – magenta value
  • y – yellow value
  • k – black value
  • alpha – alpha channel value of the color. 255 means fully opaque
Returns:

the color

easygraphics.color_hsv(h: int, s: int, v: int, alpha: int = 255) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>

Create a color with HSV color values h,s,v.

Parameters:
  • h – hue value
  • s – saturation value
  • v – Value
  • alpha – alpha channel value of the color. 255 means fully opaque
Returns:

the color

easygraphics.color_hsl(h: int, s: int, l: int, alpha: int = 255) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>

Create a color with HSL color values h,s,l.

Parameters:
  • h – hue value
  • s – saturation value
  • l – lightness value
  • alpha – alpha channel value of the color. 255 means fully opaque
Returns:

the color

easygraphics.rgb(red: int, green: int, blue: int, alpha: int = 255) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>

Create a color with RGB color values r,g,b.

Parameters:
  • red – red value
  • green – green value
  • blue – blue value
  • alpha – alpha channel value of the color. 255 means fully opaque
Returns:

the color

easygraphics.to_alpha(new_color, alpha: int = None) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5352a5c390>

Get new color based on the given color and alpha.

Parameters:
  • new_color – the base color
  • alpha – new color’s alpha
Returns:

new color with base color and the given alpha value

easygraphics.pol2cart(rho, theta)

Transform a point from polar coordinates to cartesian coordinates.

Parameters:
  • rho – rho coordinate value of the point
  • theta – theta coordinate value of the point (in radians)
Returns:

x,y coordinate value of the point

easygraphics.cart2pol(x, y)

Transform a point from cartesian coordinates to polar coordinates.

Parameters:
  • x – x coordinate value of the point
  • y – y coordinate value of the point
Returns:

rho (distance from the pole (origin) to the point), theta (the angle between the polar-axis and the line connecting the pole and the point, in radians)

easygraphics.ortho_look_at(eye_x: float, eye_y: float, eye_z: float, center_x: float, center_y: float, center_z: float, up_x: float, up_y: float, up_z: float) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5351cdf3c8>

Return the ortho projection matrix

Parameters:
  • eye_x
  • eye_y
  • eye_z
  • center_x
  • center_y
  • center_z
  • up_x
  • up_y
  • up_z
Returns:

the matrix

easygraphics.isometric_projection() → <sphinx.ext.autodoc.importer._MockObject object at 0x7f5351cdf3c8>

Return the isometric perspective projection matrix :return:

easygraphics.cart2sphere(x: float, y: float, z: float) -> (<class 'float'>, <class 'float'>, <class 'float'>)

Convert cartesian coordinate to spherical coordinate

Parameters:
  • x – x
  • y – y
  • z – z
Returns:

radius,θ,φ

easygraphics.sphere2cart(r: float, theta: float, phi: float) -> (<class 'float'>, <class 'float'>, <class 'float'>)

Convert spherical coordinate to cartesian coordinate

Parameters:
  • r – radius
  • theta – θ
  • phi – φ
Returns:

x,y,z

class easygraphics.Image(image: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>)

The image class.

Use PyQt’s QImage to save the drawing, and QPainter as the underlying drawing device.

Note that the painter is keep and reused, if you want to draw on the image by yourself, please use get_painter() to get the painter and draw.And also note there is a mask image for background processing. You should get the mask right or you will get wrong result with set_background_color() and draw_image(with_background=False).

add_updated_listener(listener: Callable[[], None])

Add a listener for updated event.

Parameters:listener – the listener to add
arc(x1: float, y1: float, start_angle: float, end_angle: float, x2: float, y2: float)

Draw an elliptical arc from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x1 – x coordinate value of the ellipse’s center
  • y1 – y coordinate value of the ellipse’s center
  • start_angle – start angle of the arc
  • end_angle – end angle of the arc
  • x2 – radius on x-axis of the ellipse
  • y2 – radius on y-axis of the ellipse
begin_shape(type=0)

Begin a shape definition

Parameters:type – the type of the shape. See VertexType const for more information
bezier(x0: float, y0: float, x1: float, y1: float, x2: float, y2: float, x3: float, y3: float)

Draw a cubic bezier curve.

points (x0,y0),(x1,y1),(x2,y2),(x3,y3) are the control points of the curve,

Parameters:
  • x0 – x coordinate of the first control point
  • y0 – y coordinate of the first control point
  • x1 – x coordinate of the second control point
  • y1 – y coordinate of the second control point
  • x2 – x coordinate of the third control point
  • y2 – y coordinate of the third control point
  • x3 – x coordinate of the fourth control point
  • y3 – y coordinate of the fourth control point
bezier_vertex(x1, y1, x2, y2, x3, y3)

Define a cubic Bezier curve. The first control point of the curve the vertex defined last time.

Parameters:
  • x1 – x pos of the second control point
  • y1 – y pos of the second control point
  • x2 – x pos of the third control point
  • y2 – y pos of the third control point
  • x3 – x pos of the fourth control point
  • y3 – y pos of the fourth control point
chord(x1: float, y1: float, start_angle: float, end_angle: float, x2: float, y2: float)

Draw an elliptical chord outline from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

The chord is not filled.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x1 – x coordinate value of the ellipse’s center
  • y1 – y coordinate value of the ellipse’s center
  • start_angle – start angle of the chord
  • end_angle – end angle of the chord
  • x2 – radius on x-axis of the ellipse
  • y2 – radius on y-axis of the ellipse
clear()

Clear the image to show the background.

clear_view_port()

Clear view port to show the background.

close()

Close and clean up the specified image.

Parameters:image – the image to be closed
copy(x: int, y: int, width: int, height: int) → easygraphics.image.Image

Create an copy of the image.

Parameters:
  • x – left-top of the copied area
  • y – left-top of the copied area
  • width – width of the copy area
  • height – height of the copy area
Returns:

new copy

static create(width: int, height: int) → easygraphics.image.Image

Create a new image.

Parameters:
  • width – width of the new image
  • height – height of the new image
Returns:

the created image

static create_from_file(filename: str) → easygraphics.image.Image

Load a image from the file.

Parameters:filename – the image file
Returns:the loaded image
curve(*points)

Draw a Catmull-Rom spline.

Parameters:points – control points
curve_vertex(x: float, y: float)

Define a Catmull-Rom curve vertex.

Parameters:
  • x – x pos of the vertex
  • y – y pos of the vertex
draw_arc(x1: float, y1: float, start_angle: float, end_angle: float, x2: float, y2: float)

Draw an elliptical arc from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x1 – x coordinate value of the ellipse’s center
  • y1 – y coordinate value of the ellipse’s center
  • start_angle – start angle of the arc
  • end_angle – end angle of the arc
  • x2 – radius on x-axis of the ellipse
  • y2 – radius on y-axis of the ellipse
draw_bezier(x0: float, y0: float, x1: float, y1: float, x2: float, y2: float, x3: float, y3: float)

Draw a cubic bezier curve.

points (x0,y0),(x1,y1),(x2,y2),(x3,y3) are the control points of the curve,

Parameters:
  • x0 – x coordinate of the first control point
  • y0 – y coordinate of the first control point
  • x1 – x coordinate of the second control point
  • y1 – y coordinate of the second control point
  • x2 – x coordinate of the third control point
  • y2 – y coordinate of the third control point
  • x3 – x coordinate of the fourth control point
  • y3 – y coordinate of the fourth control point
draw_chord(x1: float, y1: float, start_angle: float, end_angle: float, x2: float, y2: float)

Draw an elliptical chord outline from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

The chord is filled and has outline

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x1 – x coordinate value of the ellipse’s center
  • y1 – y coordinate value of the ellipse’s center
  • start_angle – start angle of the chord
  • end_angle – end angle of the chord
  • x2 – radius on x-axis of the ellipse
  • y2 – radius on y-axis of the ellipse
draw_curve(*points)

Draw a Catmull-Rom spline.

Parameters:points – control points
draw_ellipse(x1: float, y1: float, x2: float, y2: float)

Draw an ellipse centered at (x,y) , radius on x-axis is radius_x, radius on y-axis is radius_y.

The ellipse is filled and has outline.

Parameters:
  • x1 – x coordinate value of the ellipse’s center
  • y1 – y coordinate value of the ellipse’s center
  • x2 – radius on x-axis of the ellipse
  • y2 – radius on y-axis of the ellipse
draw_image(x: int, y: int, image: easygraphics.image.Image, width: int = 0, height: int = 0, src_x: int = 0, src_y: int = 0, src_width: int = 0, src_height: int = 0, with_background=True, composition_mode=None)

Copy part of the source image (src_image) to the destination image (dst_image).

(x, y) specifies the top-left point in the destination image that is to be drawn onto.

(width, height) specifies the size of drawing part on the destination image.The default is (0, 0).

(src_x, src_y) specifies the top-left point of the part in the source image that is to be drawn. The default is (0, 0).

(src_width, src_height) specifies the size of the part of the source image that is to be drawn. The default, (0, 0) (and negative) means all the way to the bottom-right of the image.

if with_background is False, the source image’s background will not be copied.

The final result will depend on the composition mode and the source image’s background. In the default mode (CompositionMode.SOURCE_OVER), the transparent background in the source will not overwrite the destination.

Parameters:
  • x – x coordinate value of the upper left point on the destination image
  • y – y coordinate value of the upper left point on the destination image
  • image – the source image to be copied
  • width – width of the drawing part on the destination image
  • height – height of the drawing part on the destination image
  • src_x – x coordinate value of the top-left point of of the part to be drawn
  • src_y – y coordinate value of the top-left point of of the part to be drawn
  • src_width – witdh of the top-left point of of the part to be drawn
  • src_height – height of the top-left point of of the part to be drawn
  • with_background – if the background should be copied.
  • composition_mode – if is None, use dst image’s composition mode to copy.
draw_line(x1: float, y1: float, x2: float, y2: float)

Draw a line from (x1,y1) to (x2,y2) on the specified image.

Parameters:
  • x1 – x coordinate value of the start point
  • y1 – y coordinate value of the start point
  • x2 – x coordinate value of the end point
  • y2 – y coordinate value of the start point
draw_lines(*points)

Draw lines.

“points” is a 2D point pair list. It should contain even number of points, and each 2 points make a point pair. And each point have 2 coordinate values(x,y). So if you have n point pairs, the points list should have 4*n values.

For examples , if points is [50,50,550,350, 50,150,550,450, 50,250,550,550], draw_lines() will draw 3 lines: (50,50) to (550,350), (50,150) to (550,450), (50,250) to (550,550)

Parameters:points – point value list
draw_path(path: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>)

Draw and fill a path.

Parameters:path – path to drawn and fill
draw_pie(x1: float, y1: float, start_angle: float, end_angle: float, x2: float, y2: float)

Draw an elliptical pie from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

The pie is filled and has outline.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x1 – x coordinate value of the ellipse’s center
  • y1 – y coordinate value of the ellipse’s center
  • start_angle – start angle of the pie
  • end_angle – end angle of the pie
  • x2 – radius on x-axis of the ellipse
  • y2 – radius on y-axis of the ellipse
draw_point(x: float, y: float)

Draw a point at (x,y) on the specified image.

Parameters:
  • x – x coordinate value of the drawing point
  • y – y coordinate value of the drawing point
draw_poly_line(*end_points)

Draw a poly line.

“end_points” is a 2D points list. Each 2 values in the list make a point. A poly line will be drawn to connect adjacent end_points defined by the the list.

For examples , if “end_points” is [50,50,550,350, 50,150,550,450, 50,250,550,550], draw_poly_line() will draw 5 lines: (50,50) to (550,350), (550,350) to (50,150), (50,150) to (550,450), (550,540) to (50,250) and(50,250) to (550,550).

Parameters:end_points – point value list
draw_polygon(*vertices)

Draw a polygon.

“vertices” is a 2D point list. Each 2 values in the list make a point. A polygon will be drawn to connect adjacent points defined by the the list.

For examples , if “vertices” is [50,50,550,350, 50,150], draw_polygon() will draw a triangle with vertices at (50,50) , (550,350) and (50,150)

The polygon is filled and has outline.

Parameters:vertices – point value list
draw_quadratic(x0, y0, x1, y1, x2, y2)

Draw a quadratic bezier curve.

points (x0,y0),(x1,y1),(x2,y2) are the control points of the curve,

Parameters:
  • x0 – x coordinate of the first control point
  • y0 – y coordinate of the first control point
  • x1 – x coordinate of the second control point
  • y1 – y coordinate of the second control point
  • x2 – x coordinate of the third control point
  • y2 – y coordinate of the third control point
draw_rect(x1: float, y1: float, x2: float, y2: float)

Draws a rectangle with upper left corner at (left, top) and lower right corner at (right,bottom).

The rectangle is filled and has outline.

Parameters:
  • x1 – x coordinate value of the upper left corner
  • y1 – y coordinate value of the upper left corner
  • x2 – x coordinate value of the lower right corner
  • y2 – y coordinate value of the lower right corner
draw_rect_text(x: int, y: int, width: int, height: int, flags=<sphinx.ext.autodoc.importer._MockObject object>, *args, sep=' ')

Print the given texts in the specified rectangle area.

Flags are defined as TextFlag const.

Parameters:
  • x – x coordinate of the output rectangle’s upper left corner
  • y – y coordinate of the output rectangle’s upper left corner
  • width – width of the output rectangle
  • height – height of the output rectangle
  • args – things to be printed (like print())
  • flags – align flags
  • sep – seperator used to join strings
draw_rounded_rect(x1: float, y1: float, x2: float, y2: float, round_x: float, round_y: float)

Draws a rounded rectangle with upper left corner at (left, top) , lower right corner at (right,bottom). raidus on x-axis of the corner ellipse arc is round_x, radius on y-axis of the corner ellipse arc is round_y.

The rectangle is filled and has outline.

Parameters:
  • x1 – x coordinate value of the upper left corner
  • y1 – y coordinate value of the upper left corner
  • x2 – x coordinate value of the lower right corner
  • y2 – y coordinate value of the lower right corner
  • round_x – raidus on x-axis of the corner ellipse arc
  • round_y – radius on y-axis of the corner ellipse arc
draw_text(x: int, y: int, *args, sep=' ')

Prints the given texts beginning at the given position (x,y).

Parameters:
  • x – x coordinate value of the start point
  • y – y coordinate value of the start point
  • args – things to be printed
  • sep – seperator used to join strings
draw_to_device(device: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>)

Draw the whole image to the specified device.

Parameters:device – the device to be drawn on
ellipse(x1: float, y1: float, x2: float, y2: float)

Draw an ellipse outline centered at (x,y) , radius on x-axis is radius_x, radius on y-axis is radius_y.

The ellipse is not filled.

Parameters:
  • x1 – x coordinate value of the ellipse’s center
  • y1 – y coordinate value of the ellipse’s center
  • x2 – radius on x-axis of the ellipse
  • y2 – radius on y-axis of the ellipse
end_shape(close=False)

End a shape definition

Parameters:close – if the shape should be closed. Only polylines can be closed.
fill_chord(x1: float, y1: float, start_angle: float, end_angle: float, x2: float, y2: float)

Draw an elliptical chord outline from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

The chord doesn’t have outline.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x1 – x coordinate value of the ellipse’s center
  • y1 – y coordinate value of the ellipse’s center
  • start_angle – start angle of the chord
  • end_angle – end angle of the chord
  • x2 – radius on x-axis of the ellipse
  • y2 – radius on y-axis of the ellipse
fill_ellipse(x1: float, y1: float, x2: float, y2: float)

Fill an ellipse centered at (x,y) , radius on x-axis is radius_x, radius on y-axis is radius_y.

The ellipse dosen’t has outline.

Parameters:
  • x1 – x coordinate value of the ellipse’s center
  • y1 – y coordinate value of the ellipse’s center
  • x2 – radius on x-axis of the ellipse
  • y2 – radius on y-axis of the ellipse
fill_image(color)

Fill the whole image with the specified color.

Parameters:color – the fill color
fill_path(path: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>)

Fill the region enclosed by the path

Parameters:path – the path enclosing the region
fill_pie(x1: float, y1: float, start_angle: float, end_angle: float, x2: float, y2: float)

Fill an elliptical pie from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

The pie doesn’t have outline.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x1 – x coordinate value of the ellipse’s center
  • y1 – y coordinate value of the ellipse’s center
  • start_angle – start angle of the pie
  • end_angle – end angle of the pie
  • x2 – radius on x-axis of the ellipse
  • y2 – radius on y-axis of the ellipse
fill_polygon(*vertices)

Fill a polygon.

“vertices” is a 2D point list. Each 2 values in the list make a point. A polygon will be drawn to connect adjacent points defined by the the list.

For examples , if “vertices” is [50,50,550,350, 50,150], fill_polygon() will fill a triangle with vertices at (50,50) , (550,350) and (50,150).

The polygon doesn’t have outline.

Parameters:vertices – point value list
fill_rect(x1: float, y1: float, x2: float, y2: float)

Draws a rectangle with upper left corner at (left, top) and lower right corner at (right,bottom).

The rectangle doesn’t have outline.

Parameters:
  • x1 – x coordinate value of the upper left corner
  • y1 – y coordinate value of the upper left corner
  • x2 – x coordinate value of the lower right corner
  • y2 – y coordinate value of the lower right corner
fill_rounded_rect(x1: float, y1: float, x2: float, y2: float, round_x: float, round_y: float)

Fill a rounded rectangle with upper left corner at (left, top) , lower right corner at (right,bottom). raidus on x-axis of the corner ellipse arc is round_x, radius on y-axis of the corner ellipse arc is round_y.

The rectangle doesn’t have outline.

Parameters:
  • x1 – x coordinate value of the upper left corner
  • y1 – y coordinate value of the upper left corner
  • x2 – x coordinate value of the lower right corner
  • y2 – y coordinate value of the lower right corner
  • round_x – radius on x-axis of the corner ellipse arc
  • round_y – radius on y-axis of the corner ellipse arc
flip(x: float, y: float, x1: float = 0, y1: float = 0)

Reflect the coordinates against the line passing (x1,y1) and (x,y).

Note that all things will get reflected, including text! If you just want to draw on a normal coordinate system with the y-axis grows bottom up, use set_flip_y()..

Parameters:
  • x – x coordinate value of the first point
  • y – y coordinate value of the first point
  • x1 – the x coordinate of the second point
  • y1 – the y coordinate of the second point
flood_fill(x: int, y: int, border_color)

Flood fill the image starting from(x,y) and ending at borders with border_color.

The fill region border must be closed,or the whole image will be filled!

Parameters:
  • x – x coordinate value of the start point
  • y – y coordinate value of the start point
  • border_color – color of the fill region border
get_background_color()

Get the background color of the image.

Returns:background color
get_brush() → <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>

Get brush of the image

Returns:the brush
get_color()

Get the foreground (drawing) color of the specified image.

It will be used when drawing lines or shape outlines.

Returns:foreground color
get_composition_mode()

Get composition mode of the specified image.

When drawing ,the composition mode will decide how the result pixel color will be computed
(using source color and color of the destination).
Returns:composition mode
get_ellipse_mode()
get_fill_color()

Get the fill color of the specified image.

It will be used when drawing and fill shapes.

Returns:fill color
get_fill_rule()

Get the fill rule (algorithm) for filling polygons.

Returns:the rule used for filling polygons
get_fill_style()

Get fill style of the specified image.

It will be used when drawing and fill shapes.

Returns:fill style
get_font() → <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>

Get font of the specified image.

Returns:the font used by the specified image
get_font_size() → int

Get font size of the specified image.

Returns:font size of the specified image
get_height()

Get the height of the image.

Returns:image height
get_image() → <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>

Get the internal QImage.

note EasyGraphics don’t require and release qpainter each time. Because there can only be one QPainter for each QImage at time, so if you want to draw on this image customly, use get_painter() to get the internal QPainter instance.

Returns:the QImage instance used internally
get_line_style()

Get line style.

The line style will be used when drawing lines and shape outlines.

Returns:line style
get_line_width() → float

Get line width (thickness).

It will be used when drawing lines or shape outlines.

Returns:line width
get_mask() → <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>

Get background mask image.

Returns:background mask
get_mask_painter() → <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>

Get the QPainter instance for drawing the mask.

Returns:the mask painter used internally
get_painter() → <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>

Get the QPainter instance for drawing the image.

Returns:the painter used internally
get_pen() → <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>

Get the pen of the image

Returns:pen
get_pixel(x: int, y: int) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>

Get a pixel’s color on the specified image.

Parameters:
  • x – x coordinate value of the pixel
  • y – y coordinate value of the pixel
Returns:

color of the pixel

get_rect_mode()
get_transform() → <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>

Get transform matrix of the image.

Returns:the transform matrix
get_width() → int

Get the width of the image.

Returns:image width
get_x() → float

Get the x coordinate value of the current drawing position (x,y).

Some drawing functions will use the current pos to draw.(see line_to(),line_rel(),move_to(),move_rel()).

Returns:the x coordinate value of the current drawing position
get_y() → float

Get the y coordinate value of the current drawing position (x,y).

Some drawing functions will use the current pos to draw.(see line_to(),line_rel(),move_to(),move_rel())

Returns:the y coordinate value of the current drawing position
line(x1: float, y1: float, x2: float, y2: float)

Draw a line from (x1,y1) to (x2,y2) on the specified image.

Parameters:
  • x1 – x coordinate value of the start point
  • y1 – y coordinate value of the start point
  • x2 – x coordinate value of the end point
  • y2 – y coordinate value of the start point
line_rel(dx: float, dy: float)

Draw a line from the current drawing position (x,y) to (x+dx,y+dy), then set the drawing position is set to (x+dx,y+dy).

Parameters:
  • dx – x coordinate offset of the new drawing position
  • dy – y coordinate offset of the new drawing position
line_to(x: float, y: float)

Draw a line from the current drawing position to (x,y), then set the drawing position is set to (x,y).

Parameters:
  • x – x coordinate value of the new drawing position
  • y – y coordinate value of the new drawing position
lines(*points)

Draw lines.

“points” is a 2D point pair list. It should contain even number of points, and each 2 points make a point pair. And each point have 2 coordinate values(x,y). So if you have n point pairs, the points list should have 4*n values.

For examples , if points is [50,50,550,350, 50,150,550,450, 50,250,550,550], draw_lines() will draw 3 lines: (50,50) to (550,350), (50,150) to (550,450), (50,250) to (550,550)

Parameters:points – point value list
mirror(x: float, y: float, x1: float = 0, y1: float = 0)

Reflect the coordinates against the line passing (x1,y1) and (x,y).

Note that all things will get reflected, including text! If you just want to draw on a normal coordinate system with the y-axis grows bottom up, use set_flip_y()..

Parameters:
  • x – x coordinate value of the first point
  • y – y coordinate value of the first point
  • x1 – the x coordinate of the second point
  • y1 – the y coordinate of the second point
move_rel(dx: float, dy: float)

Move the drawing position by (dx,dy).

If the old position is (x,y), then the new position will be (x+dx,y+dy).

The drawing position is used by line_to(), line_rel().

Parameters:
  • dx – x coordinate offset of the new drawing position
  • dy – y coordinate offset of the new drawing position
move_to(x, y)

Set the drawing position to (x,y).

The drawing position is used by line_to(), line_rel() and move_rel().

Parameters:
  • x – x coordinate value of the new drawing position
  • y – y coordinate value of the new drawing position
path(path: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>)

Draw a path.

Parameters:path – path to be drawn
pie(x1: float, y1: float, start_angle: float, end_angle: float, x2: float, y2: float)

Draw an elliptical pie outline from start_angle to end_angle. The base ellipse is centered at (x,y) which radius on x-axis is radius_x and radius on y-axis is radius_y.

The pie is not filled.

Note: Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o’clock position.
Parameters:
  • x1 – x coordinate value of the ellipse’s center
  • y1 – y coordinate value of the ellipse’s center
  • start_angle – start angle of the pie
  • end_angle – end angle of the pie
  • x2 – radius on x-axis of the ellipse
  • y2 – radius on y-axis of the ellipse
poly_line(*end_points)

Draw a poly line.

“end_points” is a 2D points list. Each 2 values in the list make a point. A poly line will be drawn to connect adjacent end_points defined by the the list.

For examples , if “end_points” is [50,50,550,350, 50,150,550,450, 50,250,550,550], draw_poly_line() will draw 5 lines: (50,50) to (550,350), (550,350) to (50,150), (50,150) to (550,450), (550,540) to (50,250) and(50,250) to (550,550).

Parameters:end_points – point value list
polygon(*vertices)

Draw polygon outline.

“vertices” is a 2D point list. Each 2 values in the list make a point. A polygon will be drawn to connect adjacent points defined by the the list.

For examples , if “vertices” is [50,50,550,350, 50,150], polygon() will draw a triangle with vertices at (50,50) , (550,350) and (50,150).

The polygon is not filled.

Parameters:vertices – point value list
pop_transform()

Pop the last saved transform from the transform stack, and use it as the current transform.

push_transform()

Push (save) the current transform to the transform stack.

put_pixel(x: int, y: int, color)

Set a pixel’s color on the specified image.

Parameters:
  • x – x coordinate value of the pixel
  • y – y coordinate value of the pixel
  • color – the color
quadratic(x0, y0, x1, y1, x2, y2)

Draw a quadratic bezier curve.

points (x0,y0),(x1,y1),(x2,y2) are the control points of the curve,

Parameters:
  • x0 – x coordinate of the first control point
  • y0 – y coordinate of the first control point
  • x1 – x coordinate of the second control point
  • y1 – y coordinate of the second control point
  • x2 – x coordinate of the third control point
  • y2 – y coordinate of the third control point
quadratic_vertex(x1, y1, x2, y2)

Define a quadratic Bezier curve vertex. The first control point of the curve the vertex defined last time.

Parameters:
  • x1 – x pos of the second control point
  • y1 – y pos of the second control point
  • x2 – x pos of the third control point
  • y2 – y pos of the third control point
rect(x1: float, y1: float, x2: float, y2: float)

Draws a rectangle outline with upper left corner at (left, top) and lower right corner at (right,bottom).

The rectangle is not filled.

Parameters:
  • x1 – x coordinate value of the upper left corner
  • y1 – y coordinate value of the upper left corner
  • x2 – x coordinate value of the lower right corner
  • y2 – y coordinate value of the lower right corner
reflect(x: float, y: float, x1: float = 0, y1: float = 0)

Reflect the coordinates against the line passing (x1,y1) and (x,y).

Note that all things will get reflected, including text! If you just want to draw on a normal coordinate system with the y-axis grows bottom up, use set_flip_y()..

Parameters:
  • x – x coordinate value of the first point
  • y – y coordinate value of the first point
  • x1 – the x coordinate of the second point
  • y1 – the y coordinate of the second point
remove_updated_listener(listener: Callable[[], None])

Remove a updated event listener.

Parameters:listener – the listener to remove
reset_transform()

Reset all transforms (translate/rotate/scale).

reset_view_port()

Reset the view port setting.

reset_window()

Reset/remove the logical window.(see set_window())

restore_settings()

Restore previously saved drawing settings.

See save_settings().

Note: current position won’t be saved and restored.

rotate(degree: float, x: float = 0, y: float = 0)

Rotates the coordinate system around the point (x,y) with the given angle (in degree) clockwise.

Parameters:
  • degree – the rotate angle (in degree)
  • x – the x coordinate of the rotation center
  • y – the y coordinate of the rotation center
rounded_rect(x1: float, y1: float, x2: float, y2: float, round_x: float, round_y: float)

Draws a rounded rectangle outline with upper left corner at (left, top) , lower right corner at (right,bottom). Raidus on x-axis of the corner ellipse arc is round_x, radius on y-axis of the corner ellipse arc is round_y.

The rectangle is not filled.

Parameters:
  • x1 – x coordinate value of the upper left corner
  • y1 – y coordinate value of the upper left corner
  • x2 – x coordinate value of the lower right corner
  • y2 – y coordinate value of the lower right corner
  • round_x – raidus on x-axis of the corner ellipse arc
  • round_y – radius on y-axis of the corner ellipse arc
save(filename: str, with_background=True)

Save image to file.

Set with_background to False to get a transparent background image.

Note that JPEG format doesn’t support transparent. Use PNG format if you want a transparent background.

Parameters:
  • filename – path of the file
  • with_background – True to save the background together. False not
save_settings()

Save current drawing settings.

See restore_settings().

Note: current position won’t be saved and restored.

scale(sx: float, sy: float)

Scales the coordinate system by (sx, sy).

Parameters:
  • sx – scale factor on x axis.
  • sy – scale factor on y axis.
scaled(width: int, height: int) → easygraphics.image.Image

Create a scaled copy with the specified width and height. :param width: width of the copy :param height: height of the copy :return: new copy

set_antialiasing(anti: bool = True)

Set Anti Aliasing

Parameters:anti – if antialiasing should be set
set_background_color(background_color)

Set and change the background color.

The possible color could be consts defined in Color class, or the color created by rgb() function, or PyQt5’s QColor , QGradient object or QtCore.Qt.GlobalColor consts (see the pyqt reference).

Parameters:background_color – background color
set_brush(brush: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>)

Set the brush.

Parameters:brush – the brush
set_clip_rect(left: int, top: int, right: int, bottom: int)

Set the clip rect.

Drawings outside the clip rect will be clipped.

Parameters:
  • left – left of the clip rectangle
  • top – top of the clip rectangle
  • right – right of the clip rectangle
  • bottom – bottom of the clip rectangle
set_clipping(clipping: bool)

Set clipping.

Use set_clip_rect() to set the clip rectangle.

Parameters:clipping – True will turn on clipping, False will turn off clipping
set_color(color)

Set the foreground (drawing) color of the specified image.

It will be used when drawing lines or shape outlines.

The possible color could be consts defined in Color class, or the color created by rgb() function, or PyQt5’s QColor , QGradient object or QtCore.Qt.GlobalColor consts (see the pyqt reference).

Parameters:color – foreground color
set_composition_mode(mode)

Get composition mode of the specified image.

Composition modes are used to specify how the pixels in the source (image/pen/brush), are merged with the pixel in the destination image.

Parameters:mode – composition mode
set_ellipse_mode(mode)
set_fill_color(fill_color)

Set the fill (drawing) color of the specified image.

It will be used when drawing and fill shapes.

The possible color could be consts defined in Color class, or the color created by rgb() function, or PyQt5’s QColor , QGradient object or QtCore.Qt.GlobalColor consts (see the pyqt reference).

Parameters:fill_color – fill color
set_fill_rule(rule)

Set the fill rule (algorithm) for filling polygons.

Parameters:rule – the rule to be used for filling polygons
set_fill_style(fill_style)

Set fill style of the specified image.

It will be used when drawing and fill shapes. Valid values are the consts defined in FillStyle

Parameters:fill_style – fill style
set_flip_y(flip_y: bool) → None

Reflect with x-aixs as the axis (upside down). Texts will not flip.

Don’t translate the origin to other points (but you can translate and then translate back) before drawing any text. Or the text position’s calculation will get wrong! So if you want to set the origin to the image/image’s center, call set_flip_y() after the set_origin() or translate()!

Note: Use this functions instead of the reflect()/flip()/mirror(),if you only want to draw on an ordinary coordinate system with y-axis grows bottom-up.

Parameters:flip_y – True to turn on the flip, False to turn off.
set_font(font: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>)

Set font of the specified image.

Parameters:font – the font will be used
set_font_size(size: int)

Set font size of the specified image.

Parameters:size – font size of the specified image
set_line_style(line_style)

Set line style.

The line style will be used when drawing lines and shape outlines. Possible value is one of the consts defined in LineStyle.

Parameters:line_style – line style
set_line_width(width: float)

Set line width (thinkness).

It will be used when drawing lines or shape outlines.

Parameters:width – line width
set_pen(pen: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>)

Set pen.

Parameters:pen – the pen to use.
Returns:
set_rect_mode(mode)
set_transform(transform: <sphinx.ext.autodoc.importer._MockObject object at 0x7f53516470b8>)

Set image’s transform matrix.

Parameters:transform – the transform matrix to set
set_view_port(left: int, top: int, right: int, bottom: int)

Set the view port of the the specified image.

View port is the drawing zone on the image.

The drawing outside the view port is not clipped. If you want to clip the drawing ,use set_clip_rect()

if view port and “logical window” don’t have the same width and height, drawing will get zoomed. So set_window() is often used with the set_view_port

Parameters:
  • left – left of the view port rectangle
  • top – top of the view port rectangle
  • right – right of the view port rectangle
  • bottom – bottom of the view port rectangle
set_window(left: int, top: int, width: int, height: int)

Set the logical drawing window.

All your drawing is first drawing on the logical window, then mapping to view port (see set_view_port()). The logical window’s 4 corner points to streched to match the view port.

If your view port is 200x200,and you use set_window(-50,-50,100,100) to get a 100x100 logical window with the left-top corner at (-50,-50) , then the logical window’s left corner (-50,-50) is set to view port’s (0,0), and right-bottom corner (50,50) is set to view port’s right bottom corner (200,200). All logical points is mapping accordingly.

If you just want to transform the drawing, use set_origin()/translate()/rotate()/scale().

The drawing outside the logical window is not clipped. If you want to clip it, use set_clip_rect().

Parameters:
  • left – x pos of the logical window’s left-top corner
  • top – y pos of the logical window’s left-top corner
  • width – width of the logical window
  • height – height of the logical window
shear(sh: float, sv: float, x: float = 0, y: float = 0)

Shear (skew) the coordinates around the point (x,y) by sh,sv.

Parameters:
  • sh – shear ratio on the x-axis
  • sv – shear ratio on the y-axis
  • x – the x coordinate of the skew center
  • y – the y coordinate of the skew center
skew(sh: float, sv: float, x: float = 0, y: float = 0)

Shear (skew) the coordinates around the point (x,y) by sh,sv.

Parameters:
  • sh – shear ratio on the x-axis
  • sv – shear ratio on the y-axis
  • x – the x coordinate of the skew center
  • y – the y coordinate of the skew center
text_height() → int

Return height of the text (font height).

Returns:height of the text (font height)
text_width(text: str) → int

Return width of the text.

Parameters:text – the text
Returns:width of the text
to_bytes(with_background=True, format: str = 'PNG') → bytes

Convert the image to the specified format (i.e. PNG format) bytes.

Parameters:
  • with_background – True to save the background together. False not
  • format – format of the bytes content
Returns:

bytes in the specified format

translate(offset_x: float, offset_y: float)

Translates the coordinate system by the given offset; i.e. the given offset is added to points.

Parameters:
  • offset_x – offset on the x coordinate
  • offset_y – offset on the y coordinate
vertex(x: float, y: float)

Define a vertex.

Parameters:
  • x – x pos of the vertex
  • y – y pos of the vertex
easygraphics.easy_run(main_func: Callable, width=640, height=480)
easygraphics.in_easy_run_mode() → bool
easygraphics.register_for_clean_up(obj)

Register an object for clean up when the app quits.