Advertisement

Python学习使用turtle模块

阅读量:

地球绕太阳运行的轨迹示意图:

复制代码
    from turtle import Shape, Turtle, mainloop, Vec2D as Vec
    class GravSys(object):
    def __init__(self):
        self.planets = []
        self.t = 0
        self.dt = 0.01
    def init(self):
        for p in self.planets:
            p.init()
    def start(self):
        for i in range(10000):
            self.t += self.dt
            for p in self.planets:
                p.step()
    class Star(Turtle):
    def __init__(self, m, x, v, gravSys, shape):
        Turtle.__init__(self, shape=shape)
        self.penup()
        self.m = m
        self.setpos(x)

全部评论 (0)

还没有任何评论哟~