Package pygsear :: Module Drawable :: Class Turtle |
[show private | hide private]
[frames | no frames]

## Class Turtle

    object --+
             |
        Sprite --+
                 |
          Drawable --+
                     |
            MultiImage --+
                         |
              RotatedImage --+
                             |
                            Turtle

Known Subclasses:
  `EuclidTurtle`

Turtle-graphics-like object

Method Summary
| `__init__(self, w, position, deg, color, filename, colorkey, convert)`
| ``backward`(self, dist)` Move the turtle backward distance.
| ``begin`(self, interactive)` Start a new layer for drawing.
| ``begin_fill`(self)` Start saving points for filling a polygon later
| ``blink`(self, times, delay)` Flash the turtle on and off.
| ``cCircle`(self, radius, color, width)` Quick drawing circle, centered on current position.
| ``circle`(self, radius, clockwise, color, width)` Quick drawing circle.
| ``clear`(self, surface)` erase sprite image to background, returning affected rect
| ``clearScreen`(self)` Clear the screen to background color.
| ``commit`(self)` Copy drawing layer to base window.
| ``commit_fill`(self, color)` Fill the polygon of saved points
| ``cRectangle`(self, side_length, side_width, width, color, bgColor)` Quick drawing routine for rectangles.
| ``cSquare`(self, side_length, width, color, bgColor)` Quick drawing routine for squares.
| ``draw`(self, surface)` draw image, returning affected rect
| ``forward`(self, dist)` Move the turtle forward a distance
| ``get_deg`(self)` return current turtle direction.
| ``grow`(self, dx, dy)` Resize the window (larger)
| ``hide`(self)` Set the penguin icon invisible
| ``home`(self)` Move back to the home position
| ``left`(self, d)` Turn left (counter-clockwise) a number of degrees
| ``line`(self, p1, p2)` Draw a line segment between 2 points.
| ``lineTo`(self, position)` Move turtle to position, drawing a line
| ``moveTo`(self, position)` Move turtle to position, without drawing a line
| ``nudge_color`(self, red, blue, green)` Change the pen color by given amounts.
| ``penDown`(self)` Put pen down, ready to draw
| ``penUp`(self)` Pull pen up.
| ``rectangle`(self, side_length, side_width, clockwise, width, color, bgColor)` Quick drawing routine for rectangles.
| ``refresh`(self)` Update the display.
| ``reset`(self)` Clear the screen to LBLUE, and return Penguin to home
| ``right`(self, d)` Turn right (clockwise) a number of degrees
| ``rollback`(self)` Throw out drawing layer.
| ``rollback_fill`(self)` Throw out list of saved points
| ``save`(self, filename)` Save background (the picture) as filename
| ``set_background`(self, color)` Set the background color
| ``set_color`(self, color, r, g, b)` Set the color for drawing.
| ``set_fontSize`(self, fontSize)` Set default font size for `write` and `where`
| ``set_home`(self, pos)` Set the Penguin's home position
| ``set_visible`(self, vis)` Set the penguin icon visible
| ``set_width`(self, width)` Set line width for drawing.
| ``show`(self)` Set the penguin icon visible
| ``shrink`(self, dx, dy)` Resize the window (smaller)
| ``square`(self, side_length, clockwise, width, color, bgColor)` Quick drawing square.
| ``turnTo`(self, deg)` Set turtle's direction to deg (degrees).
| ``update`(self, dirty)` Update the display
| ``wait`(self)` Read pygame events until mouse click or any key press.
| ``where`(self)` Briefly show the current position of the turtle.
| ``write`(self, text, fontSize, color, bgColor)` Draw text from current position, and at current angle.
Inherited from RotatedImage
| ``flip`(self, key)` Switch images for the sprite
| ``get_rotation`(self)` return angle of rotation
| ``move`(self)` set position to next position on path
| ``rotate`(self, rad)` rotate to the left by radians
| ``rotate_left`(self)` set rotation rate to +2
| ``rotate_right`(self)` set rotation rate to -2
| ``rotate_stop`(self)` set rotation rate to 0
| ``rotate_towards`(self, point)` turn as quickly as possible towards a point
| ``set_closest`(self)` flip to the image for the current direction
| ``set_image`(self, key)` Change which image is being shown.
| ``set_rotation`(self, direction)` set angle of rotation
| ``set_rotationRate`(self, rate)` set rate of rotation in radians / second
Inherited from MultiImage
| ``addImage`(self, filename, image, colorkey, convert)` add image to list of available images
| ``removeImage`(self, key)` remove image by name
| ``stretch`(self, dx, dy, size, keepAspectRatio)` Change the size of sprite's image, and rect.
Inherited from Drawable
bool | ``can_see`(self, target, blocking_rects_list)` Performs a los (line of sight) check from the center of the source to the center of the target.
| ``center`(self, x, y, dx, dy)` Align the Drawable in its layer
`bool` | ``collide`(self, other)` return True if this sprite and other sprite overlap.
`Drawable` or `False` | ``collidelist`(self, lothers)` return True if this sprite and any in list of others collide.
`List` | ``collidelistall`(self, lothers)` return True if this sprite and any in list of others collide.
| ``direction`(self, point)` return the direction from the sprite to a point
| ``distance`(self, point)` return the distance from the sprite to a point
| ``get_position`(self)` return a copy of the sprite's position
| ``get_size`(self)` return size of sprite's rect.
| ``nudge`(self, dx, dy)` Move sprite.
| ``onscreen`(self, slack, **kw)` return True if image is on the screen or layer.
| ``pause`(self)` stop moving along Path
| ``runPath`(self, frames)` call move() continuously
| ``set_crect`(self, crect)` set the collision `pygame.Rect` used for collision checking.
| ``set_path`(self, path)` set which path to follow
| ``set_position`(self, location, *args)` Move sprite to location.
| ``set_positionRandom`(self, slack)` Move sprite to a random location on screen
| ``set_size`(self, size)` Set size of sprite's rect.
| ``solid`(self, other, move_both)` move sprite so that it does not overlap with other sprite
| ``uclear`(self, surface)` clear sprite and update display
| ``udraw`(self, surface)` Draw image and update display.
| ``unpause`(self)` start moving along Path
Inherited from Sprite
| ``__repr__`(self)`
| ``add`(self, *groups)` add(group or list of of groups, ...) add a sprite to container
| ``add_internal`(self, group)`
| ``alive`(self)` alive() -> bool check to see if the sprite is in any groups
| ``groups`(self)` groups() -> list of groups list used sprite containers
| ``kill`(self)` kill() remove this sprite from all groups
| ``remove`(self, *groups)` remove(group or list of groups, ...) remove a sprite from container
| ``remove_internal`(self, group)`
Inherited from object
| ``__delattr__`(...)` x.__delattr__('name') <==> del x.name
| ``__getattribute__`(...)` x.__getattribute__('name') <==> x.name
| ``__hash__`(x)` x.__hash__() <==> hash(x)
| ``__reduce__`(...)` helper for pickle
| ``__reduce_ex__`(...)` helper for pickle
| ``__setattr__`(...)` x.__setattr__('name', value) <==> x.name = value
| ``__str__`(x)` x.__str__() <==> str(x)
Inherited from type
| ``__new__`(T, S, ...)` T.__new__(S, ...) -> a new object with type S, a subtype of T

Class Variable Summary
`tuple` | `BGCOLOR` = `(0, 0, 0)`
`tuple` | `COLOR` = `(255, 255, 255)`
Inherited from MultiImage
`NoneType` | `filenames` = None

Method Details

### backward(self, dist) Move the turtle backward distance. eqivalent to forward(-dist) Parameters: `dist` - Number of pixels to move.

### begin(self, interactive=1) Start a new layer for drawing. Use commit() to copy layer to the base window, or use rollback() to throw away the layer and return to drawing directly to the base window.

### begin_fill(self) Start saving points for filling a polygon later Each move pushes the current point in to a list. Use commit_fill() to fill inside of the points use rollback_fill() to throw away the list without filling.

### blink(self, times=1, delay=350) Flash the turtle on and off. Parameters: `times` - Number of times to flash. `delay` - Length of flash, and delay between flashes (in millisecond).

### cCircle(self, radius, color=None, width=None) Quick drawing circle, centered on current position. Does not move the turtle (ie, the turtle will be returned to its present location before returning) "Quick drawing" means that this function draws the circle by calling `pygame.draw.circle` and not by simulating the drawing of a circle with a number of line segments and turns, which would be much slower. Parameters: `radius` - Radius of circle to draw. The center will be the current location. `color` - Color to use for drawing circle, or the string 'random' to choose a random color. Does not affect the turtle's pen color (ie, the pen color will be restored before returning) `width` - Thickness of line to use when drawing, or Zero (0) to fill with color.

### circle(self, radius, clockwise=1, color=None, width=None) Quick drawing circle. Starting from current position and rotation. "Quick drawing" means that this function draws the circle by calling `pygame.draw.circle` and not by simulating the drawing of a circle with a number of line segments and turns, which would be much slower. Parameters: `radius` - Radius of circle to draw. The center will be 90 degrees from the current direction. `clockwise` - Draw the circle turning clockwise from the current position, or if False, turn counter-clockwise. `color` - Color to use for drawing circle, or the string 'random' to choose a random color. Does not affect the turtle's pen color (ie, the pen color will be restored before returning) `width` - Thickness of line to use when drawing, or Zero (0) to fill with color.

### clear(self, surface=None) erase sprite image to background, returning affected rect Overrides: `pygsear.Drawable.Drawable.clear`

### clearScreen(self) Clear the screen to background color. Does not move the Penguin. I am considering a shorter name, perhaps cls

### commit(self) Copy drawing layer to base window.

### commit_fill(self, color=None) Fill the polygon of saved points Start saving points for fill with begin_fill() Fill is done with pygame.draw.polygon, so if the line of points crosses itself, the fill will turn inside out.

### cRectangle(self, side_length=20, side_width=10, width=None, color=None, bgColor=(0, 51, 0, 0)) Quick drawing routine for rectangles. Rectangle is centered on current position. Parameters: `side_length` - length of 1st and 3rd sides drawn `side_width` - length of 2nd and last sides drawn `width` - thickness of outline of rectangle width 0 means rectangle should be filled with color `color` - RGB tuple, color of rectangle `bgColor` - background color. Note that rectangle is not constrained to align horizontally or verically.

### cSquare(self, side_length=20, width=None, color=None, bgColor=(0, 51, 0, 0)) Quick drawing routine for squares. Square is centered on current position. Parameters: `side_length` - length of all sides drawn `width` - thickness of outline of square width 0 means square should be filled with color `color` - RGB tuple, color of square `bgColor` - background color. Note that square is not constrained to align horizontally or verically.

### draw(self, surface=None) draw image, returning affected rect Overrides: `pygsear.Drawable.Drawable.draw`

### forward(self, dist) Move the turtle forward a distance Parameters: `dist` - Number of pixels to move.

### get_deg(self) return current turtle direction. Zero (0) degrees is along the positive x-axis.

### grow(self, dx=50, dy=50) Resize the window (larger) Parameters: `dx` - horizontal amount to increase size `dy` - vertical amount to increase size

### hide(self) Set the penguin icon invisible

### home(self) Move back to the home position

### left(self, d) Turn left (counter-clockwise) a number of degrees Parameters: `d` - Number of degrees to rotate counter-clockwise.

### line(self, p1, p2) Draw a line segment between 2 points. This function ignores the state of the pen. In other words, it will draw a line to the screen in the current color even if the turtle's pen is up. Parameters: `p1` - One endpoint of line segment. `p2` - Second endpoint of line segment.

### lineTo(self, position) Move turtle to position, drawing a line Note that this ignores the state of the pen (up or down) and always draws a line in the current pen color. Parameters: `position` - Point `(x, y)` to draw the line to.

### moveTo(self, position) Move turtle to position, without drawing a line Parameters: `position` - Point `(x, y)` to move to

### nudge_color(self, red=None, blue=None, green=None) Change the pen color by given amounts. Amounts can be either integer numbers (to be added to the RGB tuple components), or percentages (to increase or decrease that component by given percent) ie, if color is `(100, 100, 100)` before the call, a call to `nudge_color(red=50, blue=-10, green="75%")` will result in the color being set to `(150, 90, 75)` Parameters: `red` - Amount to add to R element of color tuple OR a string with the amount to increease the R element. `blue` - Amount to add to B element of color tuple OR a string with the amount to increease the B element. `green` - Amount to add to G element of color tuple OR a string with the amount to increease the G element.

### penDown(self) Put pen down, ready to draw

### penUp(self) Pull pen up. Most movement will not make a mark. Note that some functions (circle notably) do not pay any attention to the state of the pen.

### rectangle(self, side_length=20, side_width=10, clockwise=1, width=None, color=None, bgColor=(0, 51, 0, 0)) Quick drawing routine for rectangles. Parameters: `side_length` - length of 1st and 3rd sides drawn `side_width` - length of 2nd and last sides drawn `clockwise` - all turns will be 90 degrees right clockwise 0 means all turns will be 90 degrees left `width` - thickness of outline of rectangle width 0 means rectangle should be filled with color `color` - RGB tuple, color of rectangle `bgColor` - background color. Note that rectangle is not constrained to align horizontally or verically.

### refresh(self) Update the display. This is useful when your system does not automatically refresh the screen after it gets covered up and then uncovered.

### reset(self) Clear the screen to LBLUE, and return Penguin to home also reset pen color to WHITE, and turn back to 90 deg (standing straight up)

### right(self, d) Turn right (clockwise) a number of degrees Parameters: `d` - Number of degrees to rotate clockwise.

### rollback(self) Throw out drawing layer.

### rollback_fill(self) Throw out list of saved points

### save(self, filename) Save background (the picture) as filename Parameters: `filename` - name of file to save the image to. if filename ends with .bmp it will be saved as a bmp (bitmap), otherwise, the filename will be made to end with .tga (if it does not already) and the file will be saved as a tga file.

### set_background(self, color=None) Set the background color Saves the current picture before changing the background color and restores the picture afterward. The picture may not be quite the same if parts of it were drawn using the old bg color.

### set_color(self, color=None, r=None, g=None, b=None) Set the color for drawing. The caller can choose one of a few ways to set the color: an RGB tuple can be passed in as the `color` parameter (or as the first argument) one or more of `r`, `g`, and `b` parameters can (also) be passed as that portion of the color tuple. If these are given in addition to the `color` parameter, these will override the elements in the `color` tuple. ie. `set_color((10, 10, 10), r=50)` will set the color to `(50, 10, 10)` If these are given with NO color tuple passed, the resulting color will start with the current color, with the new elements being set from the passed parameters ie, if the color is `(100, 100, 100)` before the call, calling `set_color(g=50, b=50)` will set the color to `(100, 50, 50)` if no parameters are passed at all, the color is set to WHITE. Parameters: `color` - an RGB tuple, or the word 'random' which will choose a color at random from (not quite) all possible. `r` - The red value of the color (0 - 255) `g` - The green value of the color (0 - 255) `b` - The blue value of the color (0 - 255)

### set_fontSize(self, fontSize=40) Set default font size for `write` and `where`

### set_home(self, pos=None) Set the Penguin's home position

### set_visible(self, vis=1) Set the penguin icon visible

### set_width(self, width) Set line width for drawing. Parameters: `width` - line width in pixels

### show(self) Set the penguin icon visible

### shrink(self, dx=50, dy=50) Resize the window (smaller) Parameters: `dx` - horizontal amount to reduce size `dy` - vertical amount to reduce size

### square(self, side_length=20, clockwise=1, width=None, color=None, bgColor=(0, 51, 0, 0)) Quick drawing square. Parameters: `side_length` - length of all sides drawn `clockwise` - all turns will be 90 degrees right clockwise 0 means all turns will be 90 degrees left `width` - thickness of outline of square width 0 means square should be filled with color `color` - RGB tuple, color of square `bgColor` - background color. Note that square is not constrained to align horizontally or verically.

### turnTo(self, deg) Set turtle's direction to deg (degrees). Parameters: `deg` - Direction to turn to. 0 degrees is along the positive x-axis.

### update(self, dirty=None) Update the display Overrides: `pygame.sprite.Sprite.update`

### wait(self) Read pygame events until mouse click or any key press.

### where(self) Briefly show the current position of the turtle.

### write(self, text, fontSize=None, color=None, bgColor=(0, 51, 0, 0)) Draw text from current position, and at current angle. Parameters: `fontSize` - text font size. `color` - RGB tuple. color of text `bgColor` - background color

Class Variable Details

    ### BGCOLOR Type: `tuple` Value:
        (0, 0, 0)

    ### COLOR Type: `tuple` Value:
        (255, 255, 255)

Generated by Epydoc 2.0 on Sat Dec 9 14:11:19 2006 | http://epydoc.sf.net