#---第1步---导入模块---

from turtle import *

from random importrandom,randint#---第2步---初始化定义---#---定义屏幕,窗口大小,标题,背景颜色

screen =Screen()#---大一点效果好一点---

width ,height = 1600,1200screen.setup(width,height)

screen.title('浪漫星空')

screen.bgcolor("black")#设置或返回以毫秒为单位的绘制延迟,延迟越大,绘图越慢

screen.delay(0)#---第3步---定义3种不同颜色的星球,大小、速度、位置、形状不同---#shape():设置乌龟的图形形状,取值:“arrow”, “turtle”, “circle”, “square”, “triangle”, “classic”#---星球---白色星星---

t = Turtle(visible = False,shape='circle')

t.pencolor("white")#海龟的颜色,也就是飞动的星球的颜色

t.fillcolor("blue")

t.penup()#旋转角度

t.setheading(-10)#坐标是随机的

t.goto(width/2,randint(-height/2,height/2))#---星球2---绿色远处小星星---

t2 = Turtle(visible = False,shape='turtle')#海龟的颜色,也就是飞动的星球的颜色

t2.fillcolor("green")

t2.penup()

t2.setheading(-50)#坐标是随机的

t2.goto(width,randint(-height,height))#---星球3---近的红色恒星---

t3 = Turtle(visible = False,shape='circle')#海龟的颜色,也就是飞动的星球的颜色

t3.fillcolor("red")

t3.penup()

t3.setheading(-90)#坐标是随机的

t3.goto(width*2,randint(-height*2,height*2))#---第4步---定义星球列表---用于存放---

stars =[]

stars2=[]

stars3=[]#---第5步---定义3种星球的大小、速度、位置并存放各自列表中---#---注意200为画200个各自星球就退出,注意太多了要卡死的---

for i in range(200):

star=t.clone()#决定星球的大小

s= random()/3star.shapesize(s,s)

star.speed(int(s*10))#随机产生坐标

star.setx(width/2 + randint(1,width))

star.sety(randint(-height/2,height/2))

star.showturtle()

stars.append(star)for i in range(200):

star2=t2.clone()#决定星球的大小

s2= random()/2star2.shapesize(s2,s2)

star2.speed(int(s*10))

star2.setx(width/2 + randint(1,width))

star2.sety(randint(-height/2,height/2))

star2.showturtle()

stars2.append(star2)for i in range(200):

star3=t3.clone()#决定星球的大小

s3= random()*5star3.shapesize(10*s3,10*s3)

star3.speed(int(s3*10))

star3.setx(width*2 + randint(1,width))

star3.sety(randint(-height*2,height*2))

star3.showturtle()

stars3.append(star3)#---第6步---游戏循环---各自星球的启动

whileTrue:for star instars:

star.setx(star.xcor()- 3 *star.speed())if star.xcor()

star.hideturtle()

star.setx(width/2 + randint(1,width))

star.sety( randint(-height/2,height/2))

star.showturtle()for star2 instars2:

star2.setx(star2.xcor()- 3 *star2.speed())if star2.xcor()

star2.hideturtle()

star2.setx(width/2 + randint(1,width))

star2.sety( randint(-height/2,height*2))

star2.showturtle()for star3 instars3:

star3.setx(star3.xcor()- 3 *star3.speed())if star3.xcor()

star3.hideturtle()

star3.setx(width*2 + randint(1,width))

star3.sety( randint(-height*2,height*2))

star3.showturtle()

python画动态星空_python3的turtle画模仿3d星空、运动的恒星小宇宙相关推荐

  1. 用python的turtle画模仿3d星空、运动的恒星小宇宙

    1.导入模块 from turtle import * from random import random,randint 2.步初始化定义 定义屏幕,窗口大小,标题,背景颜色 screen = Sc ...

  2. 用python画星空-python3的turtle画模仿3d星空,运动的恒星小宇宙

    2.代码实现条件 python3 3.第1步: #---第1步---导入模块--- from turtle import * from random import random,randint 4.第 ...

  3. 用python画星空-python3的turtle画模仿3d星空、运动的恒星小宇宙

    #---第1步---导入模块--- from turtle import * from random importrandom,randint#---第2步---初始化定义---#---定义屏幕,窗口 ...

  4. turtle fillcolor_python3的turtle画模仿3d星空、运动的恒星小宇宙

    1.宇宙 2.代码实现条件 python3 3.第1步: #---第1步---导入模块---from turtle import *from random import random,randint ...

  5. python3的turtle画模仿3d星空,运动的恒星小宇宙

    本文参考原文-http://bjbsair.com/2020-03-25/tech-info/6248.html 1.宇宙 2.代码实现条件 python3 3.第1步: #---第1步---导入模块 ...

  6. python绘制蚊香形_python之turtle画蚊香

    原理:利用turtle绘制圆形,并使圆半径逐步增加 代码如下: import turtle turtle.pensize(30) for i in range(30): turtle.circle(i ...

  7. python绘制爱心气球_python中用turtle画爱心表白-Go语言中文社区

    python中用turtle画爱心表白 运行后的效果图: 下面的代码是在python3.7写的,代码有点长,但却语法简单易懂 代码如下: import turtle str = input('请输入表 ...

  8. python turtle画房子详细解释_Python turtle画图库画姓名实例

    *****看一下我定义的change()和run()函数****** 绘图坐标体系: 作用:设置主窗体的大小和位置 turtle.setup(width, height, startx, starty ...

  9. 用python画一个人_用turtle画个单身狗送给自己~

    python视频教程栏目介绍如何使用turtle画图. 今年的双十一到了 但还有谁记得双十一是 单身狗的节日 单身狗的我是时候站出来 捍卫自己的权益了 单身是一种怎样的状态? 我们所有人都单身过,但也 ...

最新文章

  1. android地图定位
  2. postfix+mysql+dovecot
  3. 5kyu Square sums (simple)
  4. python标准日期正则表达式_Python 正则表达式验证传统日期
  5. 成功将本地文件添加到github仓库
  6. asp.net三层架构制作新闻管理_为什么使用PHP制作网站?
  7. 2台电脑一根网线传文件_黑龙江工程专用网线报价,黑电源线配件厂家
  8. 有好事?卡巴斯基推出免费杀毒软件
  9. sigar获取单个进程信息
  10. 关于专业技术资格、专业技术职务、职称三者的关系
  11. 李飞飞:我怎样走上 AI 研究之路的?
  12. mysql 创建表 create table详解
  13. Python网络数据采集9(译者:哈雷)
  14. Web前端从入门到精通(第五周)
  15. 51单片机实现跟随小车
  16. 面对 ESM 的开发模式,webpack 还有还手之力吗?(转载)
  17. 什么样的离职原因适合你
  18. 加油站以后还能叫加油站吗?
  19. 系统分析师之数据库系统(七)
  20. 最近的一份面试题(小结一下)

热门文章

  1. 关于STM32中定义数组的问题
  2. rm 删除文件或目录
  3. 项目管理知识体系术语(四) (转)
  4. 暴雪的hash算法[翻译]
  5. 正确解决驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接
  6. ‘gbk‘ codec can‘t decode byte 0xaa解决办法
  7. SpringMvc -07整合 SSM整合 【重点】
  8. 广告行业中那些趣事系列32:美团搜索NER技术实践学习笔记
  9. 便民,合格证自助打印一体机投用,只花一分钟即可实现领取实体证
  10. 解决IDEA IntelliJ注册码冲突的问题