"""
卡通坐标练习程序,这是一个用Python开发的学习与练习坐标的小程序, 以下为预览程序.
"""
import time
import random
from turtle import *
def slow_write(t,string):
"""慢慢写字的函数"""
for char in string:
t.write(char,align='center',font=('黑体',14))
t.setx(t.xcor() + 20)
time.sleep(0.2)
screen = Screen()
screen.title('坐标练习')
screen.bgcolor("black")
cors = [] # 坐标表
stamps = [] # 图章表
names = ['飞机','苹果','女孩','香蕉','蝙蝠',
'蜜蜂','铃铛','单车','小猫','小老虎',
'螃蟹','小狗','小象','小鱼','小猴',
'老鼠','章鱼','小鸟','企鹅','兔子',
'机器人','鲨鱼','汽球','海星','斑马']
images = [f'images/{i}.gif' for i in range(25)]
[screen.addshape(im) for im in images]
distance = 80
init_x = -100
init_y = -100
t = Turtle(visible=False)
t.penup()
t.color("cyan")
t.write("卡通坐标练习程序",font=("",32),align='center')
time.sleep(5)
screen.bgcolor('white')
t.color('blue')
t.clear()
for index in range(25):
x = index // 5
y = index % 5
cors.append((x+1,y+1))
x = init_x + distance * x
y = init_y + distance * y
t.goto(x,y)
image = images[index]
t.shape(image)
stamps.append(t.stamp())
for index in range(5):
t.goto(init_x + index * distance,init_y-distance)
t.write(f"第{index+1}列",align='center',font=('黑体',14))
for index in range(5):
t.goto(init_x - distance,init_y + distance * index)
t.write(f"第{index+1}排",align='center',font=('黑体',14))
strings = ['坐标是用来表示位置的两个数。',
'上面的飞机,它在第一列,第一排,它的坐标表示为(1,1)',
'小狗是在第3列第2排,所以它的坐标记为(3,2)',
'而斑马在第5列第5排,所以它的坐标记为(5,5)',
'懂了吗?要开始测验了!',
'接下来,请在对话框中输入以逗号隔开的坐标',]
w = Turtle(visible=False)
w.penup()
for s in strings:
w.goto(init_x-150,init_y-150)
slow_write(w,s)
time.sleep(3)
w.clear()
w.goto(0,-270)
# iii列表是打乱顺序的索引表
iii = [i for i in range(25)]
random.shuffle(iii)
pass
# 本程序不完整,读者可扫码获取素材与完整源码的下载链接.
screen.mainloop()
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

