Pygame Rendering Functionality¶
Utility functions/classes for rendering AiBoids objects with pygame.
See aiboids/demos/sheep.py for example usage.
- pgrender.load_pygame_image(name, colorkey=None)¶
Loads image from current working directory for use in pygame.
- Parameters
name (string) – Image file to load; must be pygame-compatible.
colorkey – (pygame.Color): Used to set a background color for this image that will be ignored during blitting. If set to -1, the upper-left pixel color will be used as the background color.
- Returns
Image for blitting; same format as pygame display.
- Return type
(pygame.Surface)
- pgrender.boid_chevron(radius, color, circle_color=None)¶
Create a simple chevron image for use in pygame.
- Parameters
radius (int or float) – Radius of the image.
color (pygame.Color) – Color of the chevron.
circle_color (optional) – If given, draw the bounding circle with this color.
- Returns
Image for blitting; same format as pygame display.
- Return type
(pygame.Surface)
- pgrender.obstacle_bumper(radius, color1=(0, 0, 0), color2=(222, 22, 22))¶
Create a simple bumper image for use in pygame.
- Parameters
radius (int or float) – Radius of the obstalce.
color1 (pygame.Color) – Color of the inner circle.
color2 (pygame.Color) – Color of the outer ring.
- Returns
Image for blitting; same format as pygame display.
- Return type
(pygame.Surface)
- class pgrender.BaseWall2dSprite(*args: Any, **kwargs: Any)¶
Pygame Sprite for rendering BaseWall2d objects.
- Parameters
owner (BaseWall2d) – The object represented by this sprite.
wall (pygame.Color) – Wall color used for rendering.
panel (pygame.Color) – Color for the front surface of the wall.
- update(delta_t=1.0)¶
Update placeholder for pygame.Sprite parent class. Does nothing.
- class pgrender.PointMass2dSprite(*args: Any, **kwargs: Any)¶
A Pygame sprite used to display a BasePointMass2d object.
- Parameters
owner (BaseWall2d) – The object represented by this sprite.
img_surf (pygame.Surface) – Base image to use for rendering; see below.
Notes
img_surf is the unscaled, non-rotated image used to draw the sprite for this object. Format and orientation should match the display mode. The front/left left of the image should face screen right/up, respectively. The center of the image is rended at the pointmass’ center position. A single base image can be shared between different sprites.
- update(delta_t=1.0)¶
Called by pygame.Group.update() to redraw this sprite.
- Parameters
delta_t (float) – Elapsed time since last update; currently unused.
- pgrender.boundary_walls(sc_size, thick=10)¶
Convenience function to generate walls/sprites near the screen border.
- Parameters
sc_size (int, int) – Width, height of the display area, in pixels.
thick (int, optional) – Thickness of walls, in pixels.
- Returns
List of BaseWall2d, List of BaseWall2dSprite.
- Return type
(list, list)
- pgrender.scattered_obstacles(numobs, radius, sc_size)¶
Convenience function for randomly-scattered obstacles and their sprites.
- Parameters
numobs (positive int) – Number of obstacles to generate.
radius (positive float) – Obstacle radius.
obs_image (pygame.Surface) – Obstacle image (shared among instances).
sc_size (int, int) – Width, height of the display area, in pixels.
- Returns
First list contains the SimpleObstacle2d’s; 2nd their sprites.
- Return type
(list, list)
Notes
By default, this uses the same sprite class as BasePointMass2d.
- pgrender.setup(screensize, caption_text='AiBoids Demo')¶
Convenience function for pygame setup boilerplate.
- Parameters
screensize (int, int) – Passed through to pygame.display.set_mode().
caption_text (string, optional) – Caption for pygame window.
- Returns
Display surface and background color.
- Return type
(pygame.Surface, pygame.Color)