猫史档案馆


【Python作品分享】随机气球【作品秀】

用户:吴勇诚吴勇诚查看:0 回复:0 评论:0 创建时间:2023-03-29T18:23:34


【作品展示】

center_image

 

【作品介绍】

这些气球随机出现,大小、颜色随机

 

【作品源代码】

import turtle
import random
t = turtle.Pen()
# 初始化
t.penup()
t.speed(10000)
background = ['gray', 'deepskyblue','darkblue','blue','skyblue','midnightblue']
colors = ['red', 'orange', 'yellow', 'lime', 'gold', 'silver', 'gray', 'cyan', 'violet', 'blue', 'slateblue', 'blueviolet','magenta', 'deeppink', 'deepskyblue', 'dodgerblue', 'springgreen', 'lawngreen', 'white', 'green', 'indigo', 'purple']
while True:
    turtle.bgcolor(background[random.randint(0, (len(background) - 1))])
    t.setheading(0)
    size = random.randint(5,30)
    t.goto(random.randint(-600, 600), random.randint(0, 270))
    color = colors[random.randint(0, (len(colors) - 1))]
    t.pencolor('black')
    t.fillcolor(color)
    t.begin_fill()
    t.pendown()
    t.circle(size)
    t.penup()
    t.end_fill()
    t.right(90)
    t.pendown()
    t.forward(size)
    t.penup()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页