"""海龟的小伙伴们,本程序演示很多不同颜色的小海龟在海里游泳"""
import turtle
from random import randint
width,height = 640,480 # 定义屏幕宽度和高度
colors = 'red','orange','yellow','green','cyan','blue','purple','gray'
screen = turtle.getscreen() # 获取屏幕对象
screen.title("海龟的小伙伴们") # 设定屏幕标题
screen.setup(width,height) # 设定屏幕宽高
screen.bgpic("dahai.png") # 设定背景图片
screen.delay(0) # 设定屏幕延时
turtles = [turtle] # 定义海龟列表
turtle.penup() # 让小海龟抬笔
turtle.shape("turtle") # 设定海龟形状
for c in colors: # 遍历每种颜色
t = turtle.clone() # 克隆一只海龟
t.color(c) # 设定海龟颜色
t.setheading(randint(0,359)) # 设定海龟朝向
turtles.append(t) # 加入海龟列表
amounts = len(turtles) # 统计海龟数量
index = 0 # 定义列表索引
while True: # 进入无限循环
t = turtles[index] # 取一只小海龟
t.fd(0.1) # 海龟前进0.1
if randint(0,100) == 0 : # 设定一定机率
t.right(randint(-90,90)) # 随机转动方向
index += 1 # 索引号加1
index = index % amounts # 对数量求余
-
- 2026 年 3 月
- 2026 年 2 月
- 2026 年 1 月
- 2025 年 12 月
- 2025 年 11 月
- 2025 年 10 月
- 2025 年 9 月
- 2025 年 6 月
- 2025 年 5 月
- 2025 年 3 月
- 2025 年 2 月
- 2025 年 1 月
- 2024 年 12 月
- 2024 年 8 月
- 2024 年 6 月
- 2024 年 5 月
- 2024 年 4 月
- 2024 年 3 月
- 2024 年 2 月
- 2023 年 11 月
- 2023 年 9 月
- 2023 年 6 月
- 2023 年 5 月
- 2023 年 4 月
- 2023 年 3 月
- 2023 年 2 月
- 2023 年 1 月
- 2022 年 12 月
- 2022 年 11 月
- 2022 年 10 月
- 2022 年 9 月
- 2022 年 8 月
- 2022 年 7 月
- 2022 年 6 月
- 2022 年 5 月
- 2022 年 4 月
- 2022 年 3 月
- 2022 年 2 月
- 2022 年 1 月
- 2021 年 12 月
- 2021 年 11 月
- 2021 年 10 月
- 2021 年 9 月
- 2021 年 8 月
- 2021 年 7 月
- 2021 年 6 月
- 2021 年 5 月
- 2021 年 4 月
- 2021 年 3 月
- 2021 年 2 月
- 2021 年 1 月
- 2020 年 12 月
- 2020 年 11 月
- 2020 年 10 月
- 2020 年 9 月
- 2020 年 8 月
- 2020 年 7 月
- 2020 年 6 月
- 2020 年 5 月
- 2020 年 4 月
- 2020 年 3 月
- 2020 年 2 月
- 2020 年 1 月
- 2019 年 12 月
- 2019 年 11 月
- 2019 年 10 月
- 2019 年 9 月
- 2019 年 8 月
- 2019 年 7 月
- 2019 年 6 月
- 2019 年 5 月
- 2019 年 4 月
- 2019 年 3 月
- 2019 年 2 月
- 2018 年 3 月
- 2018 年 1 月
- 2017 年 9 月
- 2017 年 5 月
- 2017 年 1 月

