In: Computer Science
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
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()
