Adds a turtle shape to TurtleScreen's shapelist. Arguments: (1) name is the name of an image file (PNG, GIF, PGM, and PPM) and shape is None. Installs the corresponding image shape. !! Image-shapes DO NOT rotate when turning the turtle, !! so they
(self, name, shape=None)
| 1096 | self.update() |
| 1097 | |
| 1098 | def register_shape(self, name, shape=None): |
| 1099 | """Adds a turtle shape to TurtleScreen's shapelist. |
| 1100 | |
| 1101 | Arguments: |
| 1102 | (1) name is the name of an image file (PNG, GIF, PGM, and PPM) and shape is None. |
| 1103 | Installs the corresponding image shape. |
| 1104 | !! Image-shapes DO NOT rotate when turning the turtle, |
| 1105 | !! so they do not display the heading of the turtle! |
| 1106 | (2) name is an arbitrary string and shape is the name of an image file (PNG, GIF, PGM, and PPM). |
| 1107 | Installs the corresponding image shape. |
| 1108 | !! Image-shapes DO NOT rotate when turning the turtle, |
| 1109 | !! so they do not display the heading of the turtle! |
| 1110 | (3) name is an arbitrary string and shape is a tuple |
| 1111 | of pairs of coordinates. Installs the corresponding |
| 1112 | polygon shape |
| 1113 | (4) name is an arbitrary string and shape is a |
| 1114 | (compound) Shape object. Installs the corresponding |
| 1115 | compound shape. |
| 1116 | To use a shape, you have to issue the command shape(shapename). |
| 1117 | |
| 1118 | call: register_shape("turtle.gif") |
| 1119 | --or: register_shape("tri", ((0,0), (10,10), (-10,10))) |
| 1120 | |
| 1121 | Example (for a TurtleScreen instance named screen): |
| 1122 | >>> screen.register_shape("triangle", ((5,-3),(0,5),(-5,-3))) |
| 1123 | |
| 1124 | """ |
| 1125 | if shape is None: |
| 1126 | shape = Shape("image", self._image(name)) |
| 1127 | elif isinstance(shape, str): |
| 1128 | shape = Shape("image", self._image(shape)) |
| 1129 | elif isinstance(shape, tuple): |
| 1130 | shape = Shape("polygon", shape) |
| 1131 | ## else shape assumed to be Shape-instance |
| 1132 | self._shapes[name] = shape |
| 1133 | |
| 1134 | def _colorstr(self, color): |
| 1135 | """Return color string corresponding to args. |