Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' At the moment all our circles are drawn at the centre of the screen. Can you add parameters to the draw_circle function so that you can
- draw circles at different locations on the screen?
- The goto(x, y) function moves the turtle to a specific location.
- The penup() function lifts the pen so that the turtle doesn’t draw when it’s moving.
- What do you think is the best order for the input parameters for your function?
- Can you create a similar function that draws rectangles of different sizes and shapes? You can look at the Modern Art project
- for help with drawing rectangles.
- Use your functions to draw a picture or create some art.
- '''
- from turtle import *
- from time import sleep
- tina = Turtle()
- def circle_area(r):
- return 3.1416*r**2
- def circle_perimeter(r):
- return 2*3.1416*r
- def square_area(r):
- return r**2
- def square_perimeter(r):
- return 4*r
- def draw_shape(x,y,t_name, r, col, shape):
- t_name.goto(x,y)
- t_name.pendown()
- t_name.color(col)
- if shape=="circle":
- t_name.dot(r*2)
- t_name.color("black")
- t_name.goto(0,5)
- t_name.write("Area: " + str(circle_area(r)), align="center")
- t_name.goto(0,-5)
- t_name.write("Circumference: " + str(circle_perimeter(r)), align="center")
- else:
- t_name.shape(shape)
- t_name.color("black")
- t_name.goto(0,5)
- t_name.write("Area: " + str(square_area(r)), align="center")
- t_name.goto(0,-5)
- t_name.write("Circumference: " + str(square_perimeter(r)), align="center")
- t_name.penup()
- #draw_shape(5,5,tina, 150, "blue","turtle")
- draw_shape(100,100,tina, 100, "red","square")
- draw_shape(20,100,tina, 50, "yellow","circle")
- sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement