Question

In: Computer Science

Create program in Python (using import turtle): 1)includes draw_background function 2)draw_background function uses a loop to...

Create program in Python (using import turtle):

1)includes draw_background function

2)draw_background function uses a loop to draw a background from at least one shape

3)uses at least 2 turtles to draw scent

4)includes draw_shape function

5)includes function to draw primary object

6)includes main method which creates the drawing

Solutions

Expert Solution

We have to know about Turtle. In computer graphics, turtle graphics are vector graphics using a relative cursor (the "turtle") upon a Cartesian plane. Turtle graphics is a key feature of the Logo programming language.

In Python, a function is a named sequence of statements that belong together. Their primary purpose is to help us organize programs into chunks that match how we think about the problem.

The syntax for a function definition is

def NAME( PARAMETERS ):
    STATEMENTS

Suppose we’re working with turtles, and a common operation we need is to draw squares. “Draw a square” is an abstraction, or a mental chunk, of a number of smaller steps. So let’s write a function to capture the pattern of this “building block”:

import turtle

 def draw_square(t, sz):
     """Make turtle t draw a square of sz."""
     for i in range(4):
         t.forward(sz)
         t.left(90)


 wn = turtle.Screen()        # Set up the window and its attributes
 wn.bgcolor("lightgreen")
 wn.title("Alex meets a function")

 alex = turtle.Turtle()      # Create alex
 draw_square(alex, 50)       # Call the function to draw the square
 wn.mainloop()

Output would be like this

Once we’ve defined a function, we can call it as often as we like, and its statements will be executed each time we call it. And we could use it to get any of our turtles to draw a square. In the next example, we’ve changed the draw_square function a little, and we get tess to draw 15 squares, with some variations.

import turtle

def draw_multicolor_square(t, sz):
    """Make turtle t draw a multi-color square of sz."""
    for i in ["red", "purple", "hotpink", "blue"]:
        t.color(i)
        t.forward(sz)
        t.left(90)

wn = turtle.Screen()        # Set up the window and its attributes
wn.bgcolor("lightgreen")

tess = turtle.Turtle()      # Create tess and set some attributes
tess.pensize(3)

size = 20                   # Size of the smallest square
for i in range(15):
    draw_multicolor_square(tess, size)
    size = size + 10        # Increase the size for next time
    tess.forward(10)        # Move tess along a little
    tess.right(18)          #    and give her some turn

wn.mainloop()


Related Solutions

2) create a python program that uses a for loop and range to print out the...
2) create a python program that uses a for loop and range to print out the values 10 8 6 4 2 3) Create a python program that yses a for loop to print out ["bob","al","bert"]
Python 3 Calculate factorial Create a function that uses a loop to calculate the factorial of...
Python 3 Calculate factorial Create a function that uses a loop to calculate the factorial of a number. * function name: get_fact * parameters: num (int) * returns: int * operation: Must use a loop here. Essentially calculate and return the factorial of whatever number is provided. but: - If num is less than 1 or greater than 20, print "num is out of range" and exit the function - If num is not an int, print "invalid num parameter"...
What would the Python code be to create the following working program using turtle: -Make 4...
What would the Python code be to create the following working program using turtle: -Make 4 turtles that are YELLOW, and 4 turtles that are GREEN. Create these turtles using one or more lists. -Make the yellow turtles start at a different randomized location somewhere on the left side of the screen within the range of (-100,100) and (0, -100) -Make the green turtles start at a different randomized location somewhere on the right side of the screen within the...
with python, create a fake logo for a company using turtle graphics
with python, create a fake logo for a company using turtle graphics
In C++ using a single dimensional array Create a program that uses a for loop to...
In C++ using a single dimensional array Create a program that uses a for loop to input the day, the high temperature, and low temperature for each day of the week. The day, high, and low will be placed into three elements of the array. For each loop the day, high, and low will be placed into the next set of elements of the array. After the days and temps for all seven days have been entered into the array,...
Using C++ language, create a program that uses a struct with array variables that will loop...
Using C++ language, create a program that uses a struct with array variables that will loop at least 3 times and get the below information: First Name Last Name Job Title Employee Number Hours Worked Hourly Wage Number of Deductions Claimed Then, determine if the person is entitled to overtime and gross pay. Afterwards, determine the tax and net pay. Output everything to the screen. Use functions wherever possible. Bonus Points: Use an input file to read in an unknown...
Python Create Loop 1 = 1 1 + 2 = 3 1 + 2 + 3...
Python Create Loop 1 = 1 1 + 2 = 3 1 + 2 + 3 = 6 1 + 2 + 3 + 4 = 10 1 + 2 + 3 + 4 + 5 = 15 Create a loop in python that makes this pattern
Your (turtle) program in python must include: Create four Red turtles and four Blue turtles using...
Your (turtle) program in python must include: Create four Red turtles and four Blue turtles using one or more lists. • Start each of the Red turtles at a different random location on the left side of the screen within the range of the square formed by (-100, 100) and (0, -100) and each of the Blue turtles at a random location on the right side of the screen within the range of the square formed by (0, 100) and...
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
1. Write a python program to create a list of integers using random function. Use map...
1. Write a python program to create a list of integers using random function. Use map function to process the list on the expression: 3x2+4x+5 and store the mapped elements in another list. Now use filter to do sum of all the elements in another list. 2. Write a function that takes n as input and creates a list of n lists such that ith list contains first 10 multiples of i. 3. Write a function that takes a number...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT