示例#1
0
        turt.setheading(heading)
        turt.right(90)
        turt.forward(base / 2)
        turt.left(180 - angle)
        turt.forward(side)
        turt.left(2 * angle)
        turt.forward(side)
        turt.left(180 - angle)
        turt.forward(base / 2)


class VisualPopulation(Population):
    def __init__(self, size):
        super().__init__(size)
        self.elements = [VisualElement() for _ in range(size)]

    def update(self, turt):
        super().update()
        for elem in self.elements:
            elem.show(turt)


if __name__ == "__main__":
    t = turtle.Turtle()
    pop = VisualPopulation(5)
    for elem in pop.elements:
        elem.velocity = Vector.random()
    pop.update(t)

    turtle.mainloop()
示例#2
0
 def __init__(self, position: Vector = None, velocity: Vector = None):
     self.position: Vector = position \
         if position is not None else Vector.random()
     self.velocity: Vector = velocity \
         if velocity is not None else Vector.zero()
     self.acceleration: Vector = Vector.zero()