Example #1
0
def main():
    s1 = Square(4)
    s2 = Square(7)
    t1 = Triangle(3, 5)
    t2 = Triangle(7, 8)

    shape_list = s1, s2, t1, t2

    for n, shape in enumerate(shape_list):
        print("Shape", n, "is a", shape.shape_type, "with an area of", shape.area())
def main() -> None:
    shape1 = Rectangle(100, 200)
    shape2 = Square(100)
    shape3 = Circle(100)

    print('Shape1 surface: {}'.format(shape1.surface))
    print('Shape1 perimiter: {}'.format(shape1.perimeter))

    print('Shape2 surface: {}'.format(shape2.surface))
    print('Shape2 perimiter: {}'.format(shape2.perimeter))

    print('Shape3 surface: {}'.format(shape3.surface))
    print('Shape3 perimiter: {}'.format(shape3.perimeter))
Example #3
0
 def draw(self, shape):
     # Method drawing a shape on the canvas.
     self.__canvas.delete(self.__tmp_rendered)
     rendered_shape = None
     if shape['type'] == 'rectangle' and shape['mode'] == 'normal':
         rendered_shape = Rectangle(shape)
     elif shape['type'] == 'rectangle' and shape['mode'] == 'straight':
         rendered_shape = Square(shape)
     elif shape['type'] == 'oval' and shape['mode'] == 'normal':
         rendered_shape = Oval(shape)
     elif shape['type'] == 'oval' and shape['mode'] == 'straight':
         rendered_shape = Circle(shape)
     elif shape['type'] == 'line' and shape['mode'] == 'normal':
         rendered_shape = Line(shape)
     elif shape['type'] == 'line' and shape['mode'] == 'straight':
         rendered_shape = Diagonal(shape)
     shape_id = rendered_shape.draw_on(self.__canvas)
     return shape_id
Example #4
0
def createShapes():
    shapes = []
    for i in range(randint(5, 10)):
        v = randint(1, 4)
        x, y = randint(0, 700), randint(0, 700)
        length = randint(10, 100)
        width = randint(10, 100)
        colorChoice = COLORS[randint(0, len(COLORS) - 1)]

        if v == 1:
            pass
            shapes.append(Triangle((x, y), colorChoice, length))
        if v == 2:
            shapes.append(Rectangle((x, y), colorChoice, length, width))
        if v == 3:
            shapes.append(Square((x, y), colorChoice, length))
        if v == 4:
            shapes.append(Circle((x, y), colorChoice, length))

    return shapes
Example #5
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")
Example #6
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")


Example #7
0
File: main.py Project: Robbot/Ardit
            input(
                "Enter y coordinate for upper left corner of your rectangle: ")
        )
        rec_a = int(input("Enter width of your rectangle: "))
        rec_b = int(input("Enter height of your rectangle: "))
        red = int(input("How much red should the rectangle have: "))
        green = int(input("How much green should the rectangle have: "))
        blue = int(input("How much blue should the rectangle have: "))
        r1 = Rectangle(x=rec_x,
                       y=rec_y,
                       a=rec_a,
                       b=rec_b,
                       color=(red, green, blue))
        r1.draw(canvas)
    if shape_type.lower() == "square":
        rec_x = int(
            input("Enter x coordinate for upper left corner of your square: "))
        rec_y = int(
            input("Enter y coordinate for upper left corner of your square: "))
        rec_a = int(input("Enter width and height of your square: "))
        red = int(input("How much red should the square have: "))
        green = int(input("How much green should the square have: "))
        blue = int(input("How much blue should the square have: "))
        s1 = Square(x=rec_x, y=rec_y, a=rec_a, color=(red, green, blue))
        s1.draw(canvas)

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

canvas.make("canvas.png")
Example #8
0
from drawing_pane import ConsoleDrawingPane
from shapes import Circle, Point, Rectangle, Square

pane = ConsoleDrawingPane()

pane.shapes = [
    Point(10, 5, 'P'),
    Point(30, 3, 'P'),
    Rectangle(2, 1, 10, 3, 'R'),
    Square(38, 2, 7, 'S'),
    Circle(20, 5, 2, 'C')
]

# before moving
pane.draw()

pane.shapes[2].move(1,1)
pane.shapes[4].move(2, 1)

# after moving
pane.draw()
Example #9
0
from shapes import Square, Cube

square = Square(3)
print(square.area())
print(dir(square))

cube = Cube(3)
print(cube.surface_area())
print(cube.volume())
print(cube.family_tree())
        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')
Example #11
0
        # Create the rectangle
        rectangle = Rectangle(x=rec_x,
                              y=rec_y,
                              width=rec_width,
                              height=rec_height,
                              color=(rec_red, rec_green, rec_blue))
        rectangle.draw(canvas=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: "))
        sqr_red = int(input("Enter a value for the red color (0 to 255): "))
        sqr_green = int(
            input("Enter a value for the green color (0 to 255): "))
        sqr_blue = int(input("Enter a value for the blue color (0 to 255): "))

        # Create the square
        square = Square(x=sqr_x,
                        y=sqr_y,
                        side=sqr_side,
                        color=(sqr_red, sqr_green, sqr_blue))
        square.draw(canvas=canvas)

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

canvas.make("files/canvas.png")
Example #12
0
def test_square_area():
    square = Square((0, 0), 6)
    assert square.get_area() == 36