Pymunx/Documentation: Difference between revisions

From OLPC
Jump to navigation Jump to search
mNo edit summary
m (update)
Line 2: Line 2:
== pymunx ==
== pymunx ==
: ''Physics API for easy usage of chipmunk physics engine in pygame (with pymunk)''
: ''Physics API for easy usage of chipmunk physics engine in pygame (with pymunk)''

<table border="0">
<table border="0">
<tr><td style="padding-left:80px;">[[#pymunx.__init___|pymunx.__init__]]</td>
<tr><td style="padding-left:80px;">[[#pymunx.__init___|pymunx.__init__]]</td>
<td style="padding-left:20px;">Init function: pymunk, get flags, get screen size, init space</td></tr>
<td style="padding-left:20px;">Init function: pymunk, get flags, get screen size, init space</td></tr>


<tr><td style="padding-left:80px;">[[#pymunx.set_info|pymunx.set_info]]</td>
<tr><td style="padding-left:80px;">'''[[#pymunx.set_info|pymunx.set_info]]'''</td>
<td style="padding-left:20px;">Set the Info-Text for the upper left corner</td></tr>
<td style="padding-left:20px;">Set the Info-Text for the upper left corner</td></tr>


<tr><td style="padding-left:80px;">[[#pymunx.flipy|pymunx.flipy]]</td>
<tr><td style="padding-left:80px;">'''[[#pymunx.update|pymunx.update]]'''</td>
<td style="padding-left:20px;">Convert Chipmunk y-coordinate to pyGame</td></tr>

<tr><td style="padding-left:80px;">[[#pymunx.vec2df|pymunx.vec2df]]</td>
<td style="padding-left:20px;">Convert a pygame pos to a vec2d with flipped y coordinate</td></tr>

<tr><td style="padding-left:80px;">[[#pymunx.autoset_screen_size|pymunx.autoset_screen_size]]</td>
<td style="padding-left:20px;">Get screensize from pygame</td></tr>

<tr><td style="padding-left:80px;">[[#pymunx.get_pymunk_flags|pymunx.get_pymunk_flags]]</td>
<td style="padding-left:20px;">Check pymunk version and adjusts settings</td></tr>

<tr><td style="padding-left:80px;">[[#pymunx.update|pymunx.update]]</td>
<td style="padding-left:20px;">Update the physics space</td></tr>
<td style="padding-left:20px;">Update the physics space</td></tr>


<tr><td style="padding-left:80px;">[[#pymunx.draw|pymunx.draw]]</td>
<tr><td style="padding-left:80px;">'''[[#pymunx.draw|pymunx.draw]]'''</td>
<td style="padding-left:20px;">Call draw_shape for each element</td></tr>
<td style="padding-left:20px;">Call draw_shape for each element</td></tr>


<tr><td style="padding-left:80px;">[[#pymunx.draw_shape|pymunx.draw_shape]]</td>
<tr><td style="padding-left:80px;">'''[[#pymunx.add_wall|pymunx.add_wall]]'''</td>
<td style="padding-left:20px;">Draw a given shape (circle, segment, poly) on the surface</td></tr>

<tr><td style="padding-left:80px;">[[#pymunx.add_wall|pymunx.add_wall]]</td>
<td style="padding-left:20px;">Add a fixed wall</td></tr>
<td style="padding-left:20px;">Add a fixed wall</td></tr>


<tr><td style="padding-left:80px;">[[#pymunx.add_ball|pymunx.add_ball]]</td>
<tr><td style="padding-left:80px;">'''[[#pymunx.add_ball|pymunx.add_ball]]'''</td>
<td style="padding-left:20px;">Add a ball</td></tr>
<td style="padding-left:20px;">Add a ball</td></tr>


<tr><td style="padding-left:80px;">[[#pymunx.add_square|pymunx.add_square]]</td>
<tr><td style="padding-left:80px;">'''[[#pymunx.add_square|pymunx.add_square]]'''</td>
<td style="padding-left:20px;">Add a square</td></tr>
<td style="padding-left:20px;">Add a square</td></tr>


<tr><td style="padding-left:80px;">[[#pymunx.add_poly|pymunx.add_poly]]</td>
<tr><td style="padding-left:80px;">'''[[#pymunx.add_poly|pymunx.add_poly]]'''</td>
<td style="padding-left:20px;">Add a polygon</td></tr>
<td style="padding-left:20px;">Add a polygon</td></tr>


<tr><td style="padding-left:80px;">[[#pymunx.get_element_count|pymunx.get_element_count]]</td>
<tr><td style="padding-left:80px;">'''[[#pymunx.get_element_count|pymunx.get_element_count]]'''</td>
<td style="padding-left:20px;">Returns the current element count</td></tr>
<td style="padding-left:20px;">Returns the current element count</td></tr>

<tr><td style="padding-left:80px;">'''[[#pymunx.autoset_screen_size|pymunx.autoset_screen_size]]'''</td>
<td style="padding-left:20px;">Get screensize from pygame. Call on resize</td></tr>

<tr><td style="padding-left:80px;">'''[[#pymunx.set_color|pymunx.set_color]]'''</td>
<td style="padding-left:20px;">Sets a fixed color instead of random</td></tr>

<tr><td style="padding-left:80px;">'''[[#pymunx.reset_color|pymunx.reset_color]]'''</td>
<td style="padding-left:20px;">Use random colors</td></tr>

<tr><td style="padding-left:80px;">[[#pymunx.get_color|pymunx.get_color]]</td>
<td style="padding-left:20px;">Get either fixed or random color in rgb</td></tr>

<tr><td style="padding-left:80px;">[[#pymunx.init_colors|pymunx.init_colors]]</td>
<td style="padding-left:20px;">Init the random color array</td></tr>

<tr><td style="padding-left:80px;">[[#pymunx.flipy|pymunx.flipy]]</td>
<td style="padding-left:20px;">Convert pygame y-coordinate to chipmunk's</td></tr>

<tr><td style="padding-left:80px;">[[#pymunx.vec2df|pymunx.vec2df]]</td>
<td style="padding-left:20px;">Convert a pygame pos to a vec2d with flipped y coordinate</td></tr>

<tr><td style="padding-left:80px;">[[#pymunx.draw_shape|pymunx.draw_shape]]</td>
<td style="padding-left:20px;">Draw a given shape (circle, segment, poly) on the surface</td></tr>

<tr><td style="padding-left:80px;">[[#pymunx.get_pymunk_flags|pymunx.get_pymunk_flags]]</td>
<td style="padding-left:20px;">Check pymunk version and adjusts settings</td></tr>

</table>
</table>
: ''(bold are the functions you'll likely want to use :)''




Line 59: Line 74:
::* Parameters: txt = str (break lines with \n)
::* Parameters: txt = str (break lines with \n)
::* Returns: -
::* Returns: -


=== 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.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.autoset_screen_size ===
:<big>pymunx.autoset_screen_size (self)</big>
::* Get screensize from pygame. Call this only on resize
::* Returns: -


=== pymunx.get_pymunk_flags ===
:<big>pymunx.get_pymunk_flags (self)</big>
::* Check pymunk version, adjusts settings and returns new flagset
::* Returns: class pymunk_flags




Line 99: Line 88:
::* Returns: -
::* Returns: -



=== 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: -




Line 139: Line 122:
::* Returns the current element count
::* Returns the current element count
::* Returns: int(n)
::* Returns: int(n)


=== pymunx.autoset_screen_size ===
:<big>pymunx.autoset_screen_size (self)</big>
::* Get screensize from pygame. Call this only on resize
::* Returns: -


=== pymunx.set_color ===
:<big>pymunx.set_color(self, clr)</big>
::* Use a fixed color instead of a random one
::* clr in either hex ("#123123") or rgb ((100), (100), (0))
::* Returns: -


=== pymunx.reset_color ===
:<big>pymunx.reset_color(self)</big>
::* Use random colors instead of a fixed one
::* Returns: -


=== pymunx.init_colors ===
:<big>pymunx.init_colors(self)</big>
::* Inits self.colors with a fix set of hex colors
::* Returns: -



=== 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.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.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.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.get_pymunk_flags ===
:<big>pymunx.get_pymunk_flags (self)</big>
::* Check pymunk version, adjusts settings and returns new flagset
::* Returns: class pymunk_flags


<!-- demo
=== pymunx. ===
:<big></big>
::*
::* Returns: -
-->

Revision as of 00:07, 9 March 2008

pymunx

Physics API for easy usage of chipmunk physics engine in pygame (with pymunk)
pymunx.__init__ Init function: pymunk, get flags, get screen size, init space
pymunx.set_info Set the Info-Text for the upper left corner
pymunx.update Update the physics space
pymunx.draw Call draw_shape for each element
pymunx.add_wall Add a fixed wall
pymunx.add_ball Add a ball
pymunx.add_square Add a square
pymunx.add_poly Add a polygon
pymunx.get_element_count Returns the current element count
pymunx.autoset_screen_size Get screensize from pygame. Call on resize
pymunx.set_color Sets a fixed color instead of random
pymunx.reset_color Use random colors
pymunx.get_color Get either fixed or random color in rgb
pymunx.init_colors Init the random color array
pymunx.flipy Convert pygame y-coordinate to chipmunk's
pymunx.vec2df Convert a pygame pos to a vec2d with flipped y coordinate
pymunx.draw_shape Draw a given shape (circle, segment, poly) on the surface
pymunx.get_pymunk_flags Check pymunk version and adjusts settings
(bold are the functions you'll likely want to use :)


pymunx.__init__

def __init__(self, gravity=(0.0,-900.0))
  • Init function - pymunk, get flags, get screen size, init space
  • Parameters: gravity = (int(x), int(y))
  • Returns: class pymunx


pymunx.set_info

pymunx.set_info(self, txt)
  • Set the Info-Text which will be blit at the upper left corner each update
  • Parameters: txt = str (break lines with \n)
  • Returns: -


pymunx.update

pymunx.update (self, fps=50.0, steps=5)
  • Update thy physics. fps is optional and by default set to 50.0 - steps is substeps per update
  • Returns: -


pymunx.draw

pymunx.draw (self, surface)
  • Iterate through all elements and call draw_shape with each
  • Parameters: surface = pygame.Surface
  • Returns: -


pymunx.add_wall

pymunx.add_wall (self, p1, p2, friction=10.0)
  • Add a fixed wall between points p1 and p2. friction is a optional parameter
  • Parameters: p = (int(x), int(y))
  • Returns: -


pymunx.add_ball

pymunx.add_ball (self, pos, radius=15, mass=10.0, inertia=1000, friction=0.5)
  • Add a ball at pos. Other parameters are optional
  • Parameters: pos = (int(x), int(y))
  • Returns: -


pymunx.add_square

pymunx.add_square (self, pos, a=18, mass=5.0, friction=0.2)
  • Add a square at pos.
  • Parameters: pos = (int(x), int(y))
  • Returns: -


pymunx.add_poly

pymunx.add_poly(self, points, mass=150.0, friction=10.0)
  • Add a polygon from given a given pygame pointlist
  • Parameters: points = [(int(x), int(y)), (int(x), int(y)), ...]
  • Returns: -


pymunx.get_element_count

pymunx.get_element_count(self)
  • Returns the current element count
  • Returns: int(n)


pymunx.autoset_screen_size

pymunx.autoset_screen_size (self)
  • Get screensize from pygame. Call this only on resize
  • Returns: -


pymunx.set_color

pymunx.set_color(self, clr)
  • Use a fixed color instead of a random one
  • clr in either hex ("#123123") or rgb ((100), (100), (0))
  • Returns: -


pymunx.reset_color

pymunx.reset_color(self)
  • Use random colors instead of a fixed one
  • Returns: -


pymunx.init_colors

pymunx.init_colors(self)
  • Inits self.colors with a fix set of hex colors
  • Returns: -


pymunx.get_color

pymunx.get_color(self)
  • If a fixed color is specified, return that. Else, return a random one.
  • Returns: clr = rgb ((100), (200), (0))


pymunx.flipy

pymunx.flipy (self, y)
  1. Convert Chipmunk y-coordinate to pyGame (y = -y + self.display_height)
  2. Parameters: y = int
  3. Returns: int(y_new)


pymunx.vec2df

pymunx.vec2df(self, pos)
  • 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.draw_shape

pymunx.draw_shape (self, surface, shape)
  • Draw a given shape (circle, segment, poly) on the surface
  • Parameters: surface = pygame.Surface | shape = pymunk.Shape
  • Returns: -


pymunx.get_pymunk_flags

pymunx.get_pymunk_flags (self)
  • Check pymunk version, adjusts settings and returns new flagset
  • Returns: class pymunk_flags