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

Method register_shape

Python/Turtle.py:1006–1039  ·  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 heading

(self, name, shape=None)

Source from the content-addressed store, hash-verified

1004 self.update()
1005
1006 def register_shape(self, name, shape=None):
1007 """Adds a turtle shape to TurtleScreen's shapelist.
1008
1009 Arguments:
1010 (1) name is the name of a gif-file and shape is None.
1011 Installs the corresponding image shape.
1012 !! Image-shapes DO NOT rotate when turning the turtle,
1013 !! so they do not display the heading of the turtle!
1014 (2) name is an arbitrary string and shape is a tuple
1015 of pairs of coordinates. Installs the corresponding
1016 polygon shape
1017 (3) name is an arbitrary string and shape is a
1018 (compound) Shape object. Installs the corresponding
1019 compound shape.
1020 To use a shape, you have to issue the command shape(shapename).
1021
1022 call: register_shape("turtle.gif")
1023 --or: register_shape("tri", ((0,0), (10,10), (-10,10)))
1024
1025 Example (for a TurtleScreen instance named screen):
1026 >>> screen.register_shape("triangle", ((5,-3),(0,5),(-5,-3)))
1027
1028 """
1029 if shape is None:
1030 # image
1031 if name.lower().endswith(".gif"):
1032 shape = Shape("image", self._image(name))
1033 else:
1034 raise TurtleGraphicsError("Bad arguments for register_shape.\n"
1035 + "Use help(register_shape)" )
1036 elif isinstance(shape, tuple):
1037 shape = Shape("polygon", shape)
1038 ## else shape assumed to be Shape-instance
1039 self._shapes[name] = shape
1040
1041 def _colorstr(self, color):
1042 """Return color string corresponding to args.

Callers

nothing calls this directly

Calls 3

ShapeClass · 0.85
TurtleGraphicsErrorClass · 0.85
_imageMethod · 0.80

Tested by

no test coverage detected