MCPcopy Index your code
hub / github.com/python/cpython / setworldcoordinates

Method setworldcoordinates

Lib/turtle.py:1059–1096  ·  view source on GitHub ↗

Set up a user defined coordinate-system. Arguments: llx -- a number, x-coordinate of lower left corner of canvas lly -- a number, y-coordinate of lower left corner of canvas urx -- a number, x-coordinate of upper right corner of canvas ury -- a number, y-coor

(self, llx, lly, urx, ury)

Source from the content-addressed store, hash-verified

1057 self.reset()
1058
1059 def setworldcoordinates(self, llx, lly, urx, ury):
1060 """Set up a user defined coordinate-system.
1061
1062 Arguments:
1063 llx -- a number, x-coordinate of lower left corner of canvas
1064 lly -- a number, y-coordinate of lower left corner of canvas
1065 urx -- a number, x-coordinate of upper right corner of canvas
1066 ury -- a number, y-coordinate of upper right corner of canvas
1067
1068 Set up user coodinat-system and switch to mode 'world' if necessary.
1069 This performs a screen.reset. If mode 'world' is already active,
1070 all drawings are redrawn according to the new coordinates.
1071
1072 But ATTENTION: in user-defined coordinatesystems angles may appear
1073 distorted. (see Screen.mode())
1074
1075 Example (for a TurtleScreen instance named screen):
1076 >>> screen.setworldcoordinates(-10,-0.5,50,1.5)
1077 >>> for _ in range(36):
1078 ... left(10)
1079 ... forward(0.5)
1080 """
1081 if self.mode() != "world":
1082 self.mode("world")
1083 xspan = float(urx - llx)
1084 yspan = float(ury - lly)
1085 wx, wy = self._window_size()
1086 self.screensize(wx-20, wy-20)
1087 oldxscale, oldyscale = self.xscale, self.yscale
1088 self.xscale = self.canvwidth / xspan
1089 self.yscale = self.canvheight / yspan
1090 srx1 = llx * self.xscale
1091 sry1 = -ury * self.yscale
1092 srx2 = self.canvwidth + srx1
1093 sry2 = self.canvheight + sry1
1094 self._setscrollregion(srx1, sry1, srx2, sry2)
1095 self._rescale(self.xscale/oldxscale, self.yscale/oldyscale)
1096 self.update()
1097
1098 def register_shape(self, name, shape=None):
1099 """Adds a turtle shape to TurtleScreen's shapelist.

Callers 1

mainFunction · 0.80

Calls 6

modeMethod · 0.95
screensizeMethod · 0.95
updateMethod · 0.95
_window_sizeMethod · 0.80
_setscrollregionMethod · 0.80
_rescaleMethod · 0.45

Tested by

no test coverage detected