简体   繁体   English

如何在python中旋转龟形状

[英]how to rotate turtle shape in python

I registered the shape of my turtle in my roulette game to a roulette wheel. 我在轮盘赌游戏中将我的龟的形状记录到轮盘赌轮上。 I want the wheel to spin 3 times. 我想让车轮旋转3次。 This is my program: 这是我的计划:

register_shape("wheel.gif")
wheel = None
wheel = turtle.Turtle()
wheel.ht()
wheel.shape("wheel.gif")


wheel.shapesize(5, 5)
wheel.pu()
wheel.ht()
wheel.goto(-200,-200)
wheel.st()
r = 1
for r in range(108):
    wheel.right(10)

The wheel shows up properly but it doesn't seem to spin. 车轮正确显示但似乎没有旋转。 I would assume this should work. 我认为这应该工作。 If not is there any other way. 如果没有,还有其他办法吗? Thank you. 谢谢。

I had the same issue with Python turtle graphics. 我遇到了与Python龟图相同的问题。 I circumvented it by registering different images in different rotational states. 我通过在不同的旋转状态下记录不同的图像来规避它。 Then you can use conditional statements to show a suitable image in each partcular state. 然后,您可以使用条件语句在每个部分状态中显示合适的图像。 Hope it helps! 希望能帮助到你!

I found that this will not be possible, according to the documentation of the register_shape() method: 根据register_shape()方法的文档,我发现这是不可能的:

Note: Image shapes do not rotate when turning the turtle, so they do not display the heading of the turtle! 注意:转动乌龟时图像形状不会旋转,因此它们不会显示乌龟的标题!

Reference: http://docs.python.org/library/turtle.html#turtle.register_shape 参考: http//docs.python.org/library/turtle.html#turtle.register_shape


However, it seems that there are two other ways to use register_shape() which should provide rotation, since the above disclaimer only refers to image shapes. 然而,似乎有两个其他方式使用register_shape() 提供旋转,因为上述声明仅是指图像的形状。

  1. Using coordinates to draw a polygon shape. 使用坐标绘制多边形形状。
  2. Using a compound shape object (a compound shape consists of multiple polygons). 使用复合形状对象(复合形状由多个多边形组成)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM