Question

Please help: For this project, you will create a shape drawing program using Turtle graphics. Your...

Please help:

For this project, you will create a shape drawing program using Turtle graphics. Your program will begin by asking the user how many points they would like to enter (# of vertices for the shape). Next, you will use a loop to input each X and Y coordinate and store these coordinates in lists. After inputting all of the coordinates, create a second loop that will draw and fill the shape using the coordinates that were entered. All of this will be inside a loop that will ask the user if they want to draw another shape. If the user enters yes, clear the screen and repeat the process. If the user enters no, the program will exit. The minimum requirements are listed below:

For all of your input for this program, you should use either the turtle.numinput or turtle.textinput function. You can find more information on these functions here: https://docs.python.org/3.1/library/turtle.html#turtle.numinput (Links to an external site.)

Create InputDimensions function (no parameters, x and y coordinate lists are the return values) - This function will ask the user how many coordinates they want to enter (validate the input) and then use a loop to input each of the X and Y coordinates. Store each of the X and Y coordinates in your lists. You can use the turtle.numinput() function to input each of these values. Make sure your prompt includes the loop index (coordinate #) so the user knows which coordinate they are currently inputting -- something like "Input the X value for coordinate #1".

Create DrawShape function (x and y coordinates are the function parameters, no return value) - This function will use the begin_fill and end_fill functions along with a loop to go to each of the coordinates in the X and Y coordinate lists.

Your main function will contain the loop that asks the user if they want to draw another shape. For extra credit, you can include additional options like inputting the fill color, pen size, background color, etc. from the user. You can use the turtle.textinput function to input this information.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: Please maintain proper code spacing (indentation), just copy the code part and paste it in your compiler/IDE directly, no modifications required.

#code

import turtle

''' method to input number of coordinates and coordinates'''
def InputDimensions():
    #reading # of vertices
    n=turtle.numinput('Input','Enter the number of vertices for the shape: ')
    n=int(n) #n is float now, converting to int
    points=[] #empty list
    #looping for n times
    for i in range(n):
        #reading x value for current vertex
        x=turtle.numinput('Input','Enter the x coordinate for vertex #{}'.format(i))
        # reading y value for current vertex
        y = turtle.numinput('Input', 'Enter the y coordinate for vertex #{}'.format(i))
        #appending x,y as a tuple to points list
        points.append((x,y))
    #returning list
    return points

''' method to draw the shape, given list of coordinates'''
def DrawShape(coordinates):
    #if coordinates list is empty, returning
    if len(coordinates)==0:
        return
    #pen up
    turtle.up()
    #positioning turtle at first coordinate ((x,y) tuple)
    turtle.goto(coordinates[0])
    #pen down
    turtle.down()
    #start to fill
    turtle.begin_fill()
    #looping through remaining points
    for point in coordinates[1:]:
        #moving turtle to current point
        turtle.goto(point)
    #end of fill
    turtle.end_fill()


def main():
    ch='Y'
    #looping as long as ch is not None and is 'Y' or 'y'
    while ch!=None and ch.upper()=='Y':
        #clearing screen
        turtle.Screen().clear()
        #reading fill color and bg color
        fillcolor=turtle.textinput('Input','Enter fill color:')
        turtle.fillcolor(fillcolor)
        bgcolor = turtle.textinput('Input', 'Enter background color:')
        turtle.Screen().bgcolor(bgcolor)
        #reading points
        points=InputDimensions()
        #drawing shape
        DrawShape(points)
        #asking if user likes to draw anather shape
        ch=turtle.textinput('Input','Do you want to draw another shape? Y/N')
    #finishing off
    turtle.done()

#calling main()
main()

#OUTPUT (partial)

Python Turtle Graphics Input Enter fill color: red Cancel OK X

Python Turtle Graphics X Input Enter background color: yellow Cancel ок

Python Turtle Graphics Input Enter the number of vertices for the shape: Ок Cancel

Python Turtle Graphics Input Enter the x coordinate for vertex #0 Cancel Ок X

X Python Turtle Graphics

Add a comment
Know the answer?
Add Answer to:
Please help: For this project, you will create a shape drawing program using Turtle graphics. Your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use Python 3 Create a program that uses Turtle to draw shapes. Show the following menu:...

    Use Python 3 Create a program that uses Turtle to draw shapes. Show the following menu: Enter Circle Enter Rectangle Remove Shape Draw Shapes Exit Circles – User inputs position, radius, and color. The position is the CENTER of the circle Rectangles – User inputs position, height, width, color. The position is the lower left-hand corner Colors – Allow red, yellow, blue, and green only Remove – Show the number of items in the list and let the user enter...

  • Please help with this python turtle problem using the functions provided. Python Turtle Write a program...

    Please help with this python turtle problem using the functions provided. Python Turtle Write a program using the turtle module to draw the face of a clock that looks like the image below. You will need to use the turtle module for this exercise as well as the bgcolor), shape(), color), penup), right(), forward(), pendown(), and stamp() functions. The code below can be removed or changed as needed. import turtle t turtle.Turtle0 t.forward(75)

  • Write a program which will Ask the user a series of questions using the Scanner object Based on t...

    Write a program which will Ask the user a series of questions using the Scanner object Based on the input, draw a grid of star figures on the DrawingPanel You program should ask your user: . What R, G & B values to create a color to draw the figure? How many stars across should the fgure be? How many stars tall should the figure be? Note that your program does not need to error check the users responses Your...

  • Write a C program that does the following: • Displays a menu (similar to what you...

    Write a C program that does the following: • Displays a menu (similar to what you see in a Bank ATM machine) that prompts the user to enter a single character S or D or Q and then prints a shape of Square, Diamond (with selected height and selected symbol), or Quits if user entered Q. Apart from these 2 other shapes, add a new shape of your choice for any related character. • Program then prompts the user to...

  • Java program GCompound Practice Exercise CS141 Assignment Write a class that represents a digital snowman. Your...

    Java program GCompound Practice Exercise CS141 Assignment Write a class that represents a digital snowman. Your class should follow these guidelines: 1. Store the following private class variables bodyColor of type Color b. int x, int y for the upper left corner Graphics g. a. C. 2. Create two different constructor methods a. A (int x, int y, Graphics myG) parameter constructor that makes the snowman a light gray color by default and makes x and y the upper left...

  • This is a c++ question we are not using namespace std at the top Subtraction +...

    This is a c++ question we are not using namespace std at the top Subtraction + Decision and Loop This is a twist on the previous exercise that will help you review loops and decision structures. You will again ask the user to enter two numbers. However, you will ALWAYS subtract the smaller number from the larger number to ensure that you never get a negative number for an answer. You do this by checking the numbers and switching them...

  • Python 3 coding with AWS/Ide. Objective: The purpose of this lab is for you to become familiar with Python’s built-in te...

    Python 3 coding with AWS/Ide. Objective: The purpose of this lab is for you to become familiar with Python’s built-in text container -- class str-- and lists containing multiple strings. One of the advantages of the str class is that, to the programmer, strings in your code may be treated in a manner that is similar to how numbers are treated. Just like ints, floats, a string object (i.e., variable) may be initialized with a literal value or the contents...

  • In this project you will create a console C++ program that will have the user to...

    In this project you will create a console C++ program that will have the user to enter Celsius temperature readings for anywhere between 1 and 365 days and store them in a dynamically allocated array, then display a report showing both the Celsius and Fahrenheit temperatures for each day entered. This program will require the use of pointers and dynamic memory allocation. Getting and Storing User Input: For this you will ask the user how many days’ worth of temperature...

  • MATLAN Quiz 2 Create a MATLAB function that calculates the average of values in a vector that als...

    MATLAN Quiz 2 Create a MATLAB function that calculates the average of values in a vector that also drops the slowest values. Call this function average_drop(). The function must have a single input (the vector) and a single output (the average without the lowest score). 1. 2. Create a MATLAB program that asks the user to input grades for a student and calculates the final grade and letter grade. The user must enter 5 quiz grades (worth 50% of the...

  • In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while...

    In Python! Create the program that print out only odd numbers 1,3,5,7,9 Use either a while loop or a for loop to print only odd numbers 1, 3, 5, 7, 9 *tip: you can use range () function, or a condition with ‘break’ (e.g, while count < 10) In python!: Create a program that print out 12 months of a year and associated numbers (e.g., January 1, February 2…). Two lists should be created, and then loop through the list...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT