Python的turtle复合造型测试程序

Python的turtle复合造型测试程序

李兴球python_turtle_compound_shape
李兴球python_turtle_compound_shape

李兴球python_turtle_compound_shape

"""
   turtle复合造型测试程序
   本程序来自Python海龟宝典。
   关键词 python turtle compound shape
"""

from turtle import Shape,Screen,Turtle

s = Shape("compound")                          # 新建复合造型

poly = ((10,-5),(0,10),(-10,-5))
s.addcomponent(poly, "red", "blue")            # 坐标,填充颜色,和边框颜色

poly2 = ((10,-25), (10,-5), (-10,-5),(-10,-25))
s.addcomponent(poly2,'yellow','cyan')          # 添加部件

screen = Screen()                              # 新建屏幕
screen.addshape('fh',s)                        # 添加造型 

t = Turtle(shape='fh')                         # 新建海龟
t.shapesize(10)                                # 海龟变大
t.left(90)                                     # 左转90度
name = t.turtle.shapeIndex                     # 造型名字
shape = screen._shapes[name]                   # 取出造型
data = shape._data                             # 造型数据
print(data)                                    # 打印数据

李兴球

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