from turtle import *
import random
# 创建画布颜色
setup(800, 800)
bgcolor("white")
# 画笔的速度
speed(50)
# 画笔颜色mode
colormode(255)
#画气球
for i in range(25):
# 随机起点
x = random.randint(-400, 400)
y = random.randint(-400, 400)
#三原色随机取值
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
#取气球的颜色
color(r, g, b)
#画圆
begin_fill()
circle(50)
end_fill()
#画气球线
right(90)
forward(150)
left(90)
#随机起点
penup()
goto(x, y)
pendown()
#隐藏海龟
hideturtle()
#按退出结束窗口
exitonclick()
python海龟画图多彩气球
于 2023-10-19 10:26:24 首次发布