MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / Shape

Class Shape

tools/python-3.11.9-amd64/Lib/turtle.py:871–915  ·  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

869
870
871class Shape(object):
872 """Data structure modeling shapes.
873
874 attribute _type is one of "polygon", "image", "compound"
875 attribute _data is - depending on _type a poygon-tuple,
876 an image or a list constructed using the addcomponent method.
877 """
878 def __init__(self, type_, data=None):
879 self._type = type_
880 if type_ == "polygon":
881 if isinstance(data, list):
882 data = tuple(data)
883 elif type_ == "image":
884 if isinstance(data, str):
885 if data.lower().endswith(".gif") and isfile(data):
886 data = TurtleScreen._image(data)
887 # else data assumed to be Photoimage
888 elif type_ == "compound":
889 data = []
890 else:
891 raise TurtleGraphicsError("There is no shape type %s" % type_)
892 self._data = data
893
894 def addcomponent(self, poly, fill, outline=None):
895 """Add component to a shape of type compound.
896
897 Arguments: poly is a polygon, i. e. a tuple of number pairs.
898 fill is the fillcolor of the component,
899 outline is the outline color of the component.
900
901 call (for a Shapeobject namend s):
902 -- s.addcomponent(((0,0), (10,10), (-10,10)), "red", "blue")
903
904 Example:
905 >>> poly = ((0,0),(10,-5),(0,10),(-10,-5))
906 >>> s = Shape("compound")
907 >>> s.addcomponent(poly, "red", "blue")
908 >>> # .. add more components and then use register_shape()
909 """
910 if self._type != "compound":
911 raise TurtleGraphicsError("Cannot add component to %s Shape"
912 % self._type)
913 if outline is None:
914 outline = fill
915 self._data.append([poly, fill, outline])
916
917
918class Tbuffer(object):

Callers 4

mainFunction · 0.90
__init__Method · 0.85
register_shapeMethod · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected