山东智趣岛论坛

 找回密码
 立即注册
搜索
热搜: C++ 编程 信奥

小喇叭+ 发布

01-24 12:40
查看: 1124|回复: 0

python满天彩色星

[复制链接]
会员网龄
30.2岁
:14 天
:2 天
1001

97

主题

19

回帖

8万

积分

管理员

BOSS

Rank: 9Rank: 9Rank: 9

积分
88341

最佳新人活跃会员热心会员推广达人宣传达人灌水之王突出贡献优秀版主荣誉管理论坛元老

[

发表于 2025-7-15 17:22:15 | 显示全部楼层 |阅读模式
[Python] 纯文本查看 复制代码
import turtle as pen                #turtle海龟库
import random  #导入 随机库

pen.speed(0)  #设置速度

for i in range(100):    #循环100遍

    c=["red","yellow","blue","purple","green","orange"]   #把所有颜色集中放到c里,注意引号把颜色引起来,颜色之间逗号隔开
    d=random.randint(0,5)  #获取0-5直接随机数给了d
    e=random.randint(0,5)
    
    
    pen.color(c[d])  #从c里选择第d个颜色
    
    pen.fillcolor(c[e])#设置填充颜色

    
    pen.begin_fill() #开始填充
    pen.forward(50) #前进200像素
    pen.right(144)  #向右转144度

    pen.forward(50) #前进200像素
    pen.right(144)  #向右转144度
    
    pen.forward(50) #前进200像素
    pen.right(144)  #向右转144度

    pen.forward(50) #前进200像素
    pen.right(144)  #向右转144度

    pen.forward(50) #前进200像素
    pen.right(144)  #向右转144度
    
    pen.end_fill()  #结束填充


    a=random.randint(-900,900)
    b=random.randint(-600,600) 

    pen.penup()  #抬笔
  
    pen.goto(a,b) #移动到(100,200)
    pen.pendown()  #落笔




382363955
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|山东智趣岛论坛 ( 鲁ICP备2025164045号 )

GMT+8, 2026-1-29 06:13 , Processed in 3.069688 second(s), 55 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表