Beispiel #1
0
def tile2(x, y, scale):
    '''
	Draws an unfilledtriangle tile of unit length 1, which then is modified based 
	on the scale. Draws a set of triangles inside this square that is of size scale 
	with the lower left corner at (x,y). This creates a series of red triangles in a 
	triangle. 
	'''
    Triangle1 = shapes.TriangleU(1)
    Triangle1.draw(x, y, scale)

    for i in range(10):
        shift = 0
        numTriangles = 10 - i
        for j in range(numTriangles):
            if scale % 20 == 0:
                x0 = x + i * scale / 10 + shift
                y0 = y + j * scale / 11.5
                Triangle1 = shapes.Triangle(1)
                Triangle1.setColor('red')
                Triangle1.draw(x0, y0, scale / 10)
                shift += scale / 20
            else:
                x0 = x + i * scale / 10 + shift
                y0 = y + j * scale / 11.59
                Triangle1 = shapes.Triangle(1)
                Triangle1.setColor('red')
                Triangle1.draw(x0, y0, scale / 10)
                shift += scale / 20
Beispiel #2
0
def main():
    # call the triangle as the element to draw tree with calling the tree function
    s = shapes.Triangle(distance=1, color='red')
    s.setWidth(3)
    s.setStyle('normal')
    s.setJitter(0)
    tree(s, 150, -150, 100)

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

    # define two strings
    square = 'F-F-F-F-'
    triangle = 'F-F-F-'

    terp = turtle_interpreter.TurtleInterpreter()

    # draw normal
    terp.place(-200, 300)
    terp.setStyle('normal')
    terp.setColor("blue")
    terp.setWidth(1)
    terp.drawString(square, 100, 90)

    # draw jitter
    terp.place(-200, 150)
    terp.setStyle('jitter')
    terp.setJitter(2)
    terp.setColor("red")
    terp.setWidth(1)
    terp.drawString(square, 100, 90)

    # draw jitter3
    terp.place(-200, 0)
    terp.setStyle('jitter3')
    terp.setJitter(2)
    terp.setColor("blue")
    terp.setWidth(1)
    terp.drawString(square, 100, 90)

    # draw dotted
    terp.place(-200, -150)
    terp.setStyle('dotted')
    terp.setJitter(2)
    terp.setColor("")
    terp.setWidth(1)
    terp.drawString(square, 100, 90)

    terp.hold()
Beispiel #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()
Beispiel #4
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()
Beispiel #5
0
    def convert(t):
        def findClosest(point):
            idx = tree.query(toNumpy([point]))[1]
            return valid_points[idx]

        A = findClosest(shapes.Point(t.a.x, t.a.y))
        B = findClosest(shapes.Point(t.b.x, t.b.y))
        C = findClosest(shapes.Point(t.c.x, t.c.y))
        return shapes.Triangle(A, B, C)
Beispiel #6
0
def triangulatePoints(points):
    points = toNumpy(points)
    triangulation = sp.Delaunay(points)
    triangles = []
    for i in range(len(triangulation.simplices)):
        verts = map(lambda p: shapes.Point(p[0], p[1]),
                    points[triangulation.simplices[i, :]])
        triangle = shapes.Triangle(verts[0], verts[1], verts[2])
        triangles.append(triangle)
    return triangles
Beispiel #7
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()
def tile(x, y, scale):

    # draw the triangle tiles
    tri = s.Triangle(scale, (0, 0, 0))
    tri.setColor("SteelBlue")
    tri.draw(x, y, 85, 60)
    tri.setColor("Gold")
    tri.draw(x + 135, y + 80, 85, 240)

    #draw stars
    st = s.Star(scale, (0, 0, 0))
    st.setColor("Salmon")
    st.draw(x + 40, y + 30, 10, 90)

    #draw diamonds
    d = s.Diamond(scale, (0, 0, 0))
    d.setColor("DodgerBlue")
    d.draw(x + 85, y + 55, 15, 60)
Beispiel #9
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)
Beispiel #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()
Beispiel #11
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()
Beispiel #12
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()
def main():
    '''creates the home scene by calling shape functions at different line styles'''
    terp = ti.TurtleInterpreter()

    r = s.Rectangle(50)
    r.setStyle('jitter3')
    r.setJitter(3)
    r.setColor('lawn green')
    r.draw(-400, -400, 1.5, 90)

    r = s.Rectangle(50)
    r.setStyle('jitter3')
    r.setJitter(3)
    r.setColor('light sky blue')
    r.draw(-400, 0, 1.5, 90)

    r = s.Rectangle(20)
    r.setStyle('jitter')
    r.setJitter(3)
    r.setColor('light slate blue')
    r.draw(-250, -180, 6, 90)

    sq = s.Square(180)
    sq.setStyle('jitter')
    sq.setJitter(3)
    sq.setColor('light slate blue')
    sq.draw(-250, 120)

    rt = s.Rectangle(20)
    rt.setStyle('jitter')
    rt.setJitter(2)
    rt.setColor('grey')
    rt.draw(-240, 210)

    tr = s.Triangle(45)
    tr.setStyle('jitter')
    tr.setJitter(3)
    tr.setColor('dark slate blue')
    tr.draw(-250, 120, 4, 60)

    rt = s.Rectangle(40)
    rt.setStyle('jitter')
    rt.setJitter(2)
    rt.setColor('dark slate blue')
    rt.draw(-220, -20)

    sq = s.Square(80)
    sq.setStyle('jitter')
    sq.setJitter(3)
    sq.setColor('slate blue')
    sq.draw(-220, 100)

    sq = s.Square(90)
    sq.setStyle('jitter')
    sq.setJitter(3)
    sq.setColor('slate blue')
    sq.draw(100, 30)

    sq = s.Square(90)
    sq.setStyle('jitter')
    sq.setJitter(3)
    sq.setColor('slate blue')
    sq.draw(-40, 30)

    t.Tree1 = t.Tree(distance=10,
                     color=(0.1, 0.5, 0.3),
                     filename='systemDL.txt')
    t.Tree1.draw(290, -90)
    t.Tree2 = t.Tree(distance=15,
                     color=(0.1, 0.5, 0.3),
                     filename='systemFL.txt')
    t.Tree2.draw(-320, -90)

    terp.hold()
Beispiel #14
0
import shapes

rect_1 = shapes.Rectangle()
print(rect_1.perimeter(10, 7))
print(rect_1.area_rect(10, 7))
print(rect_1.area_sin_rect(30, 9, 28))

circle_1 = shapes.Circle()
print(circle_1.circle_area(5))
print(circle_1.circumference_rad(5))
print(circle_1.arc_length(45, 8))

triang_1 = shapes.Triangle()
print(triang_1.area_height(2, 4))
print(triang_1.area_angle(2, 3, 90))
Beispiel #15
0

class Program(object):
    def run(self, new_shapes):
        while 1:
            command = input(
                "Please enter a shape (cube, triangular pyramid, circle, quadrilateral, pentagon or triangle). Type 'exit' to quit the program: "
            )

            for shape in new_shapes:
                if command in shape.name:
                    shape.get_shape_ui().get_details()
                    print("Area/Volume: ", shape.algorithm1(),
                          "\nPerimeter/Surface area: ", shape.algorithm2())
                elif "exit" in command:
                    sys.exit("Seeya!")


SHAPES = [
    shapes.TwoDAdapter(shapes.Circle("circle")),
    shapes.TwoDAdapter(shapes.Quadrilateral("quadrilateral")),
    shapes.TwoDAdapter(shapes.Pentagon("pentagon")),
    shapes.TwoDAdapter(shapes.Triangle("triangle")),
    tridshapes.TriDAdapter(tridshapes.RectangularPrism('cube')),
    tridshapes.TriDAdapter(tridshapes.TriPyramid('triangular pyramid'))
]

program = Program()

program.run(SHAPES)
Beispiel #16
0
l1.displaydetails()
l1.animalProperty()
print("\n")


print("Printing shapes classes details....\n")

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


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

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


h1 = shapes.Hexagon()
Beispiel #17
0
import shapes
import base

xy = [0, 0]

triangle = shapes.Triangle(xy, 1, 4)
circle = shapes.Circle(xy, 2)
square = shapes.Square(xy, 1)
ellipse = shapes.Ellipse(xy, 3, 2)
rectangle = shapes.Rectangle(xy, 14, 3)

mylist = [triangle, square, rectangle, circle, ellipse]

for item in mylist:
    if isinstance(item, base.Polygon):
        print(f"{item} located at {item.center} of size {item._size}")
    else:
        print(f"{item} located at {item.center} of radius {item.radius}")
Beispiel #18
0
import shapes

square = shapes.Square(5)
triangle = shapes.Triangle(3, 4)
tests = shapes.TestFunctionalities

tests.test_get_area_square(shapes.TestFunctionalities, square)
tests.test_get_perimeter_square(shapes.TestFunctionalities, square)

tests.test_get_area_triangle(shapes.TestFunctionalities, triangle)
tests.test_get_perimeter_triangle(shapes.TestFunctionalities, triangle)
Beispiel #19
0
r = shapes.Rectangle(100, 60)
r.printarea()
r.get_sides()
r.printperimeter()
r.draw()

print("\n SQUARE\n")
s = shapes.Square(4, 120)
s.printarea("square")
s.get_sides("square")
s.printperimeter("square")
s.diagonal()
s.draw()

print("\n EQUILATERAL TRIANGLE \n")
t = shapes.Triangle(3, 140)
t.printarea("equilateral triangle")
t.get_sides("equilateral triangle")
t.printperimeter("equilateral triangle")
t.draw()

print("\n RHOMBUS \n")
rh = shapes.Rhombus(50, 120)
rh.printarea()
rh.get_sides()
rh.printperimeter()
rh.draw()

print("\n PARALLELOGRAM \n")
p = shapes.Parallelogram(200, 100)
p.printarea()