- 거북이 한마리의 1차원 리스트
: [거북이, X위치, Y위치, 거북이크기, 거북이색상(R), 거북이색상(G), 거북이색상(B)]
- 2차원 리스트
: [[거북이1, X, Y, 크기, R, G, B], [거북이2, X, Y, 크기, R, G, B], [거북이3, X, Y, 크기, R, G, B] ...]
import turtle
import random
myTurtle, tX, tY, tColor, tSize, tShape = [None]*6
shapeList = []
playerTurtles = []
swidth, sheight = 500, 500
def main():
turtle.title('거북 리스트 활용')
turtle.setup(width = swidth + 50, height = sheight + 50)
turtle.screensize(swidth, sheight)
shapeList = turtle.getshapes()
for i in range(0, 100):
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 tList in playerTurtles:
myTurtle = tList[0]
myTurtle.color((tList[4], tList[5], tList[6]))
myTurtle.pencolor((tList[4], tList[5], tList[6]))
myTurtle.turtlesize(tList[3])
myTurtle.goto(tList[1], tList[2])
turtle.done()
if __name__ == "__main__" :
main()
random.shuffle(shapeList)
myTurtle = turtle.Turtle(shapeList[0])
tmpShape = random.choice(shapeList)
myTurtle = turtle.Turtle(tmpShape)