Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Attributes
turtle.Shape Class Reference
Inheritance diagram for turtle.Shape:
Inheritance graph
[legend]
Collaboration diagram for turtle.Shape:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def addcomponent

Public Attributes

_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Private Attributes

 _type
 _data

Detailed Description

Data structure modeling shapes.

attribute _type is one of "polygon", "image", "compound"
attribute _data is - depending on _type a poygon-tuple,
an image or a list constructed using the addcomponent method.

Definition at line 871 of file turtle.py.


Constructor & Destructor Documentation

def turtle.Shape.__init__ (   self,
  type_,
  data = None 
)

Definition at line 878 of file turtle.py.

00878 
00879     def __init__(self, type_, data=None):
00880         self._type = type_
00881         if type_ == "polygon":
00882             if isinstance(data, list):
00883                 data = tuple(data)
00884         elif type_ == "image":
00885             if isinstance(data, str):
00886                 if data.lower().endswith(".gif") and isfile(data):
00887                     data = TurtleScreen._image(data)
00888                 # else data assumed to be Photoimage
00889         elif type_ == "compound":
00890             data = []
00891         else:
00892             raise TurtleGraphicsError("There is no shape type %s" % type_)
00893         self._data = data

Here is the caller graph for this function:


Member Function Documentation

def turtle.Shape.addcomponent (   self,
  poly,
  fill,
  outline = None 
)
Add component to a shape of type compound.

Arguments: poly is a polygon, i. e. a tuple of number pairs.
fill is the fillcolor of the component,
outline is the outline color of the component.

call (for a Shapeobject namend s):
--   s.addcomponent(((0,0), (10,10), (-10,10)), "red", "blue")

Example:
>>> poly = ((0,0),(10,-5),(0,10),(-10,-5))
>>> s = Shape("compound")
>>> s.addcomponent(poly, "red", "blue")
### .. add more components and then use register_shape()

Definition at line 894 of file turtle.py.

00894 
00895     def addcomponent(self, poly, fill, outline=None):
00896         """Add component to a shape of type compound.
00897 
00898         Arguments: poly is a polygon, i. e. a tuple of number pairs.
00899         fill is the fillcolor of the component,
00900         outline is the outline color of the component.
00901 
00902         call (for a Shapeobject namend s):
00903         --   s.addcomponent(((0,0), (10,10), (-10,10)), "red", "blue")
00904 
00905         Example:
00906         >>> poly = ((0,0),(10,-5),(0,10),(-10,-5))
00907         >>> s = Shape("compound")
00908         >>> s.addcomponent(poly, "red", "blue")
00909         ### .. add more components and then use register_shape()
00910         """
00911         if self._type != "compound":
00912             raise TurtleGraphicsError("Cannot add component to %s Shape"
00913                                                                 % self._type)
00914         if outline is None:
00915             outline = fill
00916         self._data.append([poly, fill, outline])
00917 


Member Data Documentation

turtle.Shape._data [private]

Definition at line 892 of file turtle.py.

turtle.Shape._type [private]

Definition at line 879 of file turtle.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.


The documentation for this class was generated from the following file: