gummworld2.pygame_utils (version $Id: pygame_utils.py 407 2013-08-12 15:11:30Z stabbingfinger@gmail.com $)
index
c:\cygwin\home\bw\devel\python\svn\gummworld2_devel\gamelib\gummworld2\pygame_utils.py

pygame_utils.py - Collection of pygame utilities for Gummworld2.

 
Modules
       
imp
os
pygame
re
sys

 
Functions
       
atan2(...)
atan2(y, x)
 
Return the arc tangent (measured in radians) of y/x.
Unlike atan(y/x), the signs of both x and y are considered.
calc_line(p0, p1)
use Bresenham's algorithm to calculate a set of closed points forming a line
 
Returns an array whose elements are the points of the line.
 
Original calc_line code retrieved from:
http://en.literateprograms.org/Bresenham's_line_algorithm_(Python)?oldid=16281
calculate_bezier(p, steps=30)
calculate a bezier curve from 4 control points
 
Returns a list of the resulting points.
 
The function uses the forward differencing algorithm described here: 
http://www.niksula.cs.hut.fi/~hkankaan/Homepages/bezierfast.html
 
This code taken from www.pygame.org/wiki/BezierCurve.
ccw_corners(r)
return a tuple containing the corners of rect r in counter-clockwise
order starting with topleft
cos(...)
cos(x)
 
Return the cosine of x (measured in radians).
cw_corners(r)
return a tuple containing the corners of rect r in clockwise order
starting with topleft
degrees(...)
degrees(x)
 
Convert angle x from radians to degrees.
distance(a, b)
Calculate the distance between points a and b. Returns distance as a float.
 
The a argument is a sequence representing one end point (x1,y1).
 
The b argument is a sequence representing the other end point (x2,y2).
draw_text(image, text, pos=(0, 0), font='default', fg=(254, 254, 254), bg=(-1, -1, -1), rect_attr=('left', 'top'))
Render text on the image in the named font.
 
Text is rendered at pos in foreground color fg. Width and height of
the rendered text is returned. rect_attr are the position attributes
of the resulting rect to set equal to pos.
fill_gradient(surface, color, gradient, rect=None, vertical=True, forward=True)
fill a surface with a gradient pattern
Parameters:
surface -> drawing surface
color -> starting color
gradient -> final color
rect -> area to fill; default is surface's rect
vertical -> True=vertical; False=horizontal
forward -> True=forward; False=reverse
 
Pygame recipe: http://www.pygame.org/wiki/GradientCode
get_font(name='default')
Return the named pygame.font.
 
The named font is looked up in cached fonts. The font named 'default'
is always available. See make_font() for adding custom fonts to the
cache.
get_font_names()
Return a list of existing font names.
get_main_dir()
Intelligently find the directory the executable is in - needed for py2exe
compatibility
import_module(fullname)
Dynamically imports a module by name
 
fullname is a string in any of these syntaxes:
1. A file name in the Python path, with or without .py extension.
2. Relative or absolute path and file, with or without .py extension. If
path contains os.pathsep, the Python path is not used to locate the file.
A relative path is relative to the current working directory.
init_joystick(joy_id=-1)
Initialize joysticks. This must be called before PyGame will
start sending joystick events. If joy_id is -1 all joysticks
will be intialized. The initialized joysticks are returned as a
dict keyed by joystick id.
load_image(name, colorkey=None, alpha=False)
load an image into memory
make_font(name, file_name, font_size, bold=False, italic=False)
Create a pygame.font.Font from a file. Return the font object.
 
An instance of pygame.font.Font is created and stored in a cache for
retrieval by get_font(). Initially there is one font named 'default',
which may be replaced by a custom font via this function if desired.
Arguments mirror those of pygame.font.SysFont().
make_sysfont(name, font_name, font_size, bold=False, italic=False)
Create a pygame.font.Font from system fonts. Return the font object.
 
An instance of pygame.font.Font is created and stored in a cache for
retrieval by get_font(). Initially there is one font named 'default',
which may be replaced by a custom font via this function if desired.
Arguments mirror those of pygame.font.SysFont().
plot_curve(p)
plot a curved path along one or more sets of control points
 
p is a one-dimensional array of points in multiples of four: i.e.
four points per curve.
 
steps is the number of points desired. steps is weighted by the sum
distance of each four points in order to yield approximately
equidistant points.
 
This code derived from www.pygame.org/wiki/BezierCurve.
pow(...)
pow(x, y)
 
Return x**y (x to the power of y).
radians(...)
radians(x)
 
Convert angle x from degrees to radians.
rot_center(image, angle)
rotate an image while keeping its center and size
sign(n)
return the sign of number n
sin(...)
sin(x)
 
Return the sine of x (measured in radians).
split_thousands(s, sep=',')
insert a comma every thousands place
sqrt(...)
sqrt(x)
 
Return the square root of x.
wait_event(type=5)

 
Data
        MOUSEBUTTONDOWN = 5
RLEACCEL = 16384
__author__ = 'Gummbum, (c) 2011-2013'
__version__ = '$Id: pygame_utils.py 407 2013-08-12 15:11:30Z stabbingfinger@gmail.com $'
pi = 3.1415926535897931

 
Author
        Gummbum, (c) 2011-2013