摩天轮动画(使物体在一个圆圈中移动)python

摩天轮动画(使物体在一个圆圈中移动)python,python,windows,animation,geometry,Python,Windows,Animation,Geometry,我试图制作一个摩天轮动画(在面向对象编程的实践中),但我很难让马车绕着轮子转 #ferris wheel(circle) pygame.draw.circle(screen, blue, [250,250],150, 8) #carriage pygame.draw.polygon(screen, yellow, [[220+cx,385+cy],[280+cx,385+cy],[270+cx,400+cy],[230+cx,400+cy]],0) def carriagemovement(

我试图制作一个摩天轮动画(在面向对象编程的实践中),但我很难让马车绕着轮子转

#ferris wheel(circle)
pygame.draw.circle(screen, blue, [250,250],150, 8)

#carriage
pygame.draw.polygon(screen, yellow, [[220+cx,385+cy],[280+cx,385+cy],[270+cx,400+cy],[230+cx,400+cy]],0)

def carriagemovement(top,bottom):

global cx
global cy
top = 0
bottom = 1
if bottom == 1:
    if cx == 0 or cx < 80:
        cx = cx + 4
        cy = cy - 1
        print(cx)
else:
    if bottom == 1:
        if cx == 80 or ( cx > 80 and cx < 148):
            cx = cx + 4
            cy = cy - 3
            print (cx)
    else:
        if bottom ==1:
            if cx == 148 or (cx > 148 and cx < 159):
                cx = cx + 0.5
                cy = cy - 3
                print (cx)
        else:
            top = 1
            bottom = 0
            if top == 1:
                if (cx == 159 and top == 1) or (cx < 159 and top == 1):
                    cx = cx - 0.5
                    cy = cy - 3
                    print (cx)
#摩天轮(圆形)
pygame.draw.circle(屏幕,蓝色,[250250],150,8)
#马车
pygame.draw.polygon(屏幕,黄色,[[220+cx,385+cy],[280+cx,385+cy],[270+cx,400+cy],[230+cx,400+cy]],0)
def机架移动(顶部、底部):
全球cx
全球cy
top=0
底部=1
如果底部==1:
如果cx==0或cx<80:
cx=cx+4
cy=cy-1
打印(cx)
其他:
如果底部==1:
如果cx==80或(cx>80且cx<148):
cx=cx+4
cy=cy-3
打印(cx)
其他:
如果底部==1:
如果cx==148或(cx>148且cx<159):
cx=cx+0.5
cy=cy-3
打印(cx)
其他:
top=1
底部=0
如果top==1:
如果(cx==159和top==1)或(cx<159和top==1):
cx=cx-0.5
cy=cy-3
打印(cx)
carinemovement()是我目前正在做的事情(但由于if语句,它偏离了圆圈,当我修复它时(使用top和bottom),它只是短暂停止)

是否有一个函数或方法我没有使用,这将使它更容易?还有别的办法吗


谢谢

将问题从“x,y”笛卡尔坐标转换为“角度,距离”极坐标可能更直观。然后围绕圆移动,只需增加角度。如果你仍然想从中得到x,y值,你可以简单地用三角学(正弦/余弦)变换它们。

谢谢,这更有意义!但是你能给我举个例子吗?我还没有做过极坐标