Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from turtle import *
- from random import randint
- colormode(255) # needed as different colour mode used??
- tina = Turtle()
- def draw_circle(t_name, xpos, ypos, radius, col):
- t_name.goto(xpos, ypos)
- t_name.pendown() # order is important!!
- t_name.color(col) # set the colour first
- t_name.dot(radius*2)
- t_name.color("black")
- t_name.goto(xpos,ypos+5)
- t_name.write("Area: "+ str(round(circ_circum(radius),3)), align="center")
- t_name.goto(xpos,ypos-5)
- t_name.write("Circum: "+ str(round(circ_area(radius),3)), align="center")
- t_name.penup()
- def draw_rectangle(t_name, xpos, ypos, t_width, t_height, color):
- t_name.penup()
- t_name.goto(xpos,ypos)
- t_name.color("pink")
- t_name.pendown()
- t_name.begin_fill()
- t_name.forward(t_width)
- t_name.right(90)
- t_name.forward(t_height)
- t_name.right(90)
- t_name.forward(t_width)
- t_name.right(90)
- t_name.forward(t_height)
- t_name.right(90)
- t_name.end_fill()
- t_name.penup()
- #print(t_name.pos()[0]) experimenting with pos()
- if ypos<0 :
- ypost = ypos - (t_height/2)
- else:
- ypost = ypos + (t_height/2)
- t_name.goto((xpos + t_width/2), ypost) # this has a problem
- t_name.color("black")
- t_name.pendown()
- t_name.write(f"perimeter = {rect_perim(t_width, t_height)}", align="center") # ooh f strings work!
- #print(t_height) error tracing
- #print(t_width)
- t_name.penup()
- def circ_circum(r):
- return 3.142 * 2 * r
- def circ_area(r):
- return 3.142 * r * r
- def rect_perim(w,h):
- #print(w) testing out put as was geting error
- #print(h)
- return((w+h) *2) # error was here originally had (w + h * 2) school boy error
- def rect_area(w,h):
- return(w * h)
- def randomcolour():
- red = randint(0,255)
- green = randint(0, 255)
- blue = randint(0, 255)
- color(red, green, blue)
- def randomplace():
- x = randint(-180, 180)
- y = randint(-180, 180)
- goto(x,y)
- def randomrect():
- height = randint(-50, 50)
- width = randint(-50, 50)
- penup()
- randomplace()
- randomcolour()
- pendown()
- begin_fill()
- forward(width)
- right(90)
- forward(height)
- right(90)
- forward(width)
- right(90)
- forward(height)
- right(90)
- end_fill()
- # tina.dot(100)
- draw_circle(tina, 20, 20, 160, "yellow")
- draw_circle(tina, -50, -60, 80, "blue")
- draw_circle(tina, 99, 99, 40, "green")
- draw_rectangle(tina, -50, -40, 100, 100, "grey")
- randomrect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement