Package pype :: Module sprite
[frames] | no frames]

Module sprite

source code

Pygame/SDL/OpenGL based sprite engine.

Pygame-based sprite engine for doing real-time graphics during behavioral/neurophysiological experiments.

Author -- James A. Mazer (mazerj@gmail.com)

Classes
  FrameBuffer
  ScaledSprite
  Sprite
Sprite object (wrapper for pygame surface class).
  PolySprite
Sprite-like Polygon.
  TextSprite
Sprite-like Text object.
  MovieDecoder
  DisplayList
Sprite-list manager.
Functions
 
Logger(s, *args) source code
 
image2pil(image) source code
 
genaxes(w, h, rw, rh, typecode=np.float64, inverty=0)
Generate two arrays descripting sprite x- and y-coordinate axes (like Matlab MESHGRID).
source code
 
is_sequence(x)
Is arg a sequence-type?
source code
 
colr(*args, **kwargs)
Improved C() -- converts argument to RGBA color in useful way. By default generates values 0-255, but normal keyword is True, colors are assumed to be specified/generated on the range [0-1].
source code
 
C(color, gl=0)
Color specification/normalization
source code
 
barsprite(w, h, angle, color, **kw)
Make a bar (creates new sprite).
source code
 
barspriteCW(w, h, angle, color, **kw) source code
 
barspriteCCW(w, h, angle, color, **kw) source code
 
fixsprite(x, y, fb, fix_size, color, bg)
Fixation target sprite generator.
source code
 
fixsprite2(x, y, fb, fix_size, fix_ring, color, bg)
fancy fixation target sprite generator
source code
 
quickinit(dpy=":0.0", w=100, h=100, fullscreen=0, mouse=0)
Quickly setup and initialize framebuffer
source code
 
quickfb(w, h, fullscreen=0)
Get a quick (windowed) FrameBuffer for scripts and testing.
source code
 
ppflag(flags) source code
 
drawtest(fb, s)
Draw standard test pattern.
source code
 
tickbox(x, y, width, height, lwidth, color, fb) source code
Variables
  GLASS = 0, 0, 0, 0
  WHITE = 255, 255, 255
  BLACK = 1, 1, 1
  RED = 255, 1, 1
  GREEN = 1, 255, 1
  BLUE = 1, 1, 255, 1
  YELLOW = 255, 255, 1
  MAGENTA = 255, 1, 255
  CYAN = 1, 255, 255
Function Details

genaxes(w, h, rw, rh, typecode=np.float64, inverty=0)

source code 

Generate two arrays descripting sprite x- and y-coordinate axes (like Matlab MESHGRID).

NB By default the coordinate system is matrix/matlab, which means that negative values are at the top of the sprite and increase going down the screen. This is fine if all you use the function for is to compute eccentricity to shaping envelopes, but wrong for most math. Use inverty=1 to get proper world coords..

Mon Mar 3 13:24:10 2014 mazer NOTE: there was a small fencpost error here (I think) -- linspace is right, arange is likely wrong: >> x = np.arange(0, w) - ((w - 1) / 2.0) >> y = np.arange(0, h) - ((h - 1) / 2.0)

Parameters:
  • w, h - scalar values indicating the display width and height of the sprite in needing axes in pixels
  • rw, rh - scalar values indicating the "real" width and height of the sprite (specifies actually array size)
  • typecode - numpy-style typecode for the output array
  • inverty - (boolean) if true, then axes are matlab-style with 0th row at the top, y increasing in the downward direction
Returns:
pair of vectors (xaxis, yaxis) where the dimensions of each vector are (w, 1) and (1, h) respectively.

colr(*args, **kwargs)

source code 

Improved C() -- converts argument to RGBA color in useful way. By default generates values 0-255, but normal keyword is True, colors are assumed to be specified/generated on the range [0-1].

Handled cases:
colr() -> transparent color key (0,0,0,0) colr(r,g,b) colr((r,g,b)) colr(lum) --> (lum,lum,lum) colr(r,g,b,a) colr((r,g,b,a)) colr(lum) --> (lum,lum,lum, 255) colr('name') --> simple named color colr('r,g,b') --> color as string colr('r,g,b,a') --> color with alpha as string

C(color, gl=0)

source code 

Color specification/normalization

Takes number of similar color specifications and tries to convert them all into a common format compatible with pygame, that is a length 4 tuple: (red, green, blue, alpha) where the values vary [0-255], where: 0=off/transparent and 255=on/opaque.

Parameters:
  • gl - (boolean) if true, then values range [0-1], else [0-255]

barsprite(w, h, angle, color, **kw)

source code 

Make a bar (creates new sprite).

Front end for the Sprite instantiation method. This makes a sprite of the specificed width and hight, fills with the specified color (or noise) and rotates the sprite to the specified angle.

This really should be a class that inherits from Sprite().

Returns:
(sprite) requested bar

fixsprite(x, y, fb, fix_size, color, bg)

source code 

Fixation target sprite generator.

Generates a simple sprite containing an "industry standard" fixation target :-) Target is a solid filled circle of the specified color.

Parameters:
  • x, y - (pixels) location of target (center)
  • fb - frame buffer
  • fix_size - (pixels) radius of target (use _ZERO_ for single pixel target)
  • color - fill color
  • bg - background color
Returns:
new sprite containing the target

fixsprite2(x, y, fb, fix_size, fix_ring, color, bg)

source code 

fancy fixation target sprite generator

Generates a sprite containing a circular fixation target surrounded by an annulus of black (to increase detectability).

Parameters:
  • x, y - (pixels) location of target (center)
  • fb - frame buffer
  • fix_size - (pixels) radius of target (use _ZERO_ for single pixel target)
  • fix_ring - (pixels) radius of annulus
  • color - fill color
  • bg - background color
Returns:
new sprite containing the target

quickinit(dpy=":0.0", w=100, h=100, fullscreen=0, mouse=0)

source code 
Quickly setup and initialize framebuffer
Parameters:
  • dpy - (string) display string
  • w, h - (pixels) width and height of display
  • fullscreen - (boolean) full screen mode (default is no)
  • mouse - (boolean) now mouse cursor? (default is no)
Returns:
live frame buffer

quickfb(w, h, fullscreen=0)

source code 
Get a quick (windowed) FrameBuffer for scripts and testing.
Parameters:
  • w, h - (pixels) width and height of display
Returns:
live frame buffer