Skip to content

Latest commit

 

History

History
70 lines (44 loc) · 1.38 KB

app.rst

File metadata and controls

70 lines (44 loc) · 1.38 KB

Create an app

In this section we are looking how to make an interactive application using Pymunk.

app.py

Circle

The Circle class creates a body with an attached circle shape.

app.py

This is an exemple of three circles placed in a no-gravity space:

p0 = Vec2d(200, 120)
v = Vec2d(100, 0)

Space('Cercle', GRAY, gravity=(0, 0))
Circle(p0)
Circle(p0+v, 20)
Circle(p0+2*v, 50, RED)

image

app.py<app.py>

Segment

The Segment class creates a linear segment starting at position p0 having a direction vector v, a radius and a color.

app.py

This is an example of two segments of different radius, length and color:

Space('Segment', gravity=(0, 0))
Segment(p0, v)
Segment(p0+(50, 50), 2*v, 5, RED)

image

Poly

The Poly class creates a filled polygon placed at position p0 with the vertices v given with a vertex list.

app.py

This is an example of creating a triangle and a square polygon:

Space('Poly', gravity=(0, 0))
triangle = [(-30, -30), (30, -30), (0, 30)]
Poly(p0, triangle)
square = [(-30, -30), (30, -30), (30, 30), (-30, 30)]
Poly(p0+v, square)

image