"""请更改切片规则,让不同的海龟出列"""
from turtle import *
from random import *
def write_index():
"""在海龟下面写上索引号"""
i = 0
# 遍历每只海龟
def make_reg(maxnumber):
"""产生一个切片规则"""
amounts = 10
color_list = ['red','orange','yellow','green','cyan',
'blue','purple','brown','pink','white']
title = "切片教学演示动画 www.lixingqiu.com"
screen = Screen()
screen.delay(10)
screen.title(title)
screen.bgcolor("black")
t = Turtle(shape='turtle')
t.shapesize(2.5,2.5)
t.color(color_list[0]) # 设定颜色
t.penup() # 抬笔
t.bk(270) # 后退
t.sety(-90)
t.setheading(90) # 朝上
t.initcors = t.position() # 记录自己的初始坐标
for i in range(1,amounts): # 迭代变量
w = t.clone() # 克隆一只海龟
c =color_list[i%amounts]
w.color(c) # 设定颜色
w.setx(t.xcor() + i * 60) # 设置x坐标
w.initcors = w.position() # 记录自己的初始坐标
"rose是用来画不变字符串的海龟"
rose = Turtle(visible=False) # 用来写切片规则的海龟对象
rose.color("white") # 颜色为白色
rose.penup() # 抬笔
rose.goto(-180,250)
rose.write(title,font=(None,32,"normal"))
rose.goto(-80,-220)
rose.write("请单击屏幕",font=(None,22,"normal"))
rose.goto(-80,100)
# 写中括号和规则
rose.write("起始:结束:步长",font=(None,20,"normal"))
tom = Turtle(visible=False) # tom用来写变化的切片规则
tom.penup()
tom.color("cyan")
tom.goto(-85,140)
screen.turtles().pop() # 把 tom 弹出
screen.turtles().pop() # 把 rose 弹出
all_turtles = screen.turtles() # 所有的海龟对象
write_index() # 在每只海龟下面写它的索引号
def change(x,y):
"""单击屏幕,根据相应的规则显示相应的动画与文字"""
global all_turtles
screen.onclick(change)
screen.listen()
screen.mainloop()
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

