MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / Shape

Class Shape

Python/Turtle.py:769–813  ·  view source on GitHub ↗

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.

Source from the content-addressed store, hash-verified

767
768
769class Shape(object):
770 """Data structure modeling shapes.
771
772 attribute _type is one of "polygon", "image", "compound"
773 attribute _data is - depending on _type a poygon-tuple,
774 an image or a list constructed using the addcomponent method.
775 """
776 def __init__(self, type_, data=None):
777 self._type = type_
778 if type_ == "polygon":
779 if isinstance(data, list):
780 data = tuple(data)
781 elif type_ == "image":
782 if isinstance(data, str):
783 if data.lower().endswith(".gif") and isfile(data):
784 data = TurtleScreen._image(data)
785 # else data assumed to be Photoimage
786 elif type_ == "compound":
787 data = []
788 else:
789 raise TurtleGraphicsError("There is no shape type %s" % type_)
790 self._data = data
791
792 def addcomponent(self, poly, fill, outline=None):
793 """Add component to a shape of type compound.
794
795 Arguments: poly is a polygon, i. e. a tuple of number pairs.
796 fill is the fillcolor of the component,
797 outline is the outline color of the component.
798
799 call (for a Shapeobject namend s):
800 -- s.addcomponent(((0,0), (10,10), (-10,10)), "red", "blue")
801
802 Example:
803 >>> poly = ((0,0),(10,-5),(0,10),(-10,-5))
804 >>> s = Shape("compound")
805 >>> s.addcomponent(poly, "red", "blue")
806 >>> # .. add more components and then use register_shape()
807 """
808 if self._type != "compound":
809 raise TurtleGraphicsError("Cannot add component to %s Shape"
810 % self._type)
811 if outline is None:
812 outline = fill
813 self._data.append([poly, fill, outline])
814
815
816class Tbuffer(object):

Callers 2

__init__Method · 0.85
register_shapeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected