Namespace Gym.Rendering
Classes
- Clock
Paces a render loop the way
pygame.time.Clockdoes. Human-mode rendering calls Tick(double) withmetadata["render_fps"]once per frame, which sleeps just long enough to hold that frame rate, so a human-mode episode plays at the env's intended speed.
- Display
pygame's display (
pygame.display) in pygame's spelling: the display of Default, the process-wide context, so a line-for-line port keepspygame.display.set_mode(...)asDisplay.SetMode(...). Every member forwards toPygameContext.Default.Display(PygameDisplay, which documents the behaviour in full).
- Draw
The
pygame.drawfunctions Gymnasium's envs call:line(Acrobot, BipedalWalker's lidar), Rect(Surface, Color, long, long, long, long, int) (FrozenLake), Aalines(Surface, Color, bool, IReadOnlyList<(double X, double Y)>) and Aaline(Surface, Color, double, double, double, double) (MountainCar's hill, LunarLander, BipedalWalker), and for the box2d envs Polygon(Surface, Color, IReadOnlyList<(double X, double Y)>, int), Circle(Surface, Color, double, double, double, int) and Lines(Surface, Color, bool, IReadOnlyList<(double X, double Y)>, int), on surfaces without per-pixel alpha.
- Event
An event,
pygame.event.Event(type, dict): a type and a dict of attributes (keyfor a key event,xandyfor a resize), read by Python name through PyAttributes or Dict. Post one to EventQueue to drive Play without a keyboard, as Gymnasium's tests do.
- EventQueue
pygame's event queue (
pygame.event) in pygame's spelling: the queue of Default, the process-wide context, filled by Display's window and by Post(Event), drained by Get(). Every member forwards toPygameContext.Default.Events(PygameEventQueue, which documents the behaviour in full).
- EventType
pygame's event types (
pygame.QUIT,pygame.KEYDOWN, ...): the ones a Gym.NET window posts and Play reads, with pygame-ce 2.5.8's values, and Name(int) for every type pygame names.
- GfxDraw
The
pygame.gfxdrawprimitives 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.
- ImageIO
pygame.image, namedImageIOso it does not clash with ImageSharp'sImagein code that uses both. The part Gymnasium's envs use: Load(string), for the PNG sprites and tiles of the toy_text envs and Pendulum's torque arrow, and FromBytes(byte[], int, int, string), which builds the same kind of surface from raw pixels.
- KeyCode
The keycodes pygame puts in a key event's
key(SDL2'sSDL_Keycode), by readable names: Left is pygame'sK_LEFT. Use them in akeys_to_actionmapping for Play, and in an IInteractiveEnvViewer that translates its framework's keys.
- PygameContext
One pygame "process" (DR-41): a display (Display) and the event queue its window feeds (Events), so several games can run side by side, each in a window of its own and each reading only its own events. Default is the process-wide context that pygame's spelling reaches: the static Display and EventQueue forward to it, so line-for-line ports keep
pygame.display.set_mode(...)asDisplay.SetMode(...).
- PygameDisplay
A PygameContext's display (
pygame.display): the one window the context draws into through its surface, opened by SetMode(int, int, bool, EnvViewerFactory?, string?), shown by Flip(), closed by Quit(). Play plays an env in it. The window is a viewer from the viewer factory (DR-20), so it is an Avalonia or WinForms window, or nothing at all under NullEnvViewer.
- PygameEventQueue
A PygameContext's event queue (
pygame.event): filled by the context's display window (keys, its close button, resizes) and by Post(Event), drained by Get(). Play drains its context's queue once per frame, so posting events is how a program or a test plays an env without a keyboard, as Gymnasium's own tests do withpygame.event.post.
- SdlError
The
pygame.errorthe gfxdraw functions raise when an SDL_gfx primitive returns -1 (a negative radius). pygame's message isSDL_GetError(), whatever SDL error happened to be set last, so it cannot be reproduced; this message names the primitive instead.
- SurfArray
The part of
pygame.surfarrayGymnasium's envs use to hand outrgb_arrayframes: a surface's pixels as a uint8 array in pygame's axis order, or already transposed into the frame an env returns.
- Surface
A drawing surface as Gymnasium's envs create one with
pygame.Surface((width, height)): 32 bits per pixel without per-pixel alpha (SDL's XRGB8888, masks0xff0000,0xff00,0xff, alpha mask 0), black when created, with pygame's(x, y)addressing and its whole area as the clip rectangle. A surface with per-pixel alpha (HasAlpha) is what Load(string) gives for a PNG with an alpha channel, and whattransform.scale/smoothscale/flipgive for one.
- Transform
The part of
pygame.transformGymnasium's envs use: Flip(Surface, bool, bool), which turns a y-up drawing into a frame and mirrors sprites, and Scale(Surface, int, int)/Smoothscale(Surface, int, int), which size the toy_text tiles and Pendulum's torque arrow.
Structs
- Color
An RGBA colour as pygame takes it:
(r, g, b)is opaque (A255) and(r, g, b, a)blends with weighta. Gymnasium passes 3-tuples, so its primitives draw opaque unless anti-aliasing weights the edge pixels.
- Vector2
The part of
pygame.math.Vector2Gymnasium's renderers use: two float64 components and RotateRad(double), whose treatment of angles within Epsilon of a quarter turn decides where CartPole's pole is drawn.