Python精灵模块的rotate_points指令

所有命令 单独命令 屏幕命令 角色命令

单独命令 >> Python精灵模块的rotate_points指令

简介:让一系列坐标点绕着一个中心点旋转,默认为每次旋转1度。可用degree参数修改旋转的度数。
例子:
import time
from sprites import Screen,Sprite,rotate_points,centroid

screen = Screen()
screen.xy_grid()
screen.tracer(0,0) # 关闭显示刷新 

g = Sprite('blank') # 新建空白,即无造型的角色(海龟增强版角色,继承自海龟,默认抬笔)
A = (100,100);B = (200,100);C =(150,200)    # 三个坐标
t = [A,B,C]                                 # 放到t列表中
mid = centroid(A,B,C)  # (A[0]+B[0]+C[0])/3,(A[1]+B[1]+C[1])/3 # 重心

while True:
    g.clear()
    g.goto(t[0]);g.pendown()
    g.goto(t[1]);g.goto(t[2])
    g.goto(t[0]);g.penup()
    # 绕着中心点,旋转t列表中所有的点,返回一个列表,
    # center参数指定旋转中心,默认为原点
    t=rotate_points(t,center=mid) # 把mid 改成t[0],t[1],t[2]尝试   
    screen.update()
    time.sleep(0.01)

writed by lixingqiu 关注"异编程"微信公众号,获取更多关于Python精灵模块的咨讯: