Class GfxDraw
The pygame.gfxdraw primitives Gymnasium's envs draw with (pygame-ce 2.5.8), including pygame's conversion
of the Python arguments, so the same inputs give the same pixels or the same error.
public static class GfxDraw
- Inheritance
-
GfxDraw
- Inherited Members
Remarks
Polygon vertices are floats, as Gymnasium computes them. pygame converts each coordinate with Python's
int() (truncation toward zero; NaN raises ValueError, an infinity
OverflowError), then to a C long (32 bits on the reference platform, Windows x64; larger
values raise Python int too large to convert to C long) and finally truncates it to Sint16 without a check:
a vertex at x = 40000 is drawn at x = -25536.
The integer arguments of AACircle(Surface, long, long, long, Color), FilledCircle(Surface, long, long, long, Color), HLine(Surface, long, long, long, Color) and
VLine(Surface, long, long, long, Color) are Python ints parsed with the h format: beyond a C long they raise the same
message, and beyond Sint16 signed short integer is greater than maximum (or less than minimum). Each
argument is checked in order, so the first bad one names the error, as in Python.
Python's OverflowError is OverflowError, the type NumSharp throws for NumPy's; its
ValueError is ValueError. On Linux and macOS a C long has 64 bits, so pygame there reports the
Sint16 range message for values between 2^31 and 2^63; Gym.NET follows the reference platform everywhere.
Reference: src_c/gfxdraw.c (pygame-ce 2.5.8).
Methods
AACircle(Surface, long, long, long, Color)
gfxdraw.aacircle(surface, x, y, r, color): the anti-aliased outline of a circle.
public static void AACircle(Surface surface, long x, long y, long r, Color color)
Parameters
surfaceSurfaceThe surface.
xlongThe centre's column, a Python int.
ylongThe centre's row.
rlongThe radius.
colorColorThe colour.
Exceptions
- ArgumentNullException
Thrown when
surfaceis null.- NotSupportedException
Thrown for a surface with per-pixel alpha, which the SDL_gfx port does not model.
- OverflowError
Thrown for an argument outside Sint16 (with pygame's message for it).
- SdlError
Thrown for a negative radius, which SDL_gfx rejects.
AAPolygon(Surface, IReadOnlyList<(double X, double Y)>, Color)
gfxdraw.aapolygon(surface, points, color): the anti-aliased outline of the polygon, each edge drawn
without its last pixel.
public static void AAPolygon(Surface surface, IReadOnlyList<(double X, double Y)> points, Color color)
Parameters
surfaceSurfaceThe surface.
pointsIReadOnlyList<(double X, double Y)>The vertices, at least 3, as
(x, y)floats.colorColorThe colour; its alpha weights the blend.
Exceptions
- ArgumentNullException
Thrown when
surfaceorpointsis null.- NotSupportedException
Thrown for a surface with per-pixel alpha, which the SDL_gfx port does not model.
- ValueError
Thrown for fewer than 3 points (
points must contain more than 2 points) or a NaN coordinate.- OverflowError
Thrown for an infinite coordinate or one beyond a C long.
FilledCircle(Surface, long, long, long, Color)
gfxdraw.filled_circle(surface, x, y, r, color): a filled circle, row by row.
public static void FilledCircle(Surface surface, long x, long y, long r, Color color)
Parameters
surfaceSurfaceThe surface.
xlongThe centre's column, a Python int.
ylongThe centre's row.
rlongThe radius.
colorColorThe colour.
Exceptions
- ArgumentNullException
Thrown when
surfaceis null.- NotSupportedException
Thrown for a surface with per-pixel alpha, which the SDL_gfx port does not model.
- OverflowError
Thrown for an argument outside Sint16.
- SdlError
Thrown for a negative radius.
FilledPolygon(Surface, IReadOnlyList<(double X, double Y)>, Color)
gfxdraw.filled_polygon(surface, points, color): the polygon's interior, scanline by scanline.
public static void FilledPolygon(Surface surface, IReadOnlyList<(double X, double Y)> points, Color color)
Parameters
surfaceSurfaceThe surface.
pointsIReadOnlyList<(double X, double Y)>The vertices, at least 3, as
(x, y)floats.colorColorThe colour; below 255 its alpha blends each filled pixel.
Exceptions
- ArgumentNullException
Thrown when
surfaceorpointsis null.- NotSupportedException
Thrown for a surface with per-pixel alpha, which the SDL_gfx port does not model.
- ValueError
Thrown for fewer than 3 points or a NaN coordinate.
- OverflowError
Thrown for an infinite coordinate or one beyond a C long.
HLine(Surface, long, long, long, Color)
gfxdraw.hline(surface, x1, x2, y, color): a horizontal line, both ends included, clipped to the surface.
public static void HLine(Surface surface, long x1, long x2, long y, Color color)
Parameters
surfaceSurfaceThe surface.
x1longOne end's column, a Python int.
x2longThe other end's column.
ylongThe row.
colorColorThe colour.
Exceptions
- ArgumentNullException
Thrown when
surfaceis null.- NotSupportedException
Thrown for a surface with per-pixel alpha, which the SDL_gfx port does not model.
- OverflowError
Thrown for an argument outside Sint16.
VLine(Surface, long, long, long, Color)
gfxdraw.vline(surface, x, y1, y2, color): a vertical line, both ends included, clipped to the surface.
public static void VLine(Surface surface, long x, long y1, long y2, Color color)
Parameters
surfaceSurfaceThe surface.
xlongThe column, a Python int.
y1longOne end's row.
y2longThe other end's row.
colorColorThe colour.
Exceptions
- ArgumentNullException
Thrown when
surfaceis null.- NotSupportedException
Thrown for a surface with per-pixel alpha, which the SDL_gfx port does not model.
- OverflowError
Thrown for an argument outside Sint16.