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)
| 2809 | self.settiltangle(angle + self.tiltangle()) |
| 2810 | |
| 2811 | def shapetransform(self, t11=None, t12=None, t21=None, t22=None): |
| 2812 | """Set or return the current transformation matrix of the turtle shape. |
| 2813 | |
| 2814 | Optional arguments: t11, t12, t21, t22 -- numbers. |
| 2815 | |
| 2816 | If none of the matrix elements are given, return the transformation |
| 2817 | matrix. |
| 2818 | Otherwise set the given elements and transform the turtleshape |
| 2819 | according to the matrix consisting of first row t11, t12 and |
| 2820 | second row t21, 22. |
| 2821 | Modify stretchfactor, shearfactor and tiltangle according to the |
| 2822 | given matrix. |
| 2823 | |
| 2824 | Examples (for a Turtle instance named turtle): |
| 2825 | >>> turtle.shape("square") |
| 2826 | >>> turtle.shapesize(4,2) |
| 2827 | >>> turtle.shearfactor(-0.5) |
| 2828 | >>> turtle.shapetransform() |
| 2829 | (4.0, -1.0, -0.0, 2.0) |
| 2830 | """ |
| 2831 | if t11 is t12 is t21 is t22 is None: |
| 2832 | return self._shapetrafo |
| 2833 | m11, m12, m21, m22 = self._shapetrafo |
| 2834 | if t11 is not None: m11 = t11 |
| 2835 | if t12 is not None: m12 = t12 |
| 2836 | if t21 is not None: m21 = t21 |
| 2837 | if t22 is not None: m22 = t22 |
| 2838 | if t11 * t22 - t12 * t21 == 0: |
| 2839 | raise TurtleGraphicsError("Bad shape transform matrix: must not be singular") |
| 2840 | self._shapetrafo = (m11, m12, m21, m22) |
| 2841 | alfa = math.atan2(-m21, m11) % (2 * math.pi) |
| 2842 | sa, ca = math.sin(alfa), math.cos(alfa) |
| 2843 | a11, a12, a21, a22 = (ca*m11 - sa*m21, ca*m12 - sa*m22, |
| 2844 | sa*m11 + ca*m21, sa*m12 + ca*m22) |
| 2845 | self._stretchfactor = a11, a22 |
| 2846 | self._shearfactor = a12/a22 |
| 2847 | self._tilt = alfa |
| 2848 | self.pen(resizemode="user") |
| 2849 | |
| 2850 | |
| 2851 | def _polytrafo(self, poly): |
nothing calls this directly
no test coverage detected