Polygon primitives for pyglet.
This package provides a Shape
object that can be acts as an interface between the libraries polygon and pyglet.
The former provides numerical routines for handling shapes, and the latter can process OpenGL bindings.
With pyglet2d, you can incorporate 2D shapes into your applications without having to write your own OpenGL calls.
- In addition to the standard constructor (from a list or array of points), four others are provided:
Shape.regular_polygon
,Shape.circle
,Shape.rectangle
, andShape.from_dict
. The latter is a specification-based constructor that is easy to use with JSON or YAML. Shape
has two methods that are useful as pyglet callbacks:Shape.draw
andShape.update
. AShape
can be given a velocity and/or an angular velocity, and it will be updated accordingly whenShape.update
is called.- A
Shape
can be manipulated using the methodsShape.scale
,Shape.rotate
,Shape.flip_x
,Shape.flip_y
,Shape.flip
, andShape.translate
, or with in-place arithmetic (e.g.shape += [5, 0]
). - Alternatively, setting the properties
Shape.center
andShape.radius
will translate and scale the shape, respectively. - Clipping operations provided by polygon are bound to the operators |, +, (union), & (intersection), - (difference), and ^ (xor).
- Additional polygon methods can be accessed directly from the
Shape.poly
attribute, where thePolygon
object is stored. - Shortcuts are provided to polygon functions via the boolean methods
Shape.overlaps(other)
andShape.covers(other)
.
See tests/graphics_demo.py
for a usage example.
This script also serves as a test.
Run it to make sure that your graphics pipeline is working correctly:
python tests/graphics_demo.py
- Python >= 3.3
- pyglet >= 1.2alpha1. This must be manually installed as it is not on PyPi.
- polygon >= 3
- numpy
pip install pyglet2d --upgrade
https://pyglet2d.readthedocs.org/
To run the all tests run:
tox