摩天轮动画(让物体绕圈移动)python

问题描述 投票:0回答:2

我正在尝试制作摩天轮动画(在面向对象编程的实践中),但我正在努力让马车围绕轮子旋转。

#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)

carriagemovement() 是我目前正在做的方式(但由于 if 语句,它偏离了圆圈,当我修复它(使用顶部和底部)时,它就停止了)。

有没有我没有使用的功能或方法可以让事情变得更容易?还有别的办法吗?

谢谢!!!

python windows animation geometry
2个回答
0
投票

将问题从“x,y”笛卡尔坐标转换为“角度,距离”极坐标可能更直观。然后,要绕圆移动,您只需增加角度即可。如果您仍然想从中获取 x,y 值,您可以简单地使用三角函数(正弦/余弦)对它们进行转换。


0
投票

哦,其实我也不知道!

© www.soinside.com 2019 - 2024. All rights reserved.