Set or return the current transformation matrix of the turtle shape. Optional arguments: t11, t12, t21, t22 -- numbers. If none of the matrix elements are given, return the transformation matrix. Otherwise set the given elements and transform the turtleshape
(self, t11=None, t12=None, t21=None, t22=None)
| 2927 | self.tiltangle(angle + self.tiltangle()) |
| 2928 | |
| 2929 | def shapetransform(self, t11=None, t12=None, t21=None, t22=None): |
| 2930 | """Set or return the current transformation matrix of the turtle shape. |
| 2931 | |
| 2932 | Optional arguments: t11, t12, t21, t22 -- numbers. |
| 2933 | |
| 2934 | If none of the matrix elements are given, return the transformation |
| 2935 | matrix. |
| 2936 | Otherwise set the given elements and transform the turtleshape |
| 2937 | according to the matrix consisting of first row t11, t12 and |
| 2938 | second row t21, 22. |
| 2939 | Modify stretchfactor, shearfactor and tiltangle according to the |
| 2940 | given matrix. |
| 2941 | |
| 2942 | Examples (for a Turtle instance named turtle): |
| 2943 | >>> turtle.shape("square") |
| 2944 | >>> turtle.shapesize(4,2) |
| 2945 | >>> turtle.shearfactor(-0.5) |
| 2946 | >>> turtle.shapetransform() |
| 2947 | (4.0, -1.0, -0.0, 2.0) |
| 2948 | """ |
| 2949 | if t11 is t12 is t21 is t22 is None: |
| 2950 | return self._shapetrafo |
| 2951 | m11, m12, m21, m22 = self._shapetrafo |
| 2952 | if t11 is not None: m11 = t11 |
| 2953 | if t12 is not None: m12 = t12 |
| 2954 | if t21 is not None: m21 = t21 |
| 2955 | if t22 is not None: m22 = t22 |
| 2956 | if t11 * t22 - t12 * t21 == 0: |
| 2957 | raise TurtleGraphicsError("Bad shape transform matrix: must not be singular") |
| 2958 | self._shapetrafo = (m11, m12, m21, m22) |
| 2959 | alfa = math.atan2(-m21, m11) % math.tau |
| 2960 | sa, ca = math.sin(alfa), math.cos(alfa) |
| 2961 | a11, a12, a21, a22 = (ca*m11 - sa*m21, ca*m12 - sa*m22, |
| 2962 | sa*m11 + ca*m21, sa*m12 + ca*m22) |
| 2963 | self._stretchfactor = a11, a22 |
| 2964 | self._shearfactor = a12/a22 |
| 2965 | self._tilt = alfa |
| 2966 | self.pen(resizemode="user") |
| 2967 | |
| 2968 | |
| 2969 | def _polytrafo(self, poly): |
nothing calls this directly
no test coverage detected