Exemple #1
0
    if shape_type.lower() == "rectangle":
        rec_x = int(input("Enter x of the rectangle: "))
        rec_y = int(input("Enter y of the rectangle: "))
        rec_width = int(input("Enter width of rectangle: "))
        rec_height = int(input("Enter height of rectangle: "))
        rec_colors = input("Enter weight of Red,Blue,Green for the rectangle: ")
        rec_colors = rec_colors.split(',')

        rec = Rectangle(x=rec_x, y=rec_y, width=rec_width, height=rec_height,
                        color=(rec_colors[0], rec_colors[1], rec_colors[2]))
        rec.draw(canvas)

    if shape_type.lower() == "square":
        squ_x = int(input("Enter x of the square: "))
        squ_y = int(input("Enter y of the square: "))
        squ_side = int(input("Enter side of square: "))
        rec_colors = input("Enter weight of Red,Blue,Green for the square: ")
        rec_colors = rec_colors.split(',')

        squ = Square(x=squ_x, y=squ_y, side=squ_side,
                     color=(rec_colors[0], rec_colors[1], rec_colors[2]))
        squ.draw(canvas)

    if shape_type.lower() == "quit":
        break


canvas.make(imagepath="./resources/pic.png")


Exemple #2
0
        rec_width = int(input("Enter the width of the rectangle: "))
        rec_height = int(input("Enter the height of the rectangle: "))
        red = int(input("How much red should the rectangle have? "))
        green = int(input("How much green ?   "))
        blue = int(input("How much blue do you like?   "))

    # Create the rectangle
    r1 = Rectangle(x=rec_x,
                   y=rec_y,
                   width=rec_width,
                   height=rec_height,
                   color=(red, green, blue))
    r1.draw(canvas)

    # Ask for square data and create square if user entered 'square'
    if shape_type.lower() == "square":
        sqr_x = int(input("Enter x of the square: "))
        sqr_y = int(input("Enter y of the square: "))
        sqr_side = int(input("Enter the side length of the square: "))
        red = int(input("How much red should the square have? "))
        green = int(input("How much green?   "))
        blue = int(input("How much blue do you like?   "))
        s1 = Square(x=sqr_x, y=sqr_y, side=sqr_side, color=(red, green, blue))
        s1.draw(canvas)

    #  Break the loop if user entered "quit"
    if shape_type.lower() == "quit":
        break

canvas.make("canvas.png")
        rec_y = get_sanitized_input("Enter the rectangle's y coordinate: ", int, 0, canvas_height - rec_height)

        red = get_sanitized_input("How much red should the rectangle have? ", int, 0, 255)
        green = get_sanitized_input("How much green should the rectangle have? ", int, 0, 255)
        blue = get_sanitized_input("How much blue should the rectangle have? ", int, 0, 255)

        # Draw the rectangle
        rectangle = Rectangle(x=rec_x, y=rec_y, height=rec_height, width=rec_width, color=(red, green, blue))
        rectangle.draw(canvas)

    # If user enters rectangle
    if shape_type.lower() == "square":
        square_side = get_sanitized_input(
            "Enter the square's side: ", int, 1,
            canvas_width if canvas_width < canvas_height else canvas_height)
        square_x = get_sanitized_input("Enter the square's x coordinate: ", int, 0, canvas_width - square_side)
        square_y = get_sanitized_input("Enter the square's y coordinate: ", int, 0, canvas_height - square_side)
        red = get_sanitized_input("How much red should the square have? ", int, 0, 255)
        green = get_sanitized_input("How much green should the square have? ", int, 0, 255)
        blue = get_sanitized_input("How much blue should the square have? ", int, 0, 255)

        # Draw the square
        square = Square(x=square_x, y=square_y, side=square_side, color=(red, green, blue))
        square.draw(canvas)

    # Handle quit
    if shape_type == "quit":
        break

canvas.make('canvas.png')