pygame 中的参数方程的行为与预期不符

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

在 Pygame 中输入参数方程作为对象的路径会导致与预期不同的行为。

我正在尝试用 Python 编写一个小游戏。我想尝试让 sprite 进入 蝴蝶曲线的形状。 Butterfly Curve

我写了 x 和 y 的参数方程,但绘制它会产生其他结果。My butterfly

我无法弄清楚为什么会这样,但如果我不得不猜测,Pyhon 运行代码的方式可能存在问题。该图并不完全对称,所以问题可能出在 Python 在不同的时间点执行代码,从而扭曲了行为?或者这可能是一个敏感性问题, 哪里的输入需要非常精确才能使行为按预期发生?不管怎样,我觉得这真的很有趣,我希望有人能给我指出正确的方向,让我开始思考这个问题。

    def butterfly_move(self):
        t = math.radians(pg.time.get_ticks() / 100)

        """Parametric equations for the butterfly curve"""
        x = math.sin(t) * (math.exp(math.cos(t) - (2*(math.cos(4*t)) + pow(math.sin(t/12),5)))) 
        y = math.cos(t) * (math.exp(math.cos(t) - (2*(math.cos(4*t)) + pow(math.sin(t/12),5))))

        self.direction = pg.math.Vector2(x,y)
        self.rect.center += self.direction * 20
python pygame game-physics parametric-equations
© www.soinside.com 2019 - 2024. All rights reserved.