Advertisement
xavicano

Untitled

Aug 2nd, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.67 KB | None | 0 0
  1. '''   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
  2.         draw circles at different locations on the screen?
  3.        The goto(x, y) function moves the turtle to a specific location.
  4.        The penup() function lifts the pen so that the turtle doesn’t draw when it’s moving.
  5.        What do you think is the best order for the input parameters for your function?
  6.  
  7.    Can you create a similar function that draws rectangles of different sizes and shapes? You can look at the Modern Art project
  8.    for help with drawing rectangles.
  9.  
  10.    Use your functions to draw a picture or create some art.
  11. '''
  12.  
  13. from turtle import *
  14. from time import sleep
  15.  
  16. tina = Turtle()
  17.  
  18. def circle_area(r):
  19.     return 3.1416*r**2
  20.    
  21. def circle_perimeter(r):
  22.     return 2*3.1416*r
  23.  
  24. def square_area(r):
  25.     return r**2
  26.    
  27. def square_perimeter(r):
  28.     return 4*r
  29.    
  30.  
  31.  
  32. def draw_shape(x,y,t_name, r, col, shape):
  33.     t_name.goto(x,y)
  34.     t_name.pendown()
  35.    
  36.     t_name.color(col)
  37.     if shape=="circle":
  38.         t_name.dot(r*2)
  39.         t_name.color("black")
  40.         t_name.goto(0,5)
  41.         t_name.write("Area: " + str(circle_area(r)), align="center")
  42.         t_name.goto(0,-5)
  43.         t_name.write("Circumference: " + str(circle_perimeter(r)), align="center")
  44.     else:
  45.         t_name.shape(shape)
  46.         t_name.color("black")
  47.         t_name.goto(0,5)
  48.         t_name.write("Area: " + str(square_area(r)), align="center")
  49.         t_name.goto(0,-5)
  50.         t_name.write("Circumference: " + str(square_perimeter(r)), align="center")
  51.     t_name.penup()
  52.  
  53.  
  54. #draw_shape(5,5,tina, 150, "blue","turtle")
  55. draw_shape(100,100,tina, 100, "red","square")
  56. draw_shape(20,100,tina, 50, "yellow","circle")
  57.  
  58. sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement