Esempio n. 1
0
def draw_background(palette: GraphWin):
    _height = palette.getHeight()
    _width = palette.getWidth()

    sky_percentage = 0.7

    sky = get_rectangle(gr.Point(0, _height * sky_percentage), _width, _height * sky_percentage)
    land = get_rectangle(gr.Point(0, _height), _width, _height * (1 - sky_percentage))
    sun = gr.Circle(gr.Point(_width * 0.85, _height * 0.15), _height * 0.1)

    sky.setFill(gr.color_rgb(0, 0, 200))
    land.setFill(gr.color_rgb(80, 240, 20))
    sun.setFill(gr.color_rgb(255, 255, 0))

    sky.draw(palette)
    land.draw(palette)
    sun.draw(palette)

    sky_shift = _height * 0.15
    for i in range(5):
        cloud = gr.Circle(gr.Point(0 + sky_shift, _height * 0.15), _height * 0.05)
        cloud.setFill(gr.color_rgb(255, 255, 255))
        cloud.draw(palette)
        sky_shift += _height * 0.1 / 2
    sky_shift = _height * 0.175
    for i in range(4):
        cloud = gr.Circle(gr.Point(0 + sky_shift, _height * 0.10), _height * 0.05)
        cloud.setFill(gr.color_rgb(255, 255, 255))
        cloud.draw(palette)
        sky_shift += _height * 0.1 / 2
Esempio n. 2
0
def setup(keybinds: Keybindings, square_size: int) -> Tuple[State, GraphWin]:
    '''
    Initializes the graphics and the list representing the grid
    '''
    rows, cols = (4, 9)
    start = (0, 4)

    grid_height = 0
    row_scale = rows * square_size
    if row_scale < 350:
        grid_height = 350
    else:
        grid_height = row_scale

    grid_width = 0
    col_scale = cols * square_size
    if col_scale < 350:
        grid_width = 350
    else:
        grid_width = col_scale

    # set up initial window
    win = GraphWin("Robot", grid_width, grid_height, autoflush=False)
    win.setBackground("green")

    help_str = '\n'.join(
        map(
            lambda item: 'Press {keys} to {desc}'.format(
                keys=', '.join(item[0]), desc=item[1][1]), keybinds.items()))
    help_text = Text(Point(win.getWidth() / 2,
                           win.getHeight() / 5 * 4), help_str)
    help_text.setFill("white")
    help_text.draw(win)

    return (State((rows, cols), start, Facing.RIGHT), win)
Esempio n. 3
0
def main():
    win = GraphWin('Smartass Buster', 600, 800)
    exit_txt = Text(Point(win.getWidth() - 60,
                          win.getHeight() - 15), 'COMPUTE')
    exit_txt.draw(win)

    tri_thing = draw(win)

    if tri_thing:
        result = tri_thing.triangles()
    else:
        result = 0

    result1_txt = Text(Point(100,
                             win.getHeight() - 45), 'This figure contains')
    result2_txt = Text(Point(100,
                             win.getHeight() - 15),
                       '{} triangles'.format(result))
    result1_txt.draw(win)
    result2_txt.draw(win)
    win.getMouse()