2010 October 12 / j|d|a|v|i|s|@|c|a|r|l|e|t|o|n|.|e|d|u

Body2DJr

Inherits from Body2D. A two-dimensional shape with a prescribed overall color and/or texture. Usually you make a shape using one of the specific constructor functions (makeDisk, etc.).

__init__(self, mesh)

Initializes the shape with the given 2D mesh of vertices and texture coordinates.

setColor(self, color)

Sets the shape's color to the given RGBA value. That is, color should be a 4-tuple or 4-list of floats between 0.0 and 1.0, indicating the red, green, blue, and opacity. The default is opaque white, (1.0, 1.0, 1.0, 1.0).

getColor(self)

Returns the color as an RGBA tuple.

addColor(self, delta)

Adds the given RGBA color tuple to the shape's color.

setTexture(self, texture)

Sets the shape's texture to the given Texture object (or None). The default is None.

getTexture(self)

Returns the shape's Texture object (or None).

Constructor Functions

makeDisk(radius, numSides=32, numAnnuli=1)

Returns a Body2DJr object that is a disk (a filled circle) of the given radius. The remaining parameters control the fineness of the mesh. The position of the Body2DJr object indicates the position of the center of the disk.

makeSector(radius, start, end, numSides=8, numAnnuli=1)

Returns a Body2DJr object that is a sector (a wedge from a disk, like a pie slice) of the given radius, running from the start angle to the end angle (in radians, counterclockwise from the positive x-direction). The remaining parameters control the fineness of the mesh. The position of the Body2DJr object indicates the position of the center of the corresponding disk.

makeAnnulus(innerRadius, outerRadius, numSides=32, numAnnuli=1)

Returns a Body2DJr object that is an annulus (a ring or washer) of the given inner and outer radii. The remaining parameters control the fineness of the mesh. The position of the Body2DJr object indicates the position of the center of the annulus.

makeRectangle(width, height, numWide=1, numHigh=1)

Returns a Body2DJr object that is a rectangle of the given width and height. The remaining parameters control the fineness of the mesh. The position of the Body2DJr object indicates the position of the center of the rectangle.

makeRoundedRectangle(width, height, radius, numWide=1, numHigh=1, numSides=8, numAnnuli=1)

Returns a Body2DJr object that is a rounded rectangle (like a playing card) of the given total width and height, with corners rounded off using circles of the given radius. The remaining parameters control the fineness of the mesh. The position of the Body2DJr object indicates the position of the center of the rounded rectangle.

makeConvexPolygon(vertices)

Returns a Body2DJr object that is a convex polygon, specified by its vertices in counterclockwise order. If the vertices describe a non-convex polygon, then unexpected visual artifacts may arise. To draw a non-convex polygon reliably, break it into convex pieces. The position of the Body2DJr object indicates the local origin, relative to which the vertices are specifed.

makeText(string, fontPath, fontSize)

Returns a Body2DJr object that is a rectangle displaying a fixed string of text, drawn in a fixed TrueType font and size. On Mac OS X a typical fontPath is '/Library/Fonts/Silom.ttf'. A typical size is 12 or 18. The text occupies the shape's texture; setting the texture to something else obliterates the text. The text is opaque white on a transparent background; setting the shape's color therefore sets the text color. The position of the Body2DJr object indicates the position of the center of the text rectangle.