Ejemplo n.º 1
0
def main():
    pygame.init()

    clock = pygame.time.Clock()
    fps = 60

    res = wid, hi = 1440, 870
    d_surf = pygame.display.set_mode(res)

    point = Point(wid / 2, hi / 2)
    n = 7
    max_dep = 5

    cols = Colours((0, 0, 0), (255, 0, 0), (255, 165, 0), (255, 255, 0),
                   (0, 0, 0), (0, 0, 0), (0, 0, 40), (255, 255, 255))

    col_spd = 2

    branch_list = []
    for i in range(n):
        branch = Branch(point,
                        angle=360 / n * i,
                        dev=90 / n,
                        dst=150,
                        max_dep=max_dep)
        branch_list.append(branch)

    set_colours(branch_list, cols)

    while True:

        cols.inc_colours(col_spd)
        d_surf.fill((0, 0, 0))
        for branch in branch_list:  # PH code to test methods: a better gen method reqd!
            branch.push_angles()
            branch.inc_tree_angle(
                -0.4)  # all works now, but order is important!
            branch.inc_angle(4, 3)
            branch.inc_angle(-2, 4)  # push_angle first
            branch.inc_tree_dev(0.08)  # then angle ops, tree-wide first
            branch.inc_dev(-0.8, 2)  # then dev ops, tree-wide first.
            branch.propagate()  # then propagate.
            # draw_circles(d_surf, branch, max_dep)
            draw_branch(d_surf, branch, cols)

        for e in pygame.event.get():
            if e.type == QUIT or e.type == KEYDOWN and e.key == 27:
                pygame.quit()
                sys.exit()

        pygame.display.update()
        clock.tick(fps)