用python画星空-python3的turtle画模仿3d星空、运动的恒星小宇宙
#---第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()<-width/2:
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()<-width/2:
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()<-width*2:
star3.hideturtle()
star3.setx(width*2 + randint(1,width))
star3.sety( randint(-height*2,height*2))
star3.showturtle()
用python画星空-python3的turtle画模仿3d星空、运动的恒星小宇宙相关推荐
- 用python画星空-python3的turtle画模仿3d星空,运动的恒星小宇宙
2.代码实现条件 python3 3.第1步: #---第1步---导入模块--- from turtle import * from random import random,randint 4.第 ...
- python3的turtle画模仿3d星空,运动的恒星小宇宙
本文参考原文-http://bjbsair.com/2020-03-25/tech-info/6248.html 1.宇宙 2.代码实现条件 python3 3.第1步: #---第1步---导入模块 ...
- 用python的turtle画模仿3d星空、运动的恒星小宇宙
1.导入模块 from turtle import * from random import random,randint 2.步初始化定义 定义屏幕,窗口大小,标题,背景颜色 screen = Sc ...
- python画动态星空_python3的turtle画模仿3d星空、运动的恒星小宇宙
#---第1步---导入模块--- from turtle import * from random importrandom,randint#---第2步---初始化定义---#---定义屏幕,窗口 ...
- turtle fillcolor_python3的turtle画模仿3d星空、运动的恒星小宇宙
1.宇宙 2.代码实现条件 python3 3.第1步: #---第1步---导入模块---from turtle import *from random import random,randint ...
- python画椭圆turtle_python之turtle画蚊香,python用turtle画圆弧,原理:利用turtl
python之turtle画蚊香,python用turtle画圆弧,原理:利用turtl 原理:利用turtle绘制圆形,并使圆半径逐步增加 代码如下:import turtleturtle.pens ...
- python画同心圆程序_python turtle画4个同心圆方法!
在python中如何使用循环结构画四个相切的圆 from turtle import * r=20 x,y=0,0 for i in range(4): if i==2: penup() goto(x ...
- python画国际象棋_python用turtle画国际象棋棋盘
用turtle画的国际象棋棋盘 import turtle turtle.speed(10) a = 30 #画背景 turtle.up() turtle.goto( -10, -10) turtle ...
- python画螺线_《Think Python》练习4-5:用turtle画螺线
要求:阅读螺线(spiral)的相关知识: 然后编写一个绘制阿基米德螺线(或者其他种类的螺线)的程序. 阿基米德螺线 import turtle from math import sin, cos, ...
最新文章
- BGP相邻体之间磋商的过程
- 特斯拉全新自动驾驶芯片最强?英伟达回怼,投资者用脚投票
- 为什么你问问题,别人都已读不回?
- Nginx反向代理Tomcat的配置方法
- android studio编译提示错误:android Error:(21, 19) 错误: 程序包R不存在
- 几个主流的Java连接池整理
- mysql5 varchar_MYSQL 5.7 VARCHAR 类型实验
- 联想电脑锁屏界面设置被组织隐藏_Word Clock数字时钟动态屏保,让你的电脑锁屏瞬间科技感十足!...
- 区块链教程Fabric1.0源代码分析MSP成员关系服务提供者一
- ActiveReports 9 新功能:创新的报表分层设计理念
- eclipse下彻底删除SVN插件
- 查词根词缀特别好的网站
- Git教程及常用命令
- 玩转教育计算机二级,全国计算机等级考试二级msoffice高级应用教材《玩转office轻松过二级》配套模拟软件使用说明.doc...
- 信息安全之访问控制策略
- flex布局中 flex:1和flex:auto的区别
- php md5 32 大写,编写生成32位大写和小写字符的md5的函数
- 生物信息学入门 GEO芯片数据差异表达分析时需要log2处理的原因
- linux setsockopt
- 人脸图像质量评价 SER
热门文章
- webrtc 入门第五章 一对一视频通话实现
- 帝国cms php循环,帝国CMS listshowclass循环栏目标签_PHP教程
- 淘宝网店要怎么去推广
- w ndows控制面板怎样打开,Windows10系统下怎样使用快捷键打开控制面板
- 前端求职路-路漫漫其修远兮,吾将上下而求索
- 文字转图片@图片加水印(JS版)
- 【小白入门板绘设计】教你学习原画新手如何设计出的好看的设计感画面!
- CAD操作——毕设救命稻草
- android点击按钮弹出图片,用android做的一个简单的点击按钮显示图片的程序
- 贴图、 纹理、材质的区别