The assignment was to create a code that would draw random shapes(in this case I chose triangles, squares, and circles). The pensize, pen color,fill color, and size must all be random but i can only get the rectangles to function correctly. The fill color in the triangles and circles keep coming up as the same as color as the pen. Any suggestions?
import turtle as t
import random as r
colors = ["red", "orange", "yellow", "green", "blue", "pink", "purple", "black", "green yellow", "chocolate", "yellow", "sienna", "tan", "salmon"]
pensize = [1,2,3,4,5,6,7,8,9,10]
def draw_triangle():
a = r.randint(-200,200)
b = r.randint(-200,200)
y = r.randint(50,70)
t.penup()
t.goto(a,b)
t.pencolor(random.choice(colors))
t.pensize(random.choice(pensize))
t.color(random.choice(colors))
t.begin_fill()
t.pendown()
t.forward(y)
t.right(90)
t.forward(y)
t.goto(a,b)
t.end_fill()
t.penup()
def draw_square():
a = r.randint(-200,200)
b = r.randint(-200,200)
y = r.randint(50,70)
t.penup()
t.goto(a,b)
t.pendown()
x = r.randint(1,40)
t.color(random.choice(colors))
t.pensize(random.choice(pensize))
t.pencolor(random.choice(colors))
t.begin_fill()
t.forward(x)
t.left(90)
t.forward(x)
t.left(90)
t.forward(x)
t.left(90)
t.forward(x)
t.end_fill()
t.penup()
def draw_circle():
a = r.randint(-200,200)
b = r.randint(-200,200)
y = r.randint(50,70)
t.pensize(random.choice(pensize))
t.pencolor(random.choice(colors))
t.penup()
t.goto(a,b)
t.pendown()
a =r.randint(1,40)
b = r.randint(1,40)
x = r.randint(1,40)
t.begin_fill()
t.color(random.choice(colors))
t.circle(x)
t.end_fill()
t.penup()
def total():
t.speed(5)
for i in range(20):
draw_triangle()
draw_square()
draw_circle()
#mainbody#
total()
Aucun commentaire:
Enregistrer un commentaire