Exemplo n.º 1
0
def scene():

    s = shapes.Square()
    s.setColor( (0.3, 0.5, 0.3) )
    s.draw(-400, -1000, scale=8, orientation=90)

    s = shapes.Square()
    s.setColor( (0.3, 0.5, 0.3) )
    s.draw(0, -100, scale=0.8, orientation=90)


    s = shapes.Square()
    s.setColor( (0.5, 0.6, 0.6) )
    s.draw(-100, -100, scale=2, orientation=90)

    t = shapes.Triangle()
    t.setColor( (0.5, 0.4, 0.4) )
    t.draw(100, 100, scale=2, orientation=180)


    #create the first shape hexagon
    h = shapes.circle()
    h.setColor( (0.4, 0.4, 0.2) )
    h.draw( -300, 350, scale=0.5, orientation=12 )

    # #create the first shape hexagon
    # h = shapes.circle()
    # h.setColor( (0.6, 0.5, 0.1) )
    # h.draw( 0, 300, scale=0.5, orientation=12 )

    # tr = tree.Tree( distance=5, angle=22.5, color=(0.5, 0.4, 0.3), iterations=3, filename=None )
    tr = tree.Tree( filename='systemH.txt') # asign tr to the tree object 
    tr.setColor( (0.5, 0.3, 0.4) )
    tr.draw(-300, -200, scale=2, orientation=90)

    # tr = tree.Tree( distance=5, angle=22.5, color=(0.5, 0.4, 0.3), iterations=3, filename=None )
    tr = tree.Tree( filename='systemH.txt') # asign tr to the tree object 
    tr.setColor( (0.5, 0.3, 0.4) )
    tr.draw(300, -200, scale=2, orientation=90)

    # # tr = tree.Tree( distance=5, angle=22.5, color=(0.5, 0.4, 0.3), iterations=3, filename=None )
    # tr = tree.Tree( filename='systemJ.txt') # asign tr to the tree object 
    # tr.setColor( (0.5, 0.3, 0.4) )
    # tr.draw(100, -75, scale=2, orientation=90)

    # # tr = tree.Tree( distance=5, angle=22.5, color=(0.5, 0.4, 0.3), iterations=3, filename=None )
    # tr = tree.Tree( filename='systemH.txt') # asign tr to the tree object 
    # tr.setColor( (0.5, 0.3, 0.4) )
    # tr.draw(-80, -75, scale=2, orientation=90)
  

      # wait
    ti.TurtleInterpreter().hold()
Exemplo n.º 2
0
def main():
    """ test function for the new jitter style
        creates a 3x3 array with jitter increasing right to left
    """

    # create a Square and a Triangle object
    s = shapes.Square()
    s.setStyle('jitter')

    t = shapes.Triangle()
    t.setStyle('jitter')

    g = 0.2

    # Put them together in a 3x3 grid
    for i in range(3):
        r = 0.2 + 0.3 * i
        for j in [0, 1, 2]:
            b = 0.8 - 0.3 * i
            t.setColor((b, g, r))
            t.setJitter(j * 3)
            t.draw(-180 + 150 * j, 180 - 150 * i, scale=0.4, orientation=0)

            s.setColor((r, g, b))
            s.setJitter(j * 3)
            s.draw(-200 + 150 * j, 200 - 150 * i, scale=0.8, orientation=0)

    turtle_interpreter.TurtleInterpreter().hold()
Exemplo n.º 3
0
def main():

    # create a square object and draw a bunch of them
    s = shapes.Square()
    s.setColor((0.3, 0.2, 0.9))
    for i in range(36):
        s.draw(0, -100, scale=0.75, orientation=i * 10)

    # create a triangle object and draw a bunch of them
    t = shapes.Triangle()
    t.setColor((0.8, 0.2, 0.3))
    for i in range(20):
        t.draw(0, 100, scale=0.8, orientation=i * 18)

    # draw some more squares
    scale = 0.8
    offset = 0
    s.setColor((0.1, 0.8, 0.2))
    for i in range(20):
        s.draw(-300, -190 + offset, scale=scale, orientation=90)
        offset += scale * 100
        scale *= 0.8

    # draw some more triangles
    scale = 0.8
    offset = 0
    t.setColor((0.1, 0.8, 0.2))
    for i in range(20):
        t.draw(300, -190 + offset, scale=scale, orientation=180)
        offset += scale * 87
        scale *= 0.83

    # wait
    turtle_interpreter.TurtleInterpreter().hold()
Exemplo n.º 4
0
def drawSquare(event=None):

    s = shapes.Square()

    terp = ti.TurtleInterpreter()
    (x, y, z) = terp.window2turtle(event.x, event.y)
    s.draw(x, y, 1)
Exemplo n.º 5
0
def main():
    num_rows = int(sys.argv[1])
    num_cols = int(sys.argv[2])
    gap = int(sys.argv[3])
    map_width = 1500
    map_height = 315
    # Block is rectangular not square
    block_width = math.floor(
        (map_width - (1 + num_cols) * gap) / (num_cols * 1.0))
    # block_height = floor((map_height - (1+num_cols)*gap)/num_cols)
    block_height = block_width
    cx = gap + block_width / 2.0
    cy = gap + block_height / 2.0
    squares_list = []

    for i in range(num_rows):
        for j in range(num_cols):
            sq = shapes.Square((int(cx), int(cy)), int(block_width))
            squares_list.append(sq)
            cx += (block_width + gap)
        cy += (gap + block_height)
        cx = gap + block_width / 2.0

    f = open('id_8.polygons', 'w')
    f.write(str(map_width) + ', ' + str(map_height) + '\n')
    for sqs in squares_list:
        centre = sqs.get_centre()
        length = sqs.get_length()
        token = 'square: ' + str(centre[0]) + ', ' + str(
            centre[1]) + ', ' + str(length) + '\n'
        f.write(token)
    f.close()
Exemplo n.º 6
0
def table_constructor(side1, side2, leg_side, name):
    """Footprint of a table"""
    leg1 = shapes.Square(leg_side)
    leg1.color("r")
    leg2 = shapes.Square(leg_side)
    leg2.traslate(side1, 0)
    leg2.color("r")
    leg3 = shapes.Square(leg_side)
    leg3.traslate(side1, side2)
    leg3.color("k")
    leg4 = shapes.Square(leg_side)
    leg4.traslate(0, side2)
    leg4.color("r")

    legs = [leg1, leg2, leg3, leg4]
    table = shapes.CompoundShape(legs, name)
    return table
Exemplo n.º 7
0
def demolinestyles():
    square = shapes.Square()
    square.setWidth(1)
    square.setStyle('normal')
    square.draw(0, 200, 1, 90)
    square.setWidth(2)
    square.setStyle('normal')
    square.draw(200, 200, 1, 90)
    square.setWidth(3)
    square.setStyle('normal')
    square.draw(-200, 200, 1, 90)
    #=============================================
    square1 = shapes.Square()
    square1.setStyle('jitter')
    square1.setJitter(2)
    square1.draw(0, 50, 1, 90)
    square1.setStyle('jitter')
    square1.setJitter(3)
    square1.draw(200, 50, 1, 90)
    square1.setStyle('jitter')
    square1.setJitter(4)
    square1.draw(-200, 50, 1, 90)
    #=============================================
    square2 = shapes.Square()
    square2.setStyle('jitter3')
    square2.setJitter(2)
    square2.draw(0, -100, 1, 90)
    square2.setStyle('jitter3')
    square2.setJitter(3)
    square2.draw(200, -100, 1, 90)
    square2.setStyle('jitter3')
    square2.setJitter(4)
    square2.draw(-200, -100, 1, 90)
    #=============================================
    square3 = shapes.Square()
    square3.setStyle('slash')
    square3.setDotSize(1)
    square3.draw(0, -250, 1, 90)
    square3.setStyle('slash')
    square3.setDotSize(3)
    square3.draw(200, -250, 1, 90)
    square3.setStyle('slash')
    square3.setDotSize(5)
    square3.draw(-200, -250, 1, 90)
Exemplo n.º 8
0
def main(argv):
    """ main function draws the items into the image
        needs an lsystem tree file to make the trees
    """
    if len(argv) < 2:
        print('Usage: python %s <lsystem file>' % (argv[0]))
        exit()

    # background
    s = shapes.Square()
    s.setString('{F-F-F-F-}')
    s.setColor((0.88, 0.92, 1.0))
    s.draw(-400, 650, 8)

    # clouds in the sky
    c = TwoBlobs()
    c.setStyle('jitter')
    c.setJitter(10)

    for i in range(6):
        c.draw(random.randint(-450, 400), random.randint(200, 400), random.random() + 0.6)

    # mountains in the background
    m = BrokenTriangle()
    m.setStyle('jitter')
    m.setJitter(10)

    for i in [0, 3, 1, 2]:
        m.setColor((random.random() * 0.05 + 0.6, random.random() * 0.05 + 0.65, random.random() * 0.1 + 0.7))
        m.draw(-450 + i * 150 + random.randint(-10, 10), -200 + random.randint(0, 100), random.random() * 0.3 + 2)

    # grass
    g = Grass()
    g.setStyle('jitter')
    g.setJitter(3)

    for i in range(2000):
        g.draw(-450 + random.randint(0, 900), random.randint(-450, -200), 4)

    # Trees
    t = tree.Tree(iterations=3, filename=argv[1])
    t.setStyle('jitter')

    for i in range(90):
        x = -450 + i * 10 + random.randint(-5, 5)
        y = -300 + random.randint(0, 100)
        scale = (y / -300.0 + random.random() * 0.1) * 0.1
        o = 90 + random.randint(-5, 5)
        t.draw(x, y, scale, o)

    # lake
    c.setColor((0.1, 0.2, 0.8))
    c.draw(-300, -300, 5, 0)

    # hold
    turtle_interpreter.TurtleInterpreter().hold()
Exemplo n.º 9
0
def rand_squares(w, h, num, min_size, max_size):
    sqrs = []
    for i in range(num):
        center = (random.randint(min_size / 2, w - min_size / 2 - 1),
                  random.randint(min_size / 2, h - min_size / 2 - 1))
        side = random.randint(min_size, max_size)
        while not valid_square(w, h, center, side):
            side = random.randint(min_size, max_size)
        sqrs.append(shapes.Square(center, side))
    return sqrs
Exemplo n.º 10
0
def main():

    s = shapes.Square(distance=1, color='green')
    s.setWidth(1)
    s.setStyle('normal')
    s.setJitter(0)
    tree(s, -250, -150, 100)

    s = shapes.Square(distance=1, color='purple')
    s.setWidth(3)
    s.setStyle('jitter')
    s.setJitter(3)
    drawStack(s, 200, -150, 100)

    s = shapes.Triangle(distance=1, color='blue')
    s.setWidth(1)
    s.setStyle('jitter3')
    s.setJitter(2)
    drawStack(s, 0, -150, 100)

    s.hold()
Exemplo n.º 11
0
def tile(x, y, scale):
    color1 = (random.random(), random.random(), random.random())
    color2 = (random.random(), random.random(), random.random())
    color3 = (random.random(), random.random(), random.random())
    s = shapes.Square()
    s.setColor( color1 )
    s.draw(x, y, scale/100, orientation=90)
    fS=shapes.fiveSide()
    fS.setColor( color2 )
    fS.draw(x+scale, y+scale, scale/100, orientation=90)
    SY=shapes.SideYellow()
    SY.setColor( color3 )
    SY.draw(x-scale, y+scale, scale/100, orientation=90)
Exemplo n.º 12
0
    def test_square_boxes_form_square(self):
        square = shapes.Square(0, 0)

        self.assertEqual(square.blocks[0].x, 0)
        self.assertEqual(square.blocks[0].y, 0)

        self.assertEqual(square.blocks[1].x, 1)
        self.assertEqual(square.blocks[1].y, 0)

        self.assertEqual(square.blocks[2].x, 0)
        self.assertEqual(square.blocks[2].y, 1)

        self.assertEqual(square.blocks[3].x, 1)
        self.assertEqual(square.blocks[3].y, 1)
Exemplo n.º 13
0
def main():

    # call the square as the element to draw tree with calling the tree function
    s = shapes.Square(distance=1, color='green')
    s.setWidth(1)
    s.setStyle('normal')
    s.setJitter(0)
    tree(s, -250, -150, 100)

    # call the square as the element to draw stack with calling the stack function
    s = shapes.Square(distance=1, color='purple')
    s.setWidth(3)
    s.setStyle('jitter')
    s.setJitter(3)
    drawStack(s, 200, -150, 100)

    # call the triangle as the element to draw stack with calling the stack function
    s = shapes.Triangle(distance=1, color='blue')
    s.setWidth(1)
    s.setStyle('jitter3')
    s.setJitter(2)
    drawStack(s, 0, -150, 100)

    s.hold()
Exemplo n.º 14
0
def paintings():
    # painting number 1
    '''hand drawn with jitter style'''
    art = s.Square(185, ('Black'))
    art.setStyle('slash')
    art.setJitter(4)
    art.draw(-525, -100, 1, 90)
    '''now i will add art to the painting'''
    t1 = tree.Tree(filename='project10extension2.txt')
    t1.setIterations(3)
    t1.setColor('LawnGreen')
    t1.draw(-400, -100, 1, 90)

    # painting number 2
    '''hand drawn with dotted style'''
    art1 = s.Square(185, ('Black'))
    art1.setStyle('slash')
    art1.setDotSize(3)
    art1.draw(-150, -100, 1, 90)
    '''now i will add art to the painting'''
    t2 = tree.Tree(filename='project10extension2.txt')
    t2.setIterations(3)
    t2.setColor('OliveDrab')
    t2.draw(0, -100, 1, 90)

    # painting number 3
    '''hand drawn with jitter3 style'''
    art2 = s.Square(185, ('Black'))
    art2.setStyle('slash')
    art2.setJitter(5)
    art2.draw(225, -100, 1, 90)
    '''now i will add art to the painting'''
    t3 = tree.Tree(filename='project10extension2.txt')
    t3.setIterations(3)
    t3.setColor('Green')
    t3.draw(400, -100, 1, 90)
Exemplo n.º 15
0
def find_sqrs(w, h):
    sqrs = []
    s = w/100
    last = None
    mul = (random.random() + 2)
    offa = tuple((random.random() * 1.6 - 0.8) for i in range(2))
    while len(sqrs) == 0 or not fills_screen(w, h, last) and not off_screen(w, h, last):
        pos = (random.randint(w/3, 2*w/3), random.randint(h/3, 2*h/3)) if len(sqrs) == 0 else last.center
        s *= mul
        #s = int(s * (random.random() * 2 + 1.5))
        #offset = tuple(random.randint((-1 * (s/2 - last.s/2)) * 2/3, (s/2 - last.s/2) * 2/3) for i in range(2)) if len(sqrs) > 0 else (0,0)
        offset = tuple((offa[i] * (s/2 - last.s/2)) for i in range(2)) if last != None else (0,0)
        #print offa
        sqrs.append(shapes.Square((pos[0] + offset[0], pos[1] + offset[1]), s))
        last = sqrs[-1]
    return sqrs[:-1]
Exemplo n.º 16
0
def task2():
	'''create scene of tree surrounded by boxes'''
	x = ti.TurtleInterpreter()
	
	#creates ground
	sq = s.Square(fill = True)
	sq.setColor('#d6f0f9')
	sq.draw(0, -200, scale = 1.5, zpos = 0, roll = 90)
	sq.draw(-150, -200, scale = 1.5, zpos = 0, roll = -90)
	sq.setColor('#f7e3f4')
	sq.draw(0, -200, scale = 1.5, zpos = 0, roll = -90)
	sq.draw(-150, -200, scale = 1.5, zpos = 0, roll = 90)
	
	
	#create tree
	tree1 = tree.Tree(20, filename = "systemZ.txt")
	tree1.setIterations(4)
	tree1.draw(0, -200, scale = 1.0, zpos = 0)
	
	#creates boxes
	sq2 = s.Box()
	colors = ['#8ee28c', '#167714', '#55c153', '#29a327']
	sq3 = s.Octahedron()
	sq4 = s.Pyramid()
	
	for i in range(0, 360, 30):
		x0 = r.randint(-70, 30)
		y0 = r.randint(-200, -150)
		sc = r.randint(1, 5)
		pick = r.choice(colors)
		roll0 = r.randint(-180, 180)
		sq2.setColor(pick)
		sq2.draw(x0, y0, scale = sc/5, roll = roll0)
	
	for i in range(4):
		x0 = r.randint(-100, 100)
		x1 = r.randint(-100, 100)
		y0 = r.randint(-150, 100)
		y1 = r.randint(-150, 100)
		sc = r.randint(1, 3)
		pick = r.choice(colors)
		roll0 = r.randint(-180, 180)
		sq3.setColor(pick)
		sq3.draw(x0, y0, scale = sc/5, roll = roll0)
		sq4.setColor(pick)
		sq4.draw(x1, y1, scale = sc/5, roll = roll0)
	x.hold()
Exemplo n.º 17
0
def tile(x, y, scale):
    '''
	Draws a square tile of unit length 1, which then is modified based on the scale
	Draws a set of triangles inside this square that is scale by scale in size with 
	lower left corner at (x,y). This creates scale by scale triangles in a square. 
	'''
    Square1 = shapes.Square(1)
    Square1.draw(x, y, scale)

    x0 = x
    y0 = y
    for i in range(10):
        x0 = x + i * scale / 10
        for j in range(10):
            y0 = y - j * scale / 10 - scale / 10
            Triangle1 = shapes.Triangle(1)
            Triangle1.setColor('blue')
            Triangle1.draw(x0, y0, scale / 10)
Exemplo n.º 18
0
def main():

    x = it.TurtleInterpreter()

    s = shapes.Square(distance=300, color=(0.1, 0.6, 0.3))
    s.draw(-150, -150, zpos=-150, roll=-90)

    s.setColor((0.2, 0.1, 0.7))
    s.draw(-150, -150, zpos=-150, orientation=90)

    s.setColor((0.8, 0.2, 0.3))
    s.setStyle('jitter')
    s.draw(-150, 0, zpos=-150, roll=-90)

    s.setColor((0.7, 0.7, 0.1))
    s.setStyle('jitter')
    s.draw(-150, 150, zpos=-150, roll=-90)

    x.hold()
Exemplo n.º 19
0
def tile(x, y, scale):
    color1 = (random.random(), random.random(), random.random())
    color2 = (random.random(), random.random(), random.random())
    color3 = (random.random(), random.random(), random.random())
    s = shapes.Square()
    s.setColor(color1)
    s.setStyle('dotted')
    s.setJitter(5)
    s.draw(x, y, scale / 100, orientation=90)
    fS = shapes.fiveSide()
    fS.setColor(color2)
    s.setStyle('jitter3')
    s.setJitter(5)
    fS.draw(x + scale, y + scale, scale / 100, orientation=90)
    SY = shapes.SideYellow()
    SY.setColor(color3)
    s.setStyle('jitter')
    s.setJitter(5)
    SY.draw(x - scale, y + scale, scale / 100, orientation=90)
Exemplo n.º 20
0
def painting():
    art = s.Square(450, (1, 1, 1))
    art.draw(-225, -100, 1, 90)
    p = s.Pentagon(100, (0, 0, 0))
    p.setColor('DarkOrchid')
    p.draw(-175, 200, 1, 90)
    st = s.Star(75, (0, 0, 0))
    st.setColor('Goldenrod')
    st.draw(80, 240, 1, 90)
    c = s.Cross(40, (0, 0, 0))
    c.setColor('LightCoral')
    c.draw(-130, 45, 1, 90)
    d = s.Diamond(100, (0, 0, 0))
    d.setColor('CadetBlue')
    d.draw(80, -10, 1, 90)
    t1 = tree.Tree(filename='systemGL.txt')
    t1.setIterations(9)
    t1.setColor('LawnGreen')
    t1.draw(0, -75, 1, 90)
Exemplo n.º 21
0
def readShapesFromJson(data):
    shapes_list = []
    if 'Figures' not in data.keys():
        return []
    palette = data['Palette']
    i = 1
    for shape in data['Figures']:
        if (validate.validateShape(shape)):
            color = ''
            if 'color' in shape:
                if validate.validateColor(shape['color'], palette):
                    color = shape['color']
            if shape['type'] == 'point':
                shapes_list.append(shapes.Point(shape['x'], shape['y']))
            elif shape['type'] == 'polygon':
                points = []
                for point in shape['points']:
                    points.append(shapes.Point(point[0], point[1]))
                shapes_list.append(shapes.Polygon(points, color))
            elif shape['type'] == 'rectangle':
                point = shapes.Point(shape['x'], shape['y'])
                rect = shapes.Rectangle(point, shape['width'], shape['height'],
                                        color)
                shapes_list.append(rect)
            elif shape['type'] == 'square':
                point = shapes.Point(shape['x'], shape['y'])
                shapes_list.append(
                    shapes.Square(point, shape.get('size'), color))
            elif shape['type'] == 'circle':
                point = shapes.Point(shape['x'], shape['y'])
                shapes_list.append(
                    shapes.Circle(point, shape.get('radius'), color))
            else:
                print('Wrong type in Figure number', i, 'in file.')
        else:
            print('Wrong parameters in Figure number', i, 'in file.')
        i = i + 1
    return shapes_list
Exemplo n.º 22
0
def tile(x, y, scale):
    # use random colors
    color1 = (random.random(), random.random(), random.random())
    color2 = (random.random(), random.random(), random.random())
    color3 = (random.random(), random.random(), random.random())

    # draw the square
    s = shapes.Square()
    s.setColor(color1)
    s.setWidth(1)
    s.setStyle('jitter3')
    s.setJitter(2)
    s.draw(x, y, scale / 100, orientation=90)

    #draw the fiveSide
    fS = shapes.fiveSide()
    fS.setColor(color2)
    fS.draw(x + scale, y + scale, scale / 100, orientation=90)

    #draw the SideYellow
    SY = shapes.SideYellow()
    SY.setColor(color3)
    SY.draw(x - scale, y + scale, scale / 100, orientation=90)
Exemplo n.º 23
0
def tile(x, y, scale):

    # draw the square tiles
    sq = s.Square(scale, (0, 0, 0))
    sq.setColor("Aquamarine")
    sq.draw(x, y, 90, 90)

    #draw crosses
    c = s.Cross(scale, (0, 0, 0))
    c.setColor("Red")
    c.draw(x + 45, y + 45, 7, 90)

    #draw stars
    st = s.Star(scale, (0, 0, 0))
    st.setColor("Orchid")
    st.draw(x + 20, y + 70, 10, 90)
    st.draw(x + 70, y + 20, 10, 90)

    #draw diamonds
    d = s.Diamond(scale, (0, 0, 0))
    d.setColor("DodgerBlue")
    d.draw(x + 70, y + 70, 15, 90)
    d.draw(x + 15, y + 20, 15, 90)
Exemplo n.º 24
0
def main():

    # create a square object and draw a bunch of them
    s = shapes.Square()
    s.setColor((0.3, 0.2, 0.9))
    for i in range(36):
        s.draw(0, -100, scale=0.75, orientation=i * 10)

    # create a triangle object and draw a bunch of them
    t = shapes.Triangle()
    t.setColor((0.8, 0.2, 0.3))
    for i in range(20):
        t.draw(0, 100, scale=0.8, orientation=i * 18)

    # create a fillTriangle object and draw a bunch of them
    fT = shapes.fillTriangle()
    fT.setColor((0.8, 0.2, 0.3))
    for i in range(20):
        fT.draw(250, -100, scale=0.75, orientation=i * 30)

    # create a 5sides object and draw it
    fS = shapes.fiveSide()
    fS.setColor("red")
    fS.draw(-300, -50, scale=0.75, orientation=0)

    # create a star object and draw a red one
    S = shapes.Side()
    S.setColor("red")
    S.draw(-300, 200, scale=0.75, orientation=0)

    # create a star object and draw a yellow one
    SY = shapes.SideYellow()
    SY.setColor("yellow")
    SY.draw(200, 200, scale=0.75, orientation=0)

    # wait
    turtle_interpreter.TurtleInterpreter().hold()
Exemplo n.º 25
0
#!/usr/bin/python3

import shapes

square1 = shapes.Square(3.0)
circle1 = shapes.Circle(4.0)

print("length of square1 = " + str(square1.getSide()))
print("radius of circle1 = " + str(circle1.getRadius()))
Exemplo n.º 26
0
def tile(x, y, scale):
    s = shapes.Square()
    #s. setColor( (0.3, 0.4, 0.4 ) )
    s.draw(0, 100, scale=0.8, orientation=8)

    return s
Exemplo n.º 27
0
    f2 = g.getFace(prefix2 + "." + face2)
    for (e1, e2) in zip(f1.edges, f2.edges):
      e1.mergeWith(e2)
    if toKeep < 2:
      g.delFace(f2.name)
    if toKeep < 1:
      g.delFace(f1.name)
    return g
  '''


if __name__ == "__main__":
    import shapes

    t = shapes.RegularNGon("triangle", 3, 1)
    s = shapes.Square("square", 1)

    tetra = Graph()
    tetra.addFace(t.copy("one"), ("12", "13", "14"))
    tetra.addFace(t.copy("two"), ("12", "24", "23"))
    tetra.addFace(t.copy("three"), ("13", "23", "34"))
    tetra.addFace(t.copy("four"), ("14", "34", "24"))

    tetra.showGraph()
    print tetra.faces
    print tetra.edges
    '''
  pyramid = Graph()
  pyramid.addFace( s.copy("base"), ("b1", "b2", "b3", "b4"))
  pyramid.addFace( t.copy("one"), ("b1", "14", "12"))
  pyramid.addFace( t.copy("two"), ("b2", "12", "23"))
Exemplo n.º 28
0
o1.set_name()
o1.get_name()
print("side is ", end="")
o1.get_side()
print("\n")


r1 = shapes.Rectangle()
r1.set_name()
r1.get_name()
print("side is ", end="")
r1.get_side()
print("\n")


s1 = shapes.Square()
s1.set_name()
s1.get_name()
print("side is ", end="")
s1.get_side()
print("\n")


ell1 = shapes.Ellipse()
ell1.set_name()
ell1.get_name()
ell1.set_params(40, 80)
print("Area is ", end="")
ell1.get_area()
print("\n")
Exemplo n.º 29
0
def main():
    width = int(sys.argv[1])
    height = int(sys.argv[2])
    max_obstacles = int(sys.argv[3])
    num_approx_points = int(sys.argv[4])
    file_name = str(sys.argv[5])

    if os.path.exists(file_name):
        print(
            'The map with the give name already exists. Please delete it manually before proceeding to overwrite it.'
        )

    boundary_offset = 10
    min_length = 40
    max_length = 70
    obstacles_list = []
    obstacles_type = []

    # Dummy obstacle to prevent the starting point of seekers
    # from getting blocked by some obstacle
    obs = shapes.Square((30, 30), 60)
    obstacles_list.append(obs)
    obstacles_type.append('square')

    num_obstacles = 0
    while num_obstacles < max_obstacles:
        obs_valid = False
        while not obs_valid:
            cx = random.randint(max_length + boundary_offset,
                                width - max_length - boundary_offset)
            cy = random.randint(max_length + boundary_offset,
                                height - max_length - boundary_offset)
            length = random.randint(min_length, max_length)
            choice = random.randint(0, 1)
            choice = 1
            if choice == 0:
                obs = shapes.Square((cx, cy), length)
                obs_type = 'square'
            else:
                obs = shapes.Circle((cx, cy), length, num_approx_points)
                obs_type = 'circle'

            collision = False
            for other in obstacles_list:
                if obs.check_aabb_collision(other, 20):
                    collision = True
                    break
            if not collision:
                obstacles_list.append(obs)
                obstacles_type.append(obs_type)
                obs_valid = True
                num_obstacles += 1

    f = open(file_name, 'w+')

    f.write(str(width) + ', ' + str(height) + '\n')
    for obs, obs_type in zip(obstacles_list[1:], obstacles_type[1:]):
        centre = obs.get_centre()
        token = obs_type + ': ' + str(centre[0]) + ', ' + str(centre[1])
        if obs_type == 'circle':
            token += ', ' + str(
                obs.get_radius()) + ',' + str(num_approx_points)
        elif obs_type == 'square':
            token += ', ' + str(obs.get_length())

        token += '\n'
        f.write(token)
Exemplo n.º 30
0
 def setUp(self):
     self.square = shapes.Square(1)