Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

create these functions: for exercise 6.41: **6.41 (Turtle: draw points, rectangles, and circles) Use the functions defined in Listing 6.14 to write a program that

create these functions: for exercise 6.41:

image text in transcribed

image text in transcribedimage text in transcribed

**6.41 (Turtle: draw points, rectangles, and circles) Use the functions defined in Listing 6.14 to write a program that displays a rectangle centered at (75, 0) with width and height 100 and a circle centered at (50, 0) with radius 50. Fill 10 random points inside the rectangle and 10 inside the circle, as shown in Figure 6.11c. create the following functions: distance(xa, ya, xb, yb): it calculate and returns the distance between (xa, ya) and (xb, yb) this calculation is already created : def distance(xa, ya, xb, yb): distance = ((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb)) ** 0.5 return distance drawPointsInCircle(): This function needs to draw 10 random dots. Use random.randint(0,100) and random.randint(-50,50) to generate random x and y values. Measure the distance to the center of the circle (using the distance() function above), and if the result is 50 or less, then draw a dot at that (x,y) location using drawPoint function: def drawPoint(x, y): turtle.penup() turtle.goto(x, y) turtle.pendown() turtle.begin_fill() turtle.circle(3) turtle.end_fill() Use a while loop in which you count the points that are inside the circle. When the program has already counted 10, the loop can end. drawPointsInSquare(): This function should draw 10 random dots in the square. Use random.randint(-125, -25) and random.randint(-50, 50) to generate random x and y values. These coordinates may not be inside the square so just draw a dot at the generated (x, y) point using the drawPoint function. You may use a for loop because all the generated coordinates will be inside the square. main(): This function will coordinate the actions in the programs, it should call drawPointsInCircle and drawPointsInSquare. Add this main() call at the end to execute the program 10 # Write a strings at the specified location (x, y) 11 def writeText(s, x, y): 12 turtle.penup) # Pull the pen up 13 turtle.goto(x, y) 14 turtle.pendown 0 # Pull the pen down 15 turtle.write(5) # Write a string 16 17 # Draw a point at the specified location (x, y) 18 def drawPoint(x, y): 19 turtle.penup # Pull the pen up 20 turtle.goto(x, y) 21 turtle.pendown # Pull the pen down 22 turtle.begin_fil10 # Begin to fill color in a shape 23 turtle.circle(3) 24 turtle.end_fillo # Fill the shape 25 26 # Draw a circle centered at (x, y) with the specified radius 27 def drawCircle(x = 0, y = 0, radius = 10): 28 turtle.penup) # Pull the pen up 29 turtle.goto (x, y - radius) 30 turtle.pendown # Pull the pen down 31 turtle.circle(radius) 32 33 # Draw a rectangle at (x, y) with the specified width and height 34 def drawRectangle(x = 0, y = 0, width = 10, height = 10): 35 turtle.penup # Pull the pen up 36 turtle.goto(X + width/2, y + height / 2) 37 turtle.pendown() # Pull the pen down 38 turtle.right(90) 39 turtle. forward(height) 40 turtle.right(90) 41 turtle. forward(width) 42 turtle.right(90) 43 turtle. forward(height) 44 turtle.right(90) 45 turtle.forward(width)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

Students also viewed these Databases questions

Question

Management (inaugurated) the recycling policy six months ago.

Answered: 1 week ago