Question

In: Computer Science

You will design and implement a graphics program that draws four concentric rectangles in a window,...

You will design and implement a graphics program that draws four concentric rectangles in a window, using four different colors of your choice, meeting the following specifications.

• The size of the window is determined by the user of the program. To be specific, you should prompt the user for both the width and height of the window (in pixels), and then you should set the size of the window using these values. (Hint: use the setup() method of the window.) Make the largest colored rectangle by setting the background color of the window. The three other colored rectangles will be drawn using the draw_rectangle() function described below in Program Design.

• After the first rectangle, the size of each rectangle will be half of the size of the one before it. Using the rectangles shown in the graphic as an example, the length and width of the red rectangle are half of the length and width of the blue rectangle, respectively. Then the length and width of the yellow rectangle are half of the length and width of the red rectangle, respectively, etc.

• You should use a for loop to draw the three rectangles. Because of this, only one line of code in your program should have a call to the function draw_rectangle().

• Use meaningful variable names.

• Use horizontal and vertical white space reasonably and consistently.

• Use named constants as appropriate.

Program Design Your program is to be implemented using the function draw_rectangle(), which draws a rectangle centered in the window of a specified size and color. In order to do this, start your program with exactly the following lines of codes: import turtle import sys sys.setExecutionLimit(60000) # 60 seconds def draw_rectangle(turt, width, height, color): turt.pencolor(color) turt.fillcolor(color) turt.up() x = - width / 2 y = height / 2 turt.goto(x,y) turt.down() turt.begin_fill() # Draw the top turt.setheading(0) turt.forward(width) # Draw the right side turt.right(90) turt.forward(height) # Draw the bottom turt.right(90) turt.forward(width) # Draw the left side turt.right(90) turt.forward(height) turt.end_fill() # Your code goes here

Please explain every step clearly and thoroughly in python, my python code keeps giving an error message.

Solutions

Expert Solution

Required program is given below:

import turtle
import sys
turt=turtle.Turtle()
def draw_rectangle(turt, width, height, color):
turt.pencolor(color)
turt.fillcolor(color)
turt.up()
x = -width / 2
y = height / 2
turt.goto(x,y)
turt.down()
turt.begin_fill() # Draw the top
turt.setheading(0)
turt.forward(width) # Draw the right side
turt.right(90)
turt.forward(height) # Draw the bottom
turt.right(90)
turt.forward(width) # Draw the left side
turt.right(90)
turt.forward(height)
turt.end_fill()
sc=turtle.Screen()
print("enter width : ")
width=int(input())
print("enter hight : ")
hight=int(input())
sc.setup(width,hight)#it will set the screen size according to user demand
l=['red','blue','yellow','green']
for color in l:
draw_rectangle(turt,width,hight,color)
width=width/2
hight=hight/2
sc.exitonclick() #it will exit the window when we click on screen

NOTE: In above program when I used "sys.setExecutionLimit(60000)" then it show error because may be my python version not supporting it so to close the program I used "sc.exitonclick()" in my program if your interpreter supports "sys.setExecutionLimit(60000)" than you can use it.

Above program interpreter image is given below:

Screenshots of output of above program is given below:

case1

case2

PLEASE UPVOTE THE ANSWER AND FEEL FREE TO ASK YOUR DOUBTS IN COMMENT SECTION


Related Solutions

Write a Python graphics program that draws the following shapes: • window size: 250 x 250...
Write a Python graphics program that draws the following shapes: • window size: 250 x 250 pixels with window title with your name • big circle, 50 pixels radius with center at (125, 125) • two green circles, 10 pixels radius; first one centered at (113, 113) and second centered at (137, 113) • one red line, from (100, 150) to (150, 150) Then answer this, what do you see? (make this a comment in your code)
Write a graphics program that creates a graphics window that is 500 pixels wide and 300 pixels high.
IN PYTHON Write a graphics program that creates a graphics window that is 500 pixels wide and 300 pixels high. Then draw a blue circle with radius 25 at (x,y) = (100,150). Then have the ‘ball’ (ie the circle) move horizontally to the right by 5 pixel steps, until it reaches x = 200. Then have it change color to red and move back to the starting point.
Design a simple program, using pseudocode, to implement the recursive formula you found in part (a)...
Design a simple program, using pseudocode, to implement the recursive formula you found in part (a) to compute numbers in the Fibonacci sequence. Describe in detail how your program implements the recursive formula. You may find it useful to discuss how it through a concrete example such as F(8) = 21.
Design and implement a Java program that creates a GUI that will allow a customer to...
Design and implement a Java program that creates a GUI that will allow a customer to order pizza and other items from a Pizza Paarlor. The customer should be able to order a variety of items which are listed below. The GUI should allow the customer (viaJavaFX UI Controls - text areas, buttons, checkbox, radio button, etc.) to input the following information: Name of the customer First Name Last Name Phone number of the customer Type of food being order...
Design and implement a C++ program that performs the following steps:Ask the user to enter a...
Design and implement a C++ program that performs the following steps:Ask the user to enter a positive integer number N; Your program may need to prompt the user to enter many times until it reads in a positive number;Let user to enter N (obtained in the previous step) floating point numbers, and count how many positive ones there are in the sequence and sum up these positive numbers; (Hint: negative numbers or 0 are ignored).Display result.You can and should use...
Design and implement a program in python that takes a list of items along with quantities...
Design and implement a program in python that takes a list of items along with quantities or weights. The program should include at least two function definition that is called within the main part of your program. Each item has a price associated by quantity or weight. The user enters the item along with the quantity or weight and the program prints out a table for each item along with the quantity/weight and total price. Your program should be able...
Design and implement a C++ program read in a whole line of characters as the input...
Design and implement a C++ program read in a whole line of characters as the input string; count and display how many times how frequently (among the letters) each (case insensitive) letter appears in the above mentioned input string; Sample program execution: An example of executing such a program is shown below. Note that the user input is in italic font. Please enter a line of characters: This is a really long line of characters! There are 41 characters in...
IN C++ PLEASE!!! Design and implement a program (name it Coins) that determines the values of...
IN C++ PLEASE!!! Design and implement a program (name it Coins) that determines the values of coins in a jar. The program prints out the total dollars and cents in the jar. The program prompts the user to enter the number of coins (quarters, dimes, nickels, and pennies). Print out the number of coins entered for each coin type on separate lines followed by the total amount of money in the jar as dollars and cents as shown below.
Design and implement a program that reads a series of 10 integers from the user and...
Design and implement a program that reads a series of 10 integers from the user and prints their average. Read each input value as a string, and then attempt to convert it to an integer using the Integer.parseInt method. If this process throws a NumberFormatException (meaning that the input is not a valid number), print an appropriate error message and prompt for the number again. Continue reading values until 10 valid integers have been entered.
1. Design and implement a program that reads a series of integers from the user and...
1. Design and implement a program that reads a series of integers from the user and continually prints their average after every reading. The input stops when the user enters “stop” as the input value. Read each input value as a string, then check if it is “stop” or not. If the string is not “stop”, then, attempt to convert it to an integer using the Integer.parseInt method. If this process throws a NumberFormatException, meaning that the input is not...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT