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.
| 862 | |
| 863 | |
| 864 | class Shape(object): |
| 865 | """Data structure modeling shapes. |
| 866 | |
| 867 | attribute _type is one of "polygon", "image", "compound" |
| 868 | attribute _data is - depending on _type a poygon-tuple, |
| 869 | an image or a list constructed using the addcomponent method. |
| 870 | """ |
| 871 | def __init__(self, type_, data=None): |
| 872 | self._type = type_ |
| 873 | if type_ == "polygon": |
| 874 | if isinstance(data, list): |
| 875 | data = tuple(data) |
| 876 | elif type_ == "image": |
| 877 | assert(isinstance(data, TK.PhotoImage)) |
| 878 | elif type_ == "compound": |
| 879 | data = [] |
| 880 | else: |
| 881 | raise TurtleGraphicsError("There is no shape type %s" % type_) |
| 882 | self._data = data |
| 883 | |
| 884 | def addcomponent(self, poly, fill, outline=None): |
| 885 | """Add component to a shape of type compound. |
| 886 | |
| 887 | Arguments: poly is a polygon, i. e. a tuple of number pairs. |
| 888 | fill is the fillcolor of the component, |
| 889 | outline is the outline color of the component. |
| 890 | |
| 891 | call (for a Shapeobject namend s): |
| 892 | -- s.addcomponent(((0,0), (10,10), (-10,10)), "red", "blue") |
| 893 | |
| 894 | Example: |
| 895 | >>> poly = ((0,0),(10,-5),(0,10),(-10,-5)) |
| 896 | >>> s = Shape("compound") |
| 897 | >>> s.addcomponent(poly, "red", "blue") |
| 898 | >>> # .. add more components and then use register_shape() |
| 899 | """ |
| 900 | if self._type != "compound": |
| 901 | raise TurtleGraphicsError("Cannot add component to %s Shape" |
| 902 | % self._type) |
| 903 | if outline is None: |
| 904 | outline = fill |
| 905 | self._data.append([poly, fill, outline]) |
| 906 | |
| 907 | |
| 908 | class Tbuffer(object): |
no outgoing calls
no test coverage detected
searching dependent graphs…