小编Sam*_*Sam的帖子

如何在Tkinter Canvas上的python中旋转多边形?

我正在使用Python和Tkinter创建一个小行星版本.按下左箭头键或右箭头键时,船需要旋转.这艘船是Tkinter帆布上的一个三角形.我无法想出公式来调整三角形的坐标.我相信它与罪和cos有关,尽管我并不完全确定.到目前为止,我有两个班级用于船舶,另一个用于游戏.在船类中,我有按键的回调方法.任何帮助将不胜感激.谢谢.

船级

import math
class Ship:
    def __init__(self,canvas,x,y,width,height):
        self.canvas = canvas
        self.x = x - width/2
        self.y = y + height/2
        self.width = width
        self.height = height

        self.x0 = self.x
        self.y0 = self.y

        self.x1 = self.x0 + self.width/2
        self.y1 = self.y0-self.height

        self.x2 = self.x0 + self.width
        self.y2 = self.y0

        self.ship = self.canvas.create_polygon((self.x0, self.y0, self.x1, self.y1, self.x2, self.y2), outline="white", width=3)
    def changeCoords(self):
        self.canvas.coords(self.ship,self.x0, self.y0, self.x1, self.y1, self.x2, self.y2)
    def rotateLeft(self, event=None):
        # Should rotate one degree left.
        pass
    def rotateRight(self, event=None): …
Run Code Online (Sandbox Code Playgroud)

python tkinter vector

8
推荐指数
1
解决办法
9011
查看次数

标签 统计

python ×1

tkinter ×1

vector ×1