Beispiel #1
0
def create_objects(form):
    """
        Create shapes.
    """
    message.clear()

    if form["shape_type"] == "Circle":
        circle = Circle(
            form["shape_type"],
            form["width"],
            form["height"],
            form["left"],
            form["top"],
            form["color"]
        )

        message.append(Circle.validate(circle))

        if Circle.validate(circle) == "Circle Added":
            shapes.append(circle)


    if form["shape_type"] == "Square":
        square = Square(
            form["shape_type"],
            form["width"],
            form["height"],
            form["left"],
            form["top"],
            form["color"]
        )

        message.append(Square.validate(square))

        if Square.validate(square) == "Square Added":
            shapes.append(square)


    if form["shape_type"] == "Triangle":
        triangle = Triangle(
            form["shape_type"],
            form["width"],
            form["height"],
            form["left"],
            form["top"],
            form["color"]
        )

        message.append(Triangle.validate(triangle))

        if Triangle.validate(triangle) == "Triangle Added":
            shapes.append(triangle)
Beispiel #2
0
def main():
    square = Square(5)
    rectangle = Rectangle(12,5)
    ellipse = Ellipse(4, 10)
    oval = Oval(-4)

    shapeList = [square, rectangle, ellipse, oval]

    for s in shapeList:
        if isinstance(s, Shape):
            print("This " + s.getShape() + " has an area of " + str(s.calculateArea()))
Beispiel #3
0
 def __init__(self, side):
     print("Init Cube")
     Square.__init__(self, side)
     self.depth = side  #avoids calling constructor for object twice.
Beispiel #4
0
import pytest
from shape import Square, Rectangle, Triangle, Circle


class BadShape:
    def __init__(self, a):
        self.a = a

    @property
    def area(self):
        return self.a


figure_set_one = [
    Square(58.095),
    Rectangle(0.000887799, 44),
    Triangle(22.00001, 22.001, 22.1),
    Circle(900000234)
]
figure_set_two = [
    Square(1),
    Rectangle(999993242, 555),
    Triangle(78.956, 112.44, 96.928),
    Circle(5667.00938),
    pytest.param(BadShape(4444), marks=pytest.mark.xfail)
]


@pytest.mark.parametrize("f1", figure_set_one)
@pytest.mark.parametrize("f2", figure_set_two)
def test_add(f1, f2):
Beispiel #5
0
def test_name(data):
    s = Square(data)
    assert s.name == "Square"
Beispiel #6
0
def test_perimeter(data):
    s = Square(data)
    assert s.perimeter == data * 4
Beispiel #7
0
def test_angles(data):
    s = Square(data)
    assert s.angles == 4
Beispiel #8
0
def test_area(data):
    s = Square(data)
    assert s.area == data ** 2
Beispiel #9
0
from shape import Triangle, Square, Circle

a = input("1. Triangle \n2. Square \n3. Circle\n")
c = input("details: ")
d = c.split()
b = []
for x in d:
    b.append(int(x))
if a == '1':
    s = Triangle(b[0], b[1])
elif a == '2':
    s = Square(b[0])
else:
    s = Circle(b[0])
s.area()
s.perimeter()


 def setUp(self):
     self.test_square = Square('Square', 'Test Square', 3)
Beispiel #11
0
        r = int(input("How mach red do you want? (0,255) "))
        g = int(input("How mach green do you want? (0,255) "))
        b = int(input("How mach blue do you want? (0,255) "))
        color = [r, g, b]

        shape = Rectangle(x, y, shape_width, shape_height, color)
    elif shape == 'square':
        x = int(input('What coordinate of x it have? '))
        y = int(input('What coordinate of y it have? '))
        shape_width = int(input("What length of side will have the square? "))

        print('We create a color of the square. rgb')
        r = int(input("How mach red do you want? (0,255) "))
        g = int(input("How mach green do you want? (0,255) "))
        b = int(input("How mach blue do you want? (0,255) "))
        color = [r, g, b]

        shape = Square(x, y, shape_width, color)

    # create a img with shapes
    canvas = Canvas(width, height, color_of_canvas)
    # draw the shape on canvas
    shape.draw(canvas)
    # create file cli_image.png with canvas and shapes on them
    canvas.make('files/cli_image.png')

    answer = input('Do you wont to create another figure? y/n: ')
    if answer.lower() == 'n':
        print('Bye')
        break
Beispiel #12
0
def test3():
    s = Square("red", 1, 1, 3)
    script = [{s: [lambda o: o.move(0.5, 0)]} for _ in range(100)]
    anim = Animation([s], script, delay=0.1)
    anim.window.setCoords(0, 0, 20, 20)
    anim.show()