matrix.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:matrix 作者: bitcraft 项目源码 文件源码
def main():
    pygame.init()
    pygame.font.init()

    screen = init_screen(*screen_size)
    font = pygame.font.Font(font_name, font_size)
    clock = pygame.time.Clock()

    compute_curve()
    generate_images(font)
    init_grid(*screen_size)

    frame_number = 0
    running = True
    while running:
        if not save_to_disk:
            clock.tick(60)

        for event in pygame.event.get():
            if event.type == pygame.VIDEORESIZE:
                if not screen_size == (event.w, event.h):
                    screen = init_screen(event.w, event.h)
                    init_grid(event.w, event.h)
                    burn_set.clear()

            elif event.type == pygame.QUIT:
                running = False

        update_burners()

        # update and draw grid to the screen
        screen_blit = screen.blit
        for glyph in (i for i in glyphs if i.ttl):
            # have random chance to change the glyph
            if random() > .9:
                glyph.index = randrange(len(charset))

            # update the glyphs's life and image
            # if it becomes 0, then it won't be updated next frame
            glyph.ttl -= 1

            # get image and draw it
            screen_blit(cache[glyph.index][glyph.ttl], glyph.pos)

        screen_blit(logo, (0, 0), None, pygame.BLEND_RGBA_MULT)

        if save_to_disk:
            filename = "snapshot%05d.tga" % frame_number
            pygame.image.save(screen, filename)
            frame_number += 1

        else:
            pygame.display.flip()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号