def main():
    canvas = Canvas()
    black = True
    for x in range(SQUARES):
        draw_square(canvas, x, black)
        black = not black
    canvas.mainloop()
Пример #2
0
def main():
    canvas = Canvas()
    black = True
    y = 0
    while y * SQUARE_SIZE <= canvas.get_canvas_height():
        for x in range(SQUARES):
            draw_square(canvas, x, y, black)
            black = not black
        black = not black
        y += 1
    canvas.mainloop()
Пример #3
0
def main():
    """
    Goes through one normal day. Sets up canvas, house, schedule,
    and goes through three classes!
    dialog box credit: https://stackoverflow.com/a/62672469 & https://djangocentral.com/creating-user-input-dialog/
    music code credit: https://opensource.com/article/20/9/add-sound-python-game
    resize credit: https://www.codegrepper.com/code-examples/delphi/how+to+resize+image+in+python+tkinter
    """

    canvas = Canvas(WINDOW_WIDTH, WINDOW_HEIGHT, 'Hogwarts')

    # background music
    s = 'sound'
    pygame.mixer.init()
    pygame.mixer.music.load(os.path.join('HarryPotterMusic.mp3'))
    pygame.mixer.music.play(-1)
    pygame.mixer.music.set_volume(0.5)

    # sets up house
    sorting = opening_scene(canvas)
    house_points = 0

    # fonts
    title = Font(family='4 Privet Drive', size='60')
    classes = Font(family='DearMrPotter', size='30')
    bold = Font(family='4 Privet Drive', size='25', underline=1, weight='bold')

    # NARRATOR: welcome to first day of classes
    between_classes(canvas, bold, "Welcome to your first day of school! You will receive your schedule shortly.")

    # creates schedule
    create_schedule(canvas, title, classes, bold)

    # NARRATOR: go to charms
    between_classes(canvas, bold, "Today is Monday and you have Charms first! Let's go before you're late.")

    # charms class
    house_points = charms_lesson(canvas, sorting, house_points)

    # NARRATOR:
    between_classes(canvas, bold, "Time for Transfiguration with Professor McGonagall!")

    # transfiguration class
    house_points = transfiguration_lesson(canvas, sorting, house_points)
    between_classes(canvas, bold, "Time for Defense Against the Dark Arts with Professor Lupin!")

    # defense against the dark arts
    house_points = dada_lesson(canvas, sorting, house_points)

    # finale
    ending(canvas, bold, sorting, house_points)

    canvas.mainloop()
Пример #4
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Short Film")

    # FILM BEGINS...

    display_message(canvas, 'Once upon a time...')
    create_air_and_ground(canvas)
    sun = create_sun(canvas)
    get_sun_color(canvas, sun)

    # FILM ENDS...

    display_message(canvas, 'The end...')
Пример #5
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Debris Sweeper")

    create_debris(canvas)
    while True:
        clicks = canvas.get_new_mouse_clicks()
        for click in clicks:
            remove_debris(canvas, click.x, click.y)
        canvas.update()

    canvas.mainloop()
Пример #6
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Hole Puncher")

    # animation loop
    while True:
        clicks = canvas.get_new_mouse_clicks()
        for click in clicks:
            draw_hole(canvas, click.x, click.y)
        canvas.update()

    canvas.mainloop()
Пример #7
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Making Tracks")

    # TODO: your code here!

    while True:
        clicks = canvas.get_new_mouse_clicks()

        for click in clicks:
            load_image(click.x, click.y, canvas)
        canvas.update()

    canvas.mainloop()
Пример #8
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Debris Sweeper")

    # The list of all rockets on the canvas
    rocket_list = []
    paddle = create_paddle(canvas)
    canvas.update()

    while True:
        update_paddle_location(canvas, paddle)
        check_for_new_rockets(canvas, rocket_list)
        animate_rockets(canvas, rocket_list)

        canvas.update()
        time.sleep(ANIMATION_DELAY_SECONDS)

    canvas.mainloop()
Пример #9
0
def main():
    canvas = Canvas(CANVAS_WIDTH, CANVAS_HEIGHT)
    canvas.set_canvas_title("String Art")

    height = canvas.get_canvas_height()

    for i in range(1, NUM_LINES + 1):
        a = i * LINE_SPACING

        x1 = a
        y2 = a

        canvas.create_line(x1, height, 0, y2)

    canvas.mainloop()
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Catch Me If You Can")

    diss = create_dis(canvas)
    sneaky = create_sneaky(canvas)
    finished = False

    while not finished:
        clicks = canvas.get_new_mouse_clicks()
        for i in clicks:
            finished = hit(canvas, i, sneaky)
            if not finished:
                sneaky = recreate_game(canvas, diss, sneaky)
        canvas.update()

    canvas.mainloop()
Пример #11
0
def main():
    canvas = Canvas(CANVAS_WIDTH, CANVAS_HEIGHT)
    canvas.set_canvas_title("Illusion 2")

    for row in range(NUM_ROWS):
        draw_square(canvas, row)

    canvas.mainloop()
Пример #12
0
def main():
    # Feel free to remove this graphics code if you are not using graphics
    canvas = Canvas()
    canvas.set_canvas_title("Final Project")

    # TODO: your code here!

    canvas.mainloop()
Пример #13
0
def main():
    canvas = Canvas(CANVAS_WIDTH, CANVAS_HEIGHT)
    canvas.set_canvas_title("Illusion 1")

    for x in range(CANVAS_WIDTH // SIZE):
        for y in range(CANVAS_HEIGHT // SIZE):
            draw_square(canvas, x, y)

    canvas.mainloop()
Пример #14
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Robot Face")

    draw_head(canvas)
    draw_mouth(canvas)
    draw_eyes(canvas)
    draw_label(canvas)

    canvas.mainloop()
Пример #15
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Draw People")

    draw_person(canvas, 50, 150)
    draw_person(canvas, 100, 300)
    draw_person(canvas, 500, 200)
    draw_person(canvas, 300, 250)
    draw_person(canvas, 700, 310)

    canvas.mainloop()
Пример #16
0
def main():
    """
    You should write your code between the two lines written
    already that set up the canvas.
    You should replace this comment with a better, more descriptive one.
    """
    canvas = Canvas(CANVAS_WIDTH, CANVAS_HEIGHT)
    canvas.set_canvas_title("Breakout")

    # TODO: your code here

    canvas.mainloop()
Пример #17
0
def main():
  canvas = Canvas()
  canvas.set_canvas_title("Draw Robot Face")

  ## Start of your code
  draw_head(canvas)
  draw_mouth(canvas)
  draw_eyes(canvas)
  draw_label(canvas)
  ## End of your code

  canvas.mainloop()
Пример #18
0
def main():
    """
    You should write your code between the two lines written
    already that set up the canvas.
    You should replace this comment with a better, more descriptive one.
    """
    canvas = Canvas()
    canvas.set_canvas_title("Random Circles")

    # TODO: your code here

    canvas.mainloop()
Пример #19
0
def main():
    canvas = Canvas()
    canvas.set_canvas_background_color('lime')
    balls = []
    add_ball(canvas, balls)
    while True:
        if random.randint(0, 100) > 98:
            add_ball(canvas, balls)
        animation_step(canvas, balls)
        stop_balls_out(canvas, balls)
        sleep(1 / 90)
        canvas.update()
Пример #20
0
class Program:
    HOLE_RADIUS = 10
    canvas = Canvas()

    def main(self):
        self.canvas.set_canvas_title("Hole Puncher")
        self.canvas.set_on_mouse_pressed(self.draw_hole)
        self.canvas.mainloop()

    def draw_hole(self, x, y):
        """
        Draws a circle on the canvas centered at the given location.
        """
        oval = self.canvas.create_oval(x - self.HOLE_RADIUS,
                                       y - self.HOLE_RADIUS,
                                       x + self.HOLE_RADIUS,
                                       y + self.HOLE_RADIUS)
        self.canvas.set_fill_color(oval, 'black')
        self.canvas.update()
Пример #21
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Target")

    height = canvas.get_canvas_height()
    width = canvas.get_canvas_width()

    _height = height / 2
    _width = width / 2

    big_circle = canvas.create_oval(_width - BIG_CIRCLE_RADIUS,
                                    _height - BIG_CIRCLE_RADIUS,
                                    _width + BIG_CIRCLE_RADIUS,
                                    _height + BIG_CIRCLE_RADIUS)

    medium_circle = canvas.create_oval(_width - MEDIUM_CIRCLE_RADIUS,
                                       _height - MEDIUM_CIRCLE_RADIUS,
                                       _width + MEDIUM_CIRCLE_RADIUS,
                                       _height + MEDIUM_CIRCLE_RADIUS)

    small_circle = canvas.create_oval(_width - SMALL_CIRCLE_RADIUS,
                                      _height - SMALL_CIRCLE_RADIUS,
                                      _width + SMALL_CIRCLE_RADIUS,
                                      _height + SMALL_CIRCLE_RADIUS)

    canvas.set_fill_color(big_circle, 'red')
    canvas.set_fill_color(medium_circle, 'white')
    canvas.set_fill_color(small_circle, 'red')

    canvas.mainloop()
Пример #22
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Mouse Location")

    # TODO: your code here!

    while True:
        coordinatex = canvas.get_mouse_x()
        coordinatey = canvas.get_mouse_y()

        coordinates = '(' + str(coordinatex) + ', ' + str(coordinatey) + ')'

        text = canvas.create_text(canvas.get_canvas_width() / 2, canvas.get_canvas_height() / 2, coordinates)
        canvas.set_font(text, 'Courier', 30)

        canvas.update()

        canvas.delete(text)

    canvas.mainloop()
Пример #23
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Gravity Ball")

    # draw a ball on the top left corner
    ball = canvas.create_oval(0, 0, SIZE, SIZE)
    canvas.set_color(ball, "black")

    # variables for velocity
    vx = 3
    vy = 0

    while True:
        # update vy
        vy += GRAVITY

        # should the ball bounce?
        if (canvas.get_top_y(ball) > (canvas.get_canvas_height() - SIZE)) \
                    and (vy > 0):
            vy = vy * -DAMPING

        # move
        canvas.move(ball, vx, vy)

        # animation pause. refresh canvas
        time.sleep(DELAY)
        canvas.update()

    canvas.mainloop()
Пример #24
0
def get_canvas():
    """Return a Canvas, which is a drawing window."""
    return Canvas(width=960, height=500)
Пример #25
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Move to Center")

    # draw a square on the left side of the screen, centered
    y = (canvas.get_canvas_height() - SQUARE_SIZE) / 2
    square = canvas.create_rectangle(0, y, SQUARE_SIZE, y + SQUARE_SIZE)
    canvas.set_color(square, "black")

    # move horizontally until we get to the center
    target_x = (canvas.get_canvas_width() - canvas.get_width(square)) / 2
    while canvas.get_left_x(square) < target_x:
        canvas.move(square, SQUARE_MOVE_AMOUNT, 0)
        time.sleep(ANIMATION_DELAY_SECONDS)
        canvas.update()

    canvas.mainloop()
Пример #26
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Mystery Square")

    width = canvas.get_canvas_width()
    height = canvas.get_canvas_height()

    _width = width / 2
    _height = height / 2

    # TODO: your code here

    square = canvas.create_rectangle(_width - SQUARE_SIZE // 2, _height - SQUARE_SIZE // 2, _width + SQUARE_SIZE // 2,
                                     _height + SQUARE_SIZE // 2)

    while True:
        num = random.randint(0, len(canvas.COLORS) - 1)
        canvas.set_fill_color(square, canvas.COLORS[num])
        canvas.set_outline_color(square, canvas.COLORS[num])
        canvas.update()
        time.sleep(DELAY)

    canvas.mainloop()
Пример #27
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Move to Center")

    x = 0
    y = (canvas.get_canvas_height() - SIZE) / 2
    # draw a square on the left of the screen
    square = canvas.create_rectangle(x, y, x + SIZE, y + SIZE)
    canvas.set_color(square, "black")

    # move until we get to the center
    target_x = (canvas.get_canvas_width() - canvas.get_width(square)) / 2
    while canvas.get_left_x(square) < target_x:
        canvas.move(square, 5, 0)  # move 5 pixels to the right
        time.sleep(DELAY)  # animation pause
        canvas.update()

    canvas.mainloop()
def main():
    canvas = Canvas()
    draw_square(canvas, True)
    canvas.mainloop()
Пример #29
0
def string_exec(strings, out, visualize_tail_calls, global_frame=None):
    import log

    empty = False

    if global_frame is None:
        empty = True
        from environment import build_global_frame
        log.logger.f_delta -= 1
        global_frame = build_global_frame()
        log.logger.active_frames.pop(0)  # clear builtin frame
        log.logger.f_delta += 1
        log.logger.global_frame = log.logger.frame_lookup[id(global_frame)]
        log.logger.graphics_lookup[id(global_frame)] = Canvas()

    log.logger.export_states = []
    log.logger.roots = []
    log.logger.frame_updates = []
    log.logger._out = []
    log.logger.visualize_tail_calls(visualize_tail_calls)

    for i, string in enumerate(strings):
        try:
            if not string.strip():
                continue
            buff = TokenBuffer([string])
            while not buff.done:
                expr = get_expression(buff)
                if expr is None:
                    continue
                empty = False
                log.logger.new_expr()
                holder = Holder(expr, None)
                Root.setroot(holder)
                res = evaluate(expr, global_frame, holder)
                if res is not Undefined:
                    out(res)
                if not log.logger.fragile and log.logger.autodraw:
                    try:
                        log.logger.raw_out("AUTODRAW" +
                                           json.dumps([log.logger.i, log.logger.heap.record(res)]) + "\n")
                    except RecursionError:
                        pass
        except (SchemeError, ZeroDivisionError, RecursionError, ValueError) as e:
            if isinstance(e, ParseError):
                log.logger.new_expr()
                raise
            if not log.logger.fragile:
                log.logger.raw_out("Traceback (most recent call last)\n")
                for j, expr in enumerate(log.logger.eval_stack[:MAX_TRACEBACK_LENGTH - 1]):
                    log.logger.raw_out(str(j).ljust(3) + " " + expr + "\n")
                truncated = len(log.logger.eval_stack) - MAX_TRACEBACK_LENGTH
                if len(log.logger.eval_stack) > MAX_TRACEBACK_LENGTH:
                    log.logger.raw_out(f"[{truncated} lines omitted from traceback]\n")
                    log.logger.raw_out(
                        str(len(log.logger.eval_stack) - 1).ljust(3) + " " + log.logger.eval_stack[-1] + "\n"
                    )
            log.logger.out(e)
        except TimeLimitException:
            if not log.logger.fragile:
                log.logger.out("Time limit exceeded.")
        log.logger.new_expr()

    if empty:
        log.logger.new_expr()
        holder = Holder(Undefined, None)
        Root.setroot(holder)
        evaluate(Undefined, global_frame, holder)
        log.logger.new_expr()
Пример #30
0
def main():
    canvas = Canvas()
    canvas.set_canvas_title("Bouncing Ball")

    width = canvas.get_canvas_width()
    height = canvas.get_canvas_height()

    change_x = 5
    change_y = 5

    ball = canvas.create_oval(0, 0, BALL_SIZE, BALL_SIZE)
    canvas.set_color(ball, 'blue')

    while True:

        if canvas.get_left_x(ball) == 0 and canvas.get_top_y(ball) == 0:
            change_x = -change_x
            change_y = -change_y

        if canvas.get_top_y(ball) + BALL_SIZE >= height:
            change_y = -change_y  # alt duvar

        elif canvas.get_top_y(ball) <= 0:
            change_y = -change_y # sağ duvar

        if canvas.get_left_x(ball) <= 0:
            change_x = -change_x # üst

        elif canvas.get_left_x(ball) + BALL_SIZE >= width:
            change_x = -change_x

        canvas.move(ball, change_x, change_y)

        canvas.update()
        time.sleep(DELAY)

    canvas.mainloop()