Exemplo n.º 1
0
def main():
  #设置一个画面
  windows = turtle.Screen()
  #设置背景
  windows.bgcolor('blue')
  turtle.register_shape('love',((0,0),(16,0),(16,8),(8,8),(8,16),(0,16)))
  turtle.title('welcome to the turtle zoo')
  #生成一个黄色乌龟
  bran = turtle.Turtle()
  #poly = ((0,0),(10,-5),(0.10),(-10,-5))
  #s = turtle.Shape("compound")
  #s.addcomponent(poly,'red','blue')
  #bran.shape(s)
  bran.color('yellow')
  #开始你的表演

  turtle_shape = turtle.getshapes()
  length = len(turtle_shape)
  for index,shapepart in enumerate(turtle_shape):
    bran.shape(shapepart)
    bran.speed(1)
    bran.forward(100)
    bran.right(90)
    bran.forward(100)
    bran.right(90)
    bran.forward(100)
    bran.right(90)
    bran.forward(100)
    bran.right(40)
    print index,shapepart
Exemplo n.º 2
0
def ex2():
	turtle.register_shape("myname", ((50,0),(50,50),(25,75),(0,50),(0,0)))

	turtle.shape("myname")
	turtle.getshapes()
	turtle.begin_fill()
	turtle.forward(50)
	turtle.right(90)
	turtle.forward(50)
	turtle.right(30)
	turtle.forward(50)
	turtle.right(120)
	turtle.forward(50)
	turtle.right(30)
	turtle.forward(50)

	turtle.end_fill()
Exemplo n.º 3
0
import turtle
import random

##전역 변수 선언 부분##
myTurtle, tX, tY, tColor, tSize, TShape = [None] * 6
shapeList = []
playerTurtles = []
swidth, sheight = 500, 500

##메인코드부분##
if __name__ == '__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]))
Exemplo n.º 4
0
# The most important part of this program is making a group with each turtle's information as a listed form.

import turtle as t
import random as rd

myTurtle, tX, tY, tColor, tSize, tShape = [None] * 6
shapeList = []
playerTurtles = []
swidth, sheight = 500, 500

if __name__ == "__main__":
    t.title("거북 리스트 활용")
    t.setup(width=swidth + 50, height=sheight + 50)
    t.screensize(swidth, sheight)

    shapeList = t.getshapes()
    for i in range(100):
        rd.shuffle(shapeList)
        myTurtle = t.Turtle(shapeList[0])
        tX = rd.randrange(-swidth / 2, swidth / 2)
        tY = rd.randrange(-sheight / 2, sheight / 2)
        r = rd.random()
        g = rd.random()
        b = rd.random()
        tSize = rd.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]))
Exemplo n.º 5
0
import turtle
turtle.register_shape('pentagon',
                      ((50, 0), (50, -50), (25, -100), (0, -50), (0, 0)))
turtle.shape('pentagon')
turtle.left(90)
turtle.getshapes()
turtle.mainloop()
#거북이 정보 [[거북이1,X,Y,크기,R,G,B],[거북이2,X,Y,크기,,R,G,B...]]
import turtle
import random
myturtle, tx, ty, tcolor, tsize, tshape = [None] * 6
shapelist = []
playerturtles = []
swidth, sheight = 500, 500

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(random.choice(shapelist))
    myturtle = turtle.Turtle(shapelist[0])
    tx = random.randrange(-swidth / 2, swidth / 2)
    ty = random.randrange(-sheight, sheight)

    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])
Exemplo n.º 7
0
# Нарисовать границу:
tt.hideturtle()
tt.color("blue")
#tt.pensize(1)
tt.penup()
tt.goto(-size_x, size_y)
tt.pendown()
tt.goto(size_x, size_y)
tt.goto(size_x, -size_y)
tt.goto(-size_x, -size_y)
tt.goto(-size_x, size_y)

# Создать стрелка
#screen.register_shape("player", "chui.gif") # "images\chui.gif"
# "images\chui.gif"
shapes = tt.getshapes()
player = tt.Turtle()
#player.shape("player") 
tt.register_shape(path_file + "images\\chui.gif") 
player.shape(path_file + "images\\chui.gif")
player.penup()
player.home()
player.showturtle()

# Создать несколько Зомби
tt.register_shape(path_file + "images\\guard1.gif")
enemies = []
enemy_i = 0
while enemy_i < enemy_count:
    enemy = tt.Turtle()
    enemy.penup()
Exemplo n.º 8
0
import turtle
import random

# 전역 변수 선언 #
myTurtle, tX, tY, tColor, tSize, tShape = [None] * 6
shapeList = []
playerTurtles = []  #거북이 2차원 리스트
swidth, sheight = 500, 500

# 메인 코드 #
if __name__ == "__main__":  #이건 왜 선언을 하는거지? 인터프리터에서 직접 실행한 경우에만 if 문 코드 실행
    turtle.title('거북 리스트 활용')
    turtle.setup(width=swidth + 50, height=sheight + 50)
    turtle.screensize(swidth, sheight)

    shapeList = turtle.getshapes()  # 모든 거북이 이름 목록 반환
    # getshapes() = ['arrow','blank','circle','classic','square','triangle','turtle]
    for i in range(0, 5):  #tutle object 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)  # 나오는 모양의 크기가 1~3이 되게
        playerTurtles.append([myTurtle, tX, tY, tSize, r, g, b])

    for tList in playerTurtles:  # playerTurtles 안에 tList만큼 반복?
        myTurtle = tList[0]
Exemplo n.º 9
0
import turtle


class Jogador:
    def __init__(self, nome, forma):
        self.nome = nome
        self.forma = forma


# Comecamos o programa aqui

formas = turtle.getshapes()
print("Qual e o teu nome")
nome = input()
print("Qual a forma que queres")
print(formas)
forma_escolhida = input()

if forma_escolhida not in formas:
    print("forma nao reconhecida, estas tramado")
    exit(404)

j1 = Jogador(nome, forma_escolhida)
print(j1.forma)
Exemplo n.º 10
0
    mypen.left(90)
    mypen.forward(398)
    mypen.left(90)
mypen.hideturtle()

s = turtle.Shape("compound")
# poly1 = ((0,0),(10,-5),(0,10),(-10,-5))
poly1 = ((-2, -13), (0, -14), (2, -13), (2, 10), (0, 11), (-2, 10))
s.addcomponent(poly1, "black")
poly2 = ((0, 4), (10, -4), (-10, -4))
s.addcomponent(poly2, "black")
poly3 = ((0, -11), (5, -16), (-5, -16))
s.addcomponent(poly3, "black")
wn.register_shape("myshape", s)

print(turtle.getshapes())
#Create player turtle
player = turtle.Turtle()
player.color('black')
player.shape('myshape')
player.penup()
player.speed(0)

#Game Variables
score = 0
speed = 0
timeout = time.time() + 60


#Define Game Functions
def turn_left():