
关于星空,有很多唯美的句子。
一、先来看看Python星空图代码绘制成品


"在整个宇宙里,你是独属于我的那颗星"
二、分解Python模拟3D星空图代码讲解

1 下载并加载库
"""代码用途:模拟3D星空作者:阿黎逸阳"""from turtle import *from random import random,randint
2 设置屏幕和背景颜色
设置屏幕的像素,并把背景颜色设置为黑色。
s = Screen()width ,height = 800,600s.setup(width,height) #输入宽和高为整数时, 表示像素; 为小数时, 表示占据电脑屏幕的比例s.title("模拟3D星空-阿黎逸阳") #设置标题s.bgcolor("black") #设置背景颜色为黑色s.mode("logo") #设置乌龟模式(“standard”,“logo”或“world”)并执行重置,logo表示向上s.delay(0) #设置或返回以毫秒为单位的绘图延迟,这里要设为0,否则很卡
3 在屏幕的右下角写下文字
printer = Turtle()printer.hideturtle()printer.penup()printer.color('white')printer.goto(-100,-150)printer.write("In the whole universe\n\n",move = True, align="left", font=("Italic", 30, "bold"))printer.goto(-300,-200)printer.write("you're the only star belongs me!\n\n",move = True, align="left", font=("Italic", 30, "bold"))
4 设置绘圆圈的基本语句
t = Turtle(visible = False,shape='circle')t.pencolor("white") #设置画笔的颜色t.fillcolor("white") #设置图形填充颜色t.penup() #抬起画笔t.setheading(-90) #设置当前朝向角度t.goto(width/2,randint(-height/2,height/2)) #把画笔移动到定点
如对代码有疑问,可以到公众号中私信我。
参考文献:
https://www.diyijuzi.com/weimei/4515.html
-end-
你可能感兴趣:
喜欢3D星空图
就请点个 “ 在看”吧
原文作者:阿黎逸阳的代码;如有侵权,请联系管理员删除。