python画星空

import turtle#画画需要引入turtle库
import random#使用随机数需要引入random

turtle.colormode(255)#绘画需要颜色,括号中填写255
t = turtle.Turtle()#创建一支笔,不要漏下括号
turtle.bgcolor(101,124,233)#使用rag三色模式调整颜色

t.speed(0)#画笔的速度
li = [“white”,“yellow”,“gold”]#列表里的颜色为接下来画星星时笔的颜色和填充颜色
for j in range(1000):#大循环开始,不要漏下冒号
#Python中根据缩进判断循环开始与结束
temp1 = random.choice(li)#从列表中随机的选择颜色
#之所以设置一新变量选择颜色,是因为如果画星星笔的颜色和填充颜色分开随机选择,二者颜色有可能不同
t.fillcolor(temp1)
t.color(temp1)#此处画星星笔的颜色和填充颜色均是上面所取的随机颜色,确保了颜色相同
t.begin_fill()#开始填充颜色
temp2 = random.randint(5,15)#前闭后闭,设置星星的大小
li2 = [5,7,9]#列表中的数字为接下来星星的边数
temp3 = random.choice(li2)#从列表中随机的选择一个数
#之所以设置一新变量选择星星的边长,是因为如果画星星时分开随机选择,可能导致星星边长不同
for i in range(temp3):#小循环1开始画星星
t.forward(temp2)
t.left(180-180/temp3)#注意此处的表示
t.end_fill()#结束填充颜色
t.penup()#抬笔
for i in range(2):#小循环2开始,寻找新的位置画星星
t.left(random.randint(10,90))
t.forward(random.randint(10,200))
t.pendown()#落笔

turtle.done()#绘画结束

python开发的真实星空显示软件 含真实恒星位置数据3144颗 代码讲解见: https://blog.csdn.net/xiaorang/article/details/106598307 数据格式例: {'long': 0.023278328898474372, 'lat': -0.09961466705757636, 'light': 46, 'const': 66}, {'long': 0.024870941840919196, 'lat': 0.2338062439126301, 'light': 55, 'const': 62}, {'long': 0.028107061526797, 'lat': 1.1204335039257496, 'light': 56, 'const': 18}, {'long': 0.03660100303760025, 'lat': 0.5077259659824991, 'light': 21, 'const': 1}, {'long': 0.04004802831028905, 'lat': 1.0323574005393255, 'light': 23, 'const': 18}, {'long': 0.03944444109507185, 'lat': 0.3178583859888262, 'light': 55, 'const': 62}, {'long': 0.040797071265367454, 'lat': -0.488478858963941, 'light': 54, 'const': 74}, {'long': 0.0410661312228549, 'lat': -0.798444499556106, 'light': 39, 'const': 64}, {'long': 0.043800486202076855, 'lat': 0.1945266317121166, 'light': 55, 'const': 66}, {'long': 0.045036755271142, 'lat': 0.804111967609767, 'light': 50, 'const': 1}, {'long': 0.043785947609407745, 'lat': -1.4350775693910554, 'light': 53, 'const': 58}, {'long': 0.04915283505929031, 'lat': -0.2699684886295715, 'light': 49, 'const': 21}, {'long': 0.050498187206605094, 'lat': -0.4851966800391031, 'light': 54, 'const': 74}, {'long': 0.05119631890740283, 'lat': -0.6131874860342564, 'light': 52, 'const': 74}, {'long': 0.05775584219505068, 'lat': 0.26500400429202875, 'light': 28, 'const': 62}, {'long': 0.05896303407877759, 'lat': 0.7162006931179011, 'light': 57, 'const': 1}, {'long': 0.06371905629046214, 'lat': 0.3526728525507925, 'light': 48, 'const': 62}, {'long': 0.06387905062299246, 'lat': -0.33043929519585447, 'light': 44, 'const': 21}, 代码解说详细的教程见: https://blog.csdn.net/xiaorang/article/details/106598307
Python可以通过结合matplotlib库和其他艺术相关的模块来绘制星空效果,模拟梵高的风格通常需要一些艺术化处理和颜色处理技巧。下面是一个简单的例子,展示如何用Python和matplotlib创建一个抽象的、梵高风格的星空面: ```python import matplotlib.pyplot as plt from random import randint import numpy as np def梵高星空(width=500, height=500): # 创建布 fig, ax = plt.subplots(figsize=(width, height)) # 设置背景色 ax.set_facecolor((np.random.uniform(0.4, 0.6), np.random.uniform(0.4, 0.6), np.random.uniform(0.4, 0.6))) # 添加点状星体 stars = [(randint(0, width), randint(0, height)) for _ in range(randint(100, 200))] for x, y in stars: star_size = randint(1, 10) plt.scatter(x, y, s=star_size, c=(randint(80, 255), randint(80, 255), randint(80, 255)), edgecolors='black') # 模拟梵高笔触 for i in range(10): brush_stroke_width = np.random.randint(1, 5) brush_stroke_length = np.random.randint(brush_stroke_width, width // 2) start_x = np.random.randint(0, width - brush_stroke_length) start_y = np.random.randint(0, height - brush_stroke_length) for j in range(start_y, start_y + brush_stroke_length): for k in range(start_x, start_x + brush_stroke_width): if (k, j) not in stars: plt.plot([k, k], [j, j + brush_stroke_width], color=(np.random.randint(80, 255), np.random.randint(80, 255), np.random.randint(80, 255))) # 显示图像 plt.title("星空梵高风格") plt.axis('off') plt.show() # 调用函数生成星空图 梵高星空() ``` 请注意这只是一个基本的示例,实际的梵高风格会更复杂,可能涉及颜色渐变、厚涂等技术。如果你想要更加接近梵高的作品,可能需要借助其他专门的艺术库,如Pillow或skimage。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值