Pymunx/Documentation: Difference between revisions
< Pymunx
Jump to navigation
Jump to search
Crazy-chris (talk | contribs) m (update) |
Crazy-chris (talk | contribs) (ref 0.4) |
||
Line 4: | Line 4: | ||
<table border="0"> |
<table border="0"> |
||
<tr><td style="padding-left:80px;">[[#pymunx. |
<tr><td style="padding-left:80px;">[[#pymunx.__init__|pymunx.__init__]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;"> |
<tr><td style="padding-left:80px;">[[#pymunx.init_colors|pymunx.init_colors]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;"> |
<tr><td style="padding-left:80px;">[[#pymunx.set_color|pymunx.set_color]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;"> |
<tr><td style="padding-left:80px;">[[#pymunx.reset_color|pymunx.reset_color]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;"> |
<tr><td style="padding-left:80px;">[[#pymunx.get_color|pymunx.get_color]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;"> |
<tr><td style="padding-left:80px;">[[#pymunx.set_info|pymunx.set_info]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;"> |
<tr><td style="padding-left:80px;">[[#pymunx.clear|pymunx.clear]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;"> |
<tr><td style="padding-left:80px;">[[#pymunx.flipy|pymunx.flipy]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;"> |
<tr><td style="padding-left:80px;">[[#pymunx.vec2df|pymunx.vec2df]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;"> |
<tr><td style="padding-left:80px;">[[#pymunx.autoset_screen_size|pymunx.autoset_screen_size]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;"> |
<tr><td style="padding-left:80px;">[[#pymunx.is_inside|pymunx.is_inside]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;"> |
<tr><td style="padding-left:80px;">[[#pymunx.update|pymunx.update]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;">[[#pymunx. |
<tr><td style="padding-left:80px;">[[#pymunx.draw|pymunx.draw]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;">[[#pymunx. |
<tr><td style="padding-left:80px;">[[#pymunx.draw_shape|pymunx.draw_shape]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;">[[#pymunx. |
<tr><td style="padding-left:80px;">[[#pymunx.add_wall|pymunx.add_wall]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;">[[#pymunx. |
<tr><td style="padding-left:80px;">[[#pymunx.add_ball|pymunx.add_ball]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;">[[#pymunx. |
<tr><td style="padding-left:80px;">[[#pymunx.add_square|pymunx.add_square]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
<tr><td style="padding-left:80px;">[[#pymunx.add_poly|pymunx.add_poly]]</td> |
|||
<td style="padding-left:20px;"></td></tr> |
|||
<tr><td style="padding-left:80px;">[[#pymunx.apply_impulse|pymunx.apply_impulse]]</td> |
|||
<td style="padding-left:20px;"></td></tr> |
|||
<tr><td style="padding-left:80px;">[[#pymunx. |
<tr><td style="padding-left:80px;">[[#pymunx.get_element_count|pymunx.get_element_count]]</td> |
||
<td style="padding-left:20px;"> |
<td style="padding-left:20px;"></td></tr> |
||
</table> |
</table> |
||
Line 63: | Line 69: | ||
=== pymunx.__init__ === |
=== pymunx.__init__ === |
||
:<big> |
:<big>pymunx.__init__ (gravity= (0.0,-900.0))</big> |
||
::* Init function |
::* Init function: init pymunk, get screen size, init space, ... |
||
::* |
::* Parameter: gravity == (int(x), int(y)) |
||
::* Returns: |
::* Returns: pymunx() |
||
=== pymunx. |
=== pymunx.init_colors === |
||
:<big>pymunx. |
:<big>pymunx.init_colors ()</big> |
||
::* Init self.colors with a fix set of hex colors |
|||
::* Set the Info-Text which will be blit at the upper left corner each update |
|||
::* Parameters: txt = str (break lines with \n) |
|||
::* Returns: - |
::* Returns: - |
||
=== pymunx. |
=== pymunx.set_color === |
||
:<big>pymunx. |
:<big>pymunx.set_color (clr)</big> |
||
::* Set a color for all future Elements, until reset_color() is called |
|||
::* Update thy physics. fps is optional and by default set to 50.0 - steps is substeps per update |
|||
::* Parameter: clr == (Hex or RGB) |
|||
::* Returns: - |
::* Returns: - |
||
=== pymunx. |
=== pymunx.reset_color === |
||
:<big>pymunx. |
:<big>pymunx.reset_color ()</big> |
||
::* All Elements from now on will be drawn in random colors |
|||
::* Iterate through all elements and call draw_shape with each |
|||
::* Parameters: surface = pygame.Surface |
|||
::* Returns: - |
::* Returns: - |
||
=== pymunx.get_color === |
|||
:<big>pymunx.get_color ()</big> |
|||
::* Get a color - either the fixed one or the next from self.colors |
|||
::* Returns: clr = ((R), (G), (B)) |
|||
=== pymunx.add_wall === |
|||
=== pymunx.set_info === |
|||
:<big>pymunx.add_wall (self, p1, p2, friction=10.0)</big> |
|||
:<big>pymunx.set_info (txt)</big> |
|||
::* Add a fixed wall between points p1 and p2. friction is a optional parameter |
|||
::* Create the Surface for the Infotext at the Upper Left Corner |
|||
::* Parameters: p = (int(x), int(y)) |
|||
::* Parameter: txt == str() |
|||
::* Returns: - |
::* Returns: - |
||
=== pymunx. |
=== pymunx.clear === |
||
:<big>pymunx. |
:<big>pymunx.clear ()</big> |
||
::* Clears the Space |
|||
::* Add a ball at pos. Other parameters are optional |
|||
::* Parameters: pos = (int(x), int(y)) |
|||
::* Returns: - |
::* Returns: - |
||
=== pymunx. |
=== pymunx.flipy === |
||
:<big>pymunx. |
:<big>pymunx.flipy (y)</big> |
||
::* Convert pygame y-coordinate to chipmunk's |
|||
::* Add a square at pos. |
|||
::* |
::* Parameter: y == int() |
||
::* Returns: |
::* Returns: int(y_new) |
||
=== pymunx. |
=== pymunx.vec2df === |
||
:<big>pymunx. |
:<big>pymunx.vec2df (pos)</big> |
||
::* Return a vec2d with flipped y |
|||
::* Add a polygon from given a given pygame pointlist |
|||
::* |
::* Parameter: pos == vec2d(int(x), int(chipmunk_y)) |
||
::* Returns: - |
::* Returns: - |
||
=== pymunx.get_element_count === |
|||
:<big>pymunx.get_element_count(self)</big> |
|||
::* Returns the current element count |
|||
::* Returns: int(n) |
|||
=== pymunx.autoset_screen_size === |
=== pymunx.autoset_screen_size === |
||
:<big>pymunx.autoset_screen_size ( |
:<big>pymunx.autoset_screen_size (size=None)</big> |
||
::* Get |
::* Get the current PyGame Screen Size, or sets it manually |
||
::* Optional: size == (int(width), int(height)) |
|||
::* Returns: - |
::* Returns: - |
||
=== pymunx. |
=== pymunx.is_inside === |
||
:<big>pymunx. |
:<big>pymunx.is_inside (pos, tolerance=3000)</big> |
||
::* |
::* Check if pos is inside screen + tolerance |
||
::* |
::* Parameter: pos == (int(x), int(y)) |
||
::* Optional: tolerance == int(pixels) |
|||
::* Returns: - |
|||
::* Returns: True if inside, False if outside |
|||
=== pymunx. |
=== pymunx.update === |
||
:<big>pymunx. |
:<big>pymunx.update (fps=50.0, steps=5)</big> |
||
::* Update the Physics Space |
|||
::* Use random colors instead of a fixed one |
|||
::* Optional: fps == int(fps), steps == int(space_steps_per_udate) |
|||
::* Returns: - |
::* Returns: - |
||
=== pymunx. |
=== pymunx.draw === |
||
:<big>pymunx. |
:<big>pymunx.draw (surface)</big> |
||
::* Draw All Shapes, and removes the ones outside |
|||
::* Inits self.colors with a fix set of hex colors |
|||
::* Parameter: surface == pygame.Surface() |
|||
::* Returns: - |
::* Returns: - |
||
=== pymunx.draw_shape === |
|||
:<big>pymunx.draw_shape (surface, shape)</big> |
|||
::* Draw a shape (can be either Circle, Segment or Poly). |
|||
::* Parameter: surface == pygame.Surface(), shape == pymunk.Shape() |
|||
::* Returns: True if shape is inside screen, else False (for removal) |
|||
=== pymunx.get_color === |
|||
:<big>pymunx.get_color(self)</big> |
|||
::* If a fixed color is specified, return that. Else, return a random one. |
|||
::* Returns: clr = rgb ((100), (200), (0)) |
|||
=== pymunx.add_wall === |
|||
:<big>pymunx.add_wall (p1, p2, friction=1.0, elasticity=0.5, mass=inf, inertia=inf)</big> |
|||
::* Adds a fixed Wall pos = (int(x), int(y)) |
|||
::* Parameter: p1 == pos(startpoint), p2 == pos(endpoint) |
|||
::* Optional: See #physical_parameters |
|||
::* Returns: pymunk.Shape() (=> .Segment()) |
|||
=== pymunx.flipy === |
|||
:<big>pymunx.flipy (self, y)</big> |
|||
::# Convert Chipmunk y-coordinate to pyGame (y = -y + self.display_height) |
|||
::# Parameters: y = int |
|||
::# Returns: int(y_new) |
|||
=== pymunx.add_ball === |
|||
:<big>pymunx.add_ball (pos, radius=15, density=0.1, inertia=1000, friction=0.5, elasticity=0.3)</big> |
|||
::* Adds a Ball |
|||
::* Parameter: pos == (int(x), int(y)) |
|||
::* Optional: See #physical_parameters |
|||
::* Returns: pymunk.Shape() (=> .Circle()) |
|||
=== pymunx.vec2df === |
|||
:<big>pymunx.vec2df(self, pos)</big> |
|||
::* Convert a pygame pos to a vec2d with flipped y coordinate |
|||
::* Parameters: pos = (int(x), int(y)) |
|||
::* Returns: class vec2d((pos[0], self.flipy(pos[1]))) |
|||
=== pymunx.add_square === |
|||
:<big>pymunx.add_square (pos, a=18, density=0.1, friction=0.2, elasticity=0.3)</big> |
|||
::* Adding a Square | Note that a is actually half a side, due to vector easyness :) |
|||
::* Parameter: pos == (int(x), int(y)) |
|||
::* Optional: a == (sidelen/2) | #physical_parameters |
|||
::* Returns: pymunk.Shape() (=> .Poly()) |
|||
=== pymunx.draw_shape === |
|||
:<big>pymunx.draw_shape (self, surface, shape)</big> |
|||
::* Draw a given shape (circle, segment, poly) on the surface |
|||
::* Parameters: surface = pygame.Surface | shape = pymunk.Shape |
|||
::* Returns: - |
|||
=== pymunx.add_poly === |
|||
:<big>pymunx.add_poly (points, density=0.1, friction=2.0, elasticity=0.3)</big> |
|||
::* Mass will be calculated out of mass = A * density |
|||
::* Parameter: points == [(int(x), int(y)), (int(x), int(y)), ...] |
|||
::* Optional: See #physical_parameters |
|||
::* Returns: pymunk.Shape() (=> .Poly()) |
|||
=== pymunx.get_pymunk_flags === |
|||
:<big>pymunx.get_pymunk_flags (self)</big> |
|||
::* Check pymunk version, adjusts settings and returns new flagset |
|||
::* Returns: class pymunk_flags |
|||
=== pymunx.apply_impulse === |
|||
:<big>pymunx.apply_impulse (shape, impulse_vector)</big> |
|||
<!-- demo |
|||
::* Apply an Impulse to a given Shape |
|||
=== pymunx. === |
|||
::* Parameter: shape == pymunk.Shape(), impulse_vector == (int(x), int(y)) |
|||
:<big></big> |
|||
::* |
|||
::* Returns: - |
::* Returns: - |
||
--> |
|||
=== pymunx.get_element_count === |
|||
:<big>pymunx.get_element_count ()</big> |
|||
::* Get the current (approx.) element count |
|||
::* Returns: int(element_count) |
Revision as of 00:25, 10 March 2008
pymunx
- Physics API for easy usage of chipmunk physics engine in pygame (with pymunk)
- (bold are the functions you'll likely want to use :)
pymunx.__init__
- pymunx.__init__ (gravity= (0.0,-900.0))
- Init function: init pymunk, get screen size, init space, ...
- Parameter: gravity == (int(x), int(y))
- Returns: pymunx()
pymunx.init_colors
- pymunx.init_colors ()
- Init self.colors with a fix set of hex colors
- Returns: -
pymunx.set_color
- pymunx.set_color (clr)
- Set a color for all future Elements, until reset_color() is called
- Parameter: clr == (Hex or RGB)
- Returns: -
pymunx.reset_color
- pymunx.reset_color ()
- All Elements from now on will be drawn in random colors
- Returns: -
pymunx.get_color
- pymunx.get_color ()
- Get a color - either the fixed one or the next from self.colors
- Returns: clr = ((R), (G), (B))
pymunx.set_info
- pymunx.set_info (txt)
- Create the Surface for the Infotext at the Upper Left Corner
- Parameter: txt == str()
- Returns: -
pymunx.clear
- pymunx.clear ()
- Clears the Space
- Returns: -
pymunx.flipy
- pymunx.flipy (y)
- Convert pygame y-coordinate to chipmunk's
- Parameter: y == int()
- Returns: int(y_new)
pymunx.vec2df
- pymunx.vec2df (pos)
- Return a vec2d with flipped y
- Parameter: pos == vec2d(int(x), int(chipmunk_y))
- Returns: -
pymunx.autoset_screen_size
- pymunx.autoset_screen_size (size=None)
- Get the current PyGame Screen Size, or sets it manually
- Optional: size == (int(width), int(height))
- Returns: -
pymunx.is_inside
- pymunx.is_inside (pos, tolerance=3000)
- Check if pos is inside screen + tolerance
- Parameter: pos == (int(x), int(y))
- Optional: tolerance == int(pixels)
- Returns: True if inside, False if outside
pymunx.update
- pymunx.update (fps=50.0, steps=5)
- Update the Physics Space
- Optional: fps == int(fps), steps == int(space_steps_per_udate)
- Returns: -
pymunx.draw
- pymunx.draw (surface)
- Draw All Shapes, and removes the ones outside
- Parameter: surface == pygame.Surface()
- Returns: -
pymunx.draw_shape
- pymunx.draw_shape (surface, shape)
- Draw a shape (can be either Circle, Segment or Poly).
- Parameter: surface == pygame.Surface(), shape == pymunk.Shape()
- Returns: True if shape is inside screen, else False (for removal)
pymunx.add_wall
- pymunx.add_wall (p1, p2, friction=1.0, elasticity=0.5, mass=inf, inertia=inf)
- Adds a fixed Wall pos = (int(x), int(y))
- Parameter: p1 == pos(startpoint), p2 == pos(endpoint)
- Optional: See #physical_parameters
- Returns: pymunk.Shape() (=> .Segment())
pymunx.add_ball
- pymunx.add_ball (pos, radius=15, density=0.1, inertia=1000, friction=0.5, elasticity=0.3)
- Adds a Ball
- Parameter: pos == (int(x), int(y))
- Optional: See #physical_parameters
- Returns: pymunk.Shape() (=> .Circle())
pymunx.add_square
- pymunx.add_square (pos, a=18, density=0.1, friction=0.2, elasticity=0.3)
- Adding a Square | Note that a is actually half a side, due to vector easyness :)
- Parameter: pos == (int(x), int(y))
- Optional: a == (sidelen/2) | #physical_parameters
- Returns: pymunk.Shape() (=> .Poly())
pymunx.add_poly
- pymunx.add_poly (points, density=0.1, friction=2.0, elasticity=0.3)
- Mass will be calculated out of mass = A * density
- Parameter: points == [(int(x), int(y)), (int(x), int(y)), ...]
- Optional: See #physical_parameters
- Returns: pymunk.Shape() (=> .Poly())
pymunx.apply_impulse
- pymunx.apply_impulse (shape, impulse_vector)
- Apply an Impulse to a given Shape
- Parameter: shape == pymunk.Shape(), impulse_vector == (int(x), int(y))
- Returns: -
pymunx.get_element_count
- pymunx.get_element_count ()
- Get the current (approx.) element count
- Returns: int(element_count)