gameturtle模块旋转模式测试程序

gameturtle模块旋转模式测试程序

李兴球Python海龟gameturtle模块旋转模式测试程序

"""
   gameturtle模块旋转模式测试程序。
   本程序需要gameturtle0.21版支持。
"""
from gameturtle import *

root = Tk()
root.title('gameturtle旋转模式测试程序')
cv = Canvas(width=480,height=360,bg='cyan')
cv.pack()

frames = [Image.open(f"res/{i}.png") for i in range(16)]

cat1 = Sprite(cv,frames,pos=(150,100))   # 默认为360度旋转
cat2 = Sprite(cv,frames,pos=(150,200))
cat2.setrotmode(1)                       # 设置为左右旋转
cat3 = Sprite(cv,frames,pos=(150,300))
cat3.setrotmode(2)                       # 设置为不旋转

ft = ('',18,'normal')
cv.create_text((300,100),text='360度旋转',font=ft)
cv.create_text((300,200),text='左右旋转',font=ft)
cv.create_text((300,300),text='不旋转',font=ft)

while 1:
    cat1.left(1);cat1.nextshape()        # 左转并换造型
    cat2.right(1);cat2.nextshape()       # 右转并换造型
    cat3.left(1);cat3.nextshape()        # 左转并换造型
    cv.update()                          # 更新画布显示
    time.sleep(0.01)                     # 等待0.01秒 

李兴球

李兴球的博客是Python创意编程原创博客