Question

In: Computer Science

draw the vertexes of a triangle and generate a list of the vertices code is in...

draw the vertexes of a triangle and generate a list of the vertices

code is in python

use turtle graphics

Solutions

Expert Solution

The following python code Will randomly generate the verticies of the triangle using turtle graphics. Taking pairs of verticies in turn, Initially start a turtle at each heading toward the other. When the turtles collide (at the midpoint), it will eliminate one turtle and send the other toward the vertex not in the pair (totally with six turtles).

Program

from turtle import Turtle, Screen
from random import seed, randint

WIDTH, HEIGHT = 640, 480

def meet_in_the_middle(turtle_1, turtle_2):

    position_2 = turtle_2.position()

    while True:
        turtle_1.setheading(turtle_1.towards(turtle_2))
        turtle_1.forward(1)
        position_1 = turtle_1.position()
        if int(position_1[0]) == int(position_2[0]) and int(position_1[1]) == int(position_2[1]):
            break

        turtle_2.setheading(turtle_2.towards(turtle_1))
        turtle_2.forward(1)
        position_2 = turtle_2.position()
        if int(position_2[0]) == int(position_1[0]) and int(position_2[1]) == int(position_1[1]):
            break

seed()

screen = Screen()
screen.setup(WIDTH * 1.25, HEIGHT * 1.25)

vertices = []

for _ in range(3):
    x = randint(-WIDTH//2, WIDTH//2)
    y = randint(-HEIGHT//2, HEIGHT//2)
    vertices.append((x, y))

A, B, C = vertices

turtle_AtoB = Turtle(shape='turtle')
turtle_AtoB.penup()
turtle_AtoB.goto(A)
turtle_AtoB.pendown()

turtle_BtoA = Turtle(shape='turtle')
turtle_BtoA.penup()
turtle_BtoA.goto(B)
turtle_BtoA.pendown()

meet_in_the_middle(turtle_AtoB, turtle_BtoA)

turtle_BtoA.hideturtle()
turtle_AtoB.setheading(turtle_AtoB.towards(C))
turtle_AtoB.goto(C)
turtle_AtoB.hideturtle()


turtle_BtoC = Turtle(shape='turtle')
turtle_BtoC.penup()
turtle_BtoC.goto(B)
turtle_BtoC.pendown()

turtle_CtoB = Turtle(shape='turtle')
turtle_CtoB.penup()
turtle_CtoB.goto(C)
turtle_CtoB.pendown()

meet_in_the_middle(turtle_BtoC, turtle_CtoB)

turtle_CtoB.hideturtle()
turtle_BtoC.setheading(turtle_BtoC.towards(A))
turtle_BtoC.goto(A)
turtle_BtoC.hideturtle()


turtle_CtoA = Turtle(shape='turtle')
turtle_CtoA.penup()
turtle_CtoA.goto(C)
turtle_CtoA.pendown()

turtle_AtoC = Turtle(shape='turtle')
turtle_AtoC.penup()
turtle_AtoC.goto(A)
turtle_AtoC.pendown()

meet_in_the_middle(turtle_CtoA, turtle_AtoC)

turtle_AtoC.hideturtle()
turtle_CtoA.setheading(turtle_CtoA.towards(B))
turtle_CtoA.goto(B)
turtle_CtoA.hideturtle()

screen.exitonclick()

Related Solutions

The vertices of a triangle determine a circle, called the circumcircle of the triangle. Show that...
The vertices of a triangle determine a circle, called the circumcircle of the triangle. Show that if P is any point on the circumcircle of a triangle, and X, Y, and Z are the feet of the perpendiculars from P to the sides of the triangle, then X, Y and Z are collinear.
the language is matlab 1) Write a code that will print a list consisting of “triangle,”...
the language is matlab 1) Write a code that will print a list consisting of “triangle,” “circle,” and “square.” It prompts the user to choose one, and then prompts the user for the appropriate quantities (e.g., the radius of the circle) and then prints its area. If the user enters an invalid choice, the script simply prints an error message. For calculating the area, create separate functions for each choice. Name them as calcTriangle, calcCircle, calcSquare respectively, which are only...
189. An altitude of a triangle is a segment that joins one of the three vertices...
189. An altitude of a triangle is a segment that joins one of the three vertices to a point on the line that contains the opposite side, the intersection being perpendicular. For example, consider the triangle whose vertices are A = (0, 0), B = (8, 0), and C = (4, 12). (a) Find the length of the altitude from C to side AB. What is the area of ABC? (b) Find an equation for the line that contains the...
A flea moves around the vertices of a triangle in the following manner: Whenever it is...
A flea moves around the vertices of a triangle in the following manner: Whenever it is at vertex i it moves to its clockwise neighbor vertex with probability pi and to the counterclockwise neighbor with probabilityqi=1-pi,i=1,2,3 a) Find the proportion of time that the flea is at each of the vertices. b)How often does the flea make a counterclockwise move, which is then followed by 5 consecutive clockwise moves?
The  three charges are at the three vertices of an equilateral triangle ?( all angles are 60degrees)...
The  three charges are at the three vertices of an equilateral triangle ?( all angles are 60degrees) q 1  =  + 10.0 µC q 2 =  -  5 .0 nC q 3  = + 8 .0 nC Equilateral side of the triangle = 0.05 m. A. Draw forces acting on  q 1 by  q 2and q 3   B. find the components on X and Y axes . C. Use Pythagorean theorem to find the resultant . D. Use tangent to find the direction ( angle ) the resultant...
Considering the vertices of the "iron triangle" of healthcare — cost, quality, and access as described...
Considering the vertices of the "iron triangle" of healthcare — cost, quality, and access as described by Lehman — how will healthcare policy and reform successfully address one without compromising the other(s)?
Three point charges, q, 2q, and 3q, are at the vertices of an equilateral triangle of...
Three point charges, q, 2q, and 3q, are at the vertices of an equilateral triangle of sides a. If q= 15.8 nC and a= 11.1 cm, what is the magnitude of the electric field at the geometric center of the triangle? Please explain in details, in particular the trig to set up the equilateral triangle. I am confused.
Show the code how to add a node to the front of a list. Draw the...
Show the code how to add a node to the front of a list. Draw the picture also that goes with the code. NOW Show the code how to add a node to the end of a list. Draw the picture also that goes with the code. EXTRA CREDIT Show the code how to add a node to a specific spot in a list. Draw the picture also that goes with the code.
Part 1. Describe the boundaries of the triangle with vertices (0, 0), (2, 0), and (2,...
Part 1. Describe the boundaries of the triangle with vertices (0, 0), (2, 0), and (2, 6). (a) Describe the boundary with the top function, bottom function, left point, and right point. (b) Describe the boundary with the left function, right function, bottom point, and top point. Part 2. Consider the triangle with vertices (0, 0), (3, 0) and (6, 6). This triangle can be described using only one of the two perspectives presented above: top-bottom or left-right. Explain which...
Given the triangle with vertices at (1,4), (4,3), and (2,-1), sketch the image after the given...
Given the triangle with vertices at (1,4), (4,3), and (2,-1), sketch the image after the given transformation is applied. Based on your graph, identify the transformation as a translation, reflection, rotation, or other transformations, and state whether the transformation is an isometry. (x,y) -> (x,-y) (x,y) -> (y,-x) (x,y) -> (2x,2y) (x,y) -> (x+4,-y) (x,y) -> (5-x,y) (x,y) -> (x+4,y-3)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT