Advertisement
timber101

Funtions with parameters

Dec 16th, 2020
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. #  parameters
  2.  
  3. from turtle import *
  4. from random import randint
  5.  
  6. colormode(255) # needed as different colour mode used??
  7. tina = Turtle()
  8.  
  9.  
  10.  
  11. def draw_circle(t_name, xpos, ypos, radius, col):
  12.     t_name.goto(xpos, ypos)
  13.     t_name.pendown() # order is important!!
  14.     t_name.color(col) # set the colour first
  15.     t_name.dot(radius*2)
  16.     t_name.penup()
  17.    
  18. def draw_rectangle(t_name, xpos, ypos,  t_width, t_height, color):
  19.     t_name.penup()
  20.     t_name.goto(xpos,ypos)
  21.     t_name.color("pink")
  22.     t_name.pendown()
  23.     t_name.begin_fill()
  24.     t_name.forward(t_width)
  25.     t_name.right(90)
  26.     t_name.forward(t_height)
  27.     t_name.right(90)    
  28.     t_name.forward(t_width)
  29.     t_name.right(90)    
  30.     t_name.forward(t_height)
  31.     t_name.right(90)
  32.     t_name.end_fill()
  33.    
  34.    
  35. def randomcolour():
  36.     red = randint(0,255)
  37.     green = randint(0, 255)
  38.     blue = randint(0, 255)
  39.     color(red, green, blue)
  40.    
  41. def randomplace():
  42.     x = randint(-180, 180)
  43.     y = randint(-180, 180)
  44.     goto(x,y)
  45.    
  46.    
  47. def randomrect():
  48.     height = randint(-50, 50)
  49.     width = randint(-50, 50)
  50.     penup()
  51.     randomplace()
  52.     randomcolour()
  53.     pendown()
  54.     begin_fill()
  55.     forward(width)
  56.     right(90)
  57.     forward(height)
  58.     right(90)    
  59.     forward(width)
  60.     right(90)    
  61.     forward(height)
  62.     right(90)
  63.     end_fill()
  64.  
  65.  
  66.    
  67.    
  68.  
  69. # tina.dot(100)
  70.  
  71. draw_circle(tina, 20, 20, 160, "yellow")
  72. draw_circle(tina, -50, -60, 80, "blue")
  73. draw_circle(tina, 99, 99, 40, "green")
  74.  
  75. draw_rectangle(tina, 50, -40, 100, 100, "grey")
  76.  
  77. randomrect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement