# with text

Dec 16th, 2020
602
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from turtle import *
2. from random import randint
3.
4. colormode(255) # needed as different colour mode used??
5. tina = Turtle()
6.
7.
8.
9. def draw_circle(t_name, xpos, ypos, radius, col):
10.     t_name.goto(xpos, ypos)
11.     t_name.pendown() # order is important!!
12.     t_name.color(col) # set the colour first
14.     t_name.color("black")
15.     t_name.goto(xpos,ypos+5)
17.     t_name.goto(xpos,ypos-5)
19.     t_name.penup()
20.
21.
22. def draw_rectangle(t_name, xpos, ypos,  t_width, t_height, color):
23.     t_name.penup()
24.     t_name.goto(xpos,ypos)
25.     t_name.color("pink")
26.     t_name.pendown()
27.     t_name.begin_fill()
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.forward(t_width)
33.     t_name.right(90)
34.     t_name.forward(t_height)
35.     t_name.right(90)
36.     t_name.end_fill()
37.     t_name.penup()
38.     #print(t_name.pos()[0])  experimenting with pos()
39.
40.     if ypos<0 :
41.         ypost = ypos - (t_height/2)
42.     else:
43.         ypost = ypos + (t_height/2)
44.
45.     t_name.goto((xpos + t_width/2), ypost) # this has a problem
46.     t_name.color("black")
47.     t_name.pendown()
48.     t_name.write(f"perimeter = {rect_perim(t_width, t_height)}", align="center") # ooh f strings work!
49.     #print(t_height)  error tracing
50.     #print(t_width)
51.     t_name.penup()
52.
53. def circ_circum(r):
54.     return 3.142 * 2 * r
55.
56. def circ_area(r):
57.     return 3.142 * r * r
58.
59. def rect_perim(w,h):
60.     #print(w) testing out put as was geting error
61.     #print(h)
62.     return((w+h) *2) #  error was here originally had (w + h * 2)  school boy error
63.
64. def rect_area(w,h):
65.     return(w * h)
66.
67.
68. def randomcolour():
69.     red = randint(0,255)
70.     green = randint(0, 255)
71.     blue = randint(0, 255)
72.     color(red, green, blue)
73.
74. def randomplace():
75.     x = randint(-180, 180)
76.     y = randint(-180, 180)
77.     goto(x,y)
78.
79.
80. def randomrect():
81.     height = randint(-50, 50)
82.     width = randint(-50, 50)
83.     penup()
84.     randomplace()
85.     randomcolour()
86.     pendown()
87.     begin_fill()
88.     forward(width)
89.     right(90)
90.     forward(height)
91.     right(90)
92.     forward(width)
93.     right(90)
94.     forward(height)
95.     right(90)
96.     end_fill()
97.
98.
99.
100.
101.
102. # tina.dot(100)
103.
104. draw_circle(tina, 20, 20, 160, "yellow")
105. draw_circle(tina, -50, -60, 80, "blue")
106. draw_circle(tina, 99, 99, 40, "green")
107.
108. draw_rectangle(tina, -50, -40, 100, 100, "grey")
109.
110. randomrect()
111.
112.