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

Method register_shape

tools/python-3.11.9-amd64/Lib/turtle.py:1108–1141  ·  view source on GitHub ↗

Adds a turtle shape to TurtleScreen's shapelist. Arguments: (1) name is the name of a gif-file and shape is None. Installs the corresponding image shape. !! Image-shapes DO NOT rotate when turning the turtle, !! so they do not display the he

(self, name, shape=None)

Source from the content-addressed store, hash-verified

1106 self.update()
1107
1108 def register_shape(self, name, shape=None):
1109 """Adds a turtle shape to TurtleScreen's shapelist.
1110
1111 Arguments:
1112 (1) name is the name of a gif-file and shape is None.
1113 Installs the corresponding image shape.
1114 !! Image-shapes DO NOT rotate when turning the turtle,
1115 !! so they do not display the heading of the turtle!
1116 (2) name is an arbitrary string and shape is a tuple
1117 of pairs of coordinates. Installs the corresponding
1118 polygon shape
1119 (3) name is an arbitrary string and shape is a
1120 (compound) Shape object. Installs the corresponding
1121 compound shape.
1122 To use a shape, you have to issue the command shape(shapename).
1123
1124 call: register_shape("turtle.gif")
1125 --or: register_shape("tri", ((0,0), (10,10), (-10,10)))
1126
1127 Example (for a TurtleScreen instance named screen):
1128 >>> screen.register_shape("triangle", ((5,-3),(0,5),(-5,-3)))
1129
1130 """
1131 if shape is None:
1132 # image
1133 if name.lower().endswith(".gif"):
1134 shape = Shape("image", self._image(name))
1135 else:
1136 raise TurtleGraphicsError("Bad arguments for register_shape.\n"
1137 + "Use help(register_shape)" )
1138 elif isinstance(shape, tuple):
1139 shape = Shape("polygon", shape)
1140 ## else shape assumed to be Shape-instance
1141 self._shapes[name] = shape
1142
1143 def _colorstr(self, color):
1144 """Return color string corresponding to args.

Callers 1

mainFunction · 0.80

Calls 5

ShapeClass · 0.85
TurtleGraphicsErrorClass · 0.85
endswithMethod · 0.80
_imageMethod · 0.80
lowerMethod · 0.45

Tested by

no test coverage detected