My code lets the user input the turtle count. Then, it will show the amount of input with random turtle shapes and colors. I want to add 3 functions to my turtle graphics code.
- "Please enter the number of turtles: "
- Function to initialize the turtle array by receiving the number of turtles as a parameter
- Finally, the function draws the turtle
Please help me, here is my code:
import turtle
import random
myturtle,tx,ty,tcolor,tsize,tshape=[None]*6
shapelist=[]
playerturtles=[]
swidth,sheight=500,500
if __name__=='__main__':
turtle.title('Turtle list utilization')
turtle.setup(width=swidth+50,height=sheight+50)
turtle.screensize(swidth,sheight)
shapelist=turtle.getshapes()
a=int(input('Turtle Count:'))
for i in range(0,a):
random.shuffle(shapelist)
myturtle=turtle.Turtle(shapelist[0])
tx=random.randrange(-swidth/2,swidth/2)
ty=random.randrange(-sheight/2,sheight/2)
r=random.random();g=random.random();b=random.random()
tsize=random.randrange(1,3)
playerturtles.append([myturtle,tx,ty,tsize,r,g,b])
for i in range(0,a):
myturtle=playerturtles[i][0]
myturtle.color((playerturtles[i][4],playerturtles[i][5],playerturtles[i][6]))
myturtle.pencolor((playerturtles[i][4],playerturtles[i][5],playerturtles[i][6]))
myturtle.turtlesize(playerturtles[i][3])
myturtle.goto(playerturtles[i][1],playerturtles[i][2])
turtle.done()