예제 #1
0
def main():
    """Since 1 braille chars can represent 2*4 points we have to scale the board accordingly"""
    width, height = drawille.getTerminalSize()
    width, height = int((width*2.0)-2), int((height*4.0)-4)
    game = GameOfLife(width=width, height=height)
    
    def fill_board_randomly(game):
        def set_cell_randomly():
            if randrange(10) > randrange(6, 10): return 1
            return 0

        for y in range(game.height):
            for x in range(game.width):
                game.board[y][x] = set_cell_randomly()
        
    fill_board_randomly(game)             
    
    def frame_coordinates(game):
        while True:
            game.evolve_board()
            s = []
            for y in range(game.height):
                for x in range(game.width):
                    if game.board[y][x] == 1: s.append((x, y))

            yield s
     
    s = drawille.Canvas()
    drawille.animate(s, frame_coordinates, 1./5, game)
예제 #2
0

def clock():
    radius = 16

    while True:
        frame = []

        hour, minute, second = localtime()[3:6]

        hours = math.pi * (4 * hour / 24. - 1./2)
        minutes = math.pi * (2 * minute / 60. - 1. / 2)
        seconds = math.pi * (2 * second / 60. - 1. / 2)

        for angle, length in [(hours, radius / 2), (minutes, 3 * radius / 4),
                              (seconds, radius)]:
            frame.extend([c for c in line(radius,
                                          radius,
                                          radius + length * math.cos(angle),
                                          radius + length * math.sin(angle))])

        frame.extend([(radius + radius * math.cos(math.radians(x)),
                       radius + radius * math.sin(math.radians(x)))
                      for x in range(0, 360, 3)])

        yield frame


if __name__ == '__main__':
    animate(Canvas(), clock, 1./2)
예제 #3
0
# -*- coding: utf-8 -*-

from __future__ import print_function
from drawille import Canvas, line, animate
import math

def __main__():
    i = 0
    height = 40

    while True:
        frame = []

        frame.extend([coords for coords in
                      line(0,
                           height,
                           180,
                           math.sin(math.radians(i)) * height + height)])

        frame.extend([(x/2, height + math.sin(math.radians(x+i)) * height)
                      for x in range(0, 360, 2)])

        yield frame

        i += 2



if __name__ == '__main__':
    animate(Canvas(), __main__, 1./60)
예제 #4
0
    grid = grid_cls(pattern, n=x * 4 - 8, m=y * 2 - 4)

    i = 0
    while True:
        scr.addstr(x - 2, 0, f'generation: {i}')
        scr.addstr(x - 1, 0, f'population: {len(grid.live_cells)}')
        grid.tick()
        yield [
            (0, 0),
        ] + [(y, x) for x, y in grid.live_cells]
        i += 1


if __name__ == '__main__':
    parser = build_parser()
    args = parser.parse_args()

    stdscr = curses.initscr()
    curses.curs_set(False)

    canvas = Canvas()

    animate(
        canvas,
        play,
        args.speed,
        stdscr,
        PATTERN_MAP[args.pattern],
        is_toroidal=args.toroidal,
    )
예제 #5
0
from __future__ import print_function
from drawille import Canvas, line, animate
import math


def __main__():
    i = 0
    height = 40

    while True:
        frame = []

        frame.extend([
            coords
            for coords in line(0, height, 180,
                               math.sin(math.radians(i)) * height + height)
        ])

        frame.extend([(x / 2, height + math.sin(math.radians(x + i)) * height)
                      for x in range(0, 360, 2)])

        yield frame

        i += 2


if __name__ == '__main__':
    animate(Canvas(), __main__, 1. / 60)
예제 #6
0
    ft = omega / fps
    rotmat = array([[cos(ft), 0., -sin(ft)], [0., 1., 0.],
                    [sin(ft), 0., cos(ft)]])
    at = 0
    while True:
        frame = []
        frame.extend([coords for coords in line(bor, bor, bor, -bor)])
        frame.extend([coords for coords in line(bor, -bor, -bor, -bor)])
        frame.extend([coords for coords in line(-bor, -bor, -bor, bor)])
        frame.extend([coords for coords in line(-bor, bor, bor, bor)])
        for i in range(8):
            points[i] = matmul(rotmat, points[i])
        for edge in edges:
            x1 = float(points[edge[0]][0][0])
            y1 = float(points[edge[0]][1][0])
            z1 = float(points[edge[0]][2][0])
            x2 = float(points[edge[1]][0][0])
            y2 = float(points[edge[1]][1][0])
            z2 = float(points[edge[1]][2][0])

            obloc = o + wobble * sin((1 + sqrt(5)) * ft * at)
            x1p, y1p = drawproj(x1, y1, z1, obloc, s, o)
            x2p, y2p = drawproj(x2, y2, z2, obloc, s, o)
            frame.extend([coords for coords in line(x1p, y1p, x2p, y2p)])
        yield frame
        at += 1


if __name__ == '__main__':
    animate(Canvas(), __main__, 1 / fps)