easymunk.matplotlib
Module¶
This submodule contains helper functions to help with working with datascience tools such as Jupyter notebooks and Streamlit via matplotlib.
-
class
easymunk.matplotlib.
DrawOptions
(ax=None, bb=None, dot_scale=0.1)[source]¶ Bases:
easymunk.drawing.DrawOptions
-
__init__
(ax=None, bb=None, dot_scale=0.1)[source]¶ DrawOptions for space.debug_draw() to draw a space on a ax object.
Typical usage:
>>> space = mk.Space() >>> space.debug_draw("matplotlib")
You can control the color of a Shape by setting shape.color to the color you want it drawn in.
>>> shape = space.static_body.create_circle(10) >>> shape.color = (1, 0, 0, 1) # will draw shape in red
See matplotlib_util.demo.py for a full example
- Param
- ax: matplotlib.Axes
A matplotlib Axes object.
-
property
ax
¶ - Return type
<class ‘Axes’>
-
draw_circle
(pos, radius, angle=0.0, outline_color=Color(255, 0, 0, 255), fill_color=Color(255, 0, 0, 255))[source]¶ Draw circle from position, radius, angle, and colors.
- Return type
None
-
draw_fat_segment
(a, b, radius=0.0, outline_color=Color(255, 0, 0, 255), fill_color=Color(255, 0, 0, 255))[source]¶ Draw fat segment/capsule.
- Return type
None
-
draw_polygon
(verts, radius=0.0, outline_color=Color(255, 0, 0, 255), fill_color=Color(255, 0, 0, 255))[source]¶ Draw polygon from list of vertices.
- Return type
None
-
DRAW_COLLISION_POINTS
= 4¶ Draw collision points.
Use on the flags property to control if collision points should be drawn or not.
-
DRAW_CONSTRAINTS
= 2¶ Draw constraints.
Use on the flags property to control if constraints should be drawn or not.
-
DRAW_SHAPES
= 1¶ Draw shapes.
Use on the flags property to control if shapes should be drawn or not.
-
property
collision_point_color
¶ The color of collisions.
Should be a tuple of 4 ints between 0 and 255 (r, g, b, a).
-
property
constraint_color
¶ The color of constraints.
Should be a tuple of 4 ints between 0 and 255 (r, g, b, a).
-
draw_circle_shape
(circle)[source]¶ Default implementation that draws a circular shape.
This function is not affected by overriding the draw method of shape.
- Return type
None
-
draw_poly_shape
(shape)[source]¶ Default implementation that draws a polygonal shape.
This function is not affected by overriding the draw method of shape.
- Return type
None
-
draw_segment_shape
(shape)[source]¶ Default implementation that draws a segment shape.
This function is not affected by overriding the draw method of shape.
- Return type
None
-
property
flags
¶ Bit flags which of shapes, joints and collisions should be drawn.
By default all 3 flags are set, meaning shapes, joints and collisions will be drawn.
Example using the basic text only DebugDraw implementation (normally you would the desired backend instead, such as pygame_util.DrawOptions or pyglet_util.DrawOptions):
-
shape_dynamic_color
= Color(52, 152, 219, 255)¶
-
shape_kinematic_color
= Color(39, 174, 96, 255)¶
-
property
shape_outline_color
¶ The outline color of shapes.
Should be a tuple of 4 ints between 0 and 255 (r, g, b, a).
-
shape_sleeping_color
= Color(114, 148, 168, 255)¶
-
shape_static_color
= Color(149, 165, 166, 255)¶
-