python好看的流星雨代码,文本文档流星雨代码

大家好,小编来为大家解答以下问题,python制作超炫流星雨表白动态,python好看的流星雨代码,现在让我们一起来看看吧!

绘制一颗流星

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
 
x0,y0 = 1,1     #此为流星位置
ts = np.arange(0,1,0.01)    #参数
xs,ys = x0+ts, y0+ts        #绘图线条
 
points = np.array([xs, ys]).T.reshape(-1, 1, 2)
segments = np.concatenate([points[:-1], points[1:]], axis=1)
 
ax = plt.subplot()
lc = LineCollection(segments, cmap='viridis')
 
lc.set_array(ts)
lc.set_linewidth(ts[::-1])
line = ax.add_collection(lc)
 
ax.set_xlim(0, 3)
ax.set_ylim(0, 3)
plt.show()

 很多流星

from numpy.random import rand, randint
from matplotlib.collections import LineCollection

import numpy as np
import matplotlib.pyplot as plt

N, L = 20, 100  # 流星个数和线段数
ts = np.array([
    np.linspace(0, rand(), L) for _ in range(N)]).T
x0, y0 = rand(2 * N).reshape(2, 1, N)
x0 *= 5
xs, ys = x0 + ts, y0 + ts  # 绘图线条1

points = np.array([xs, ys]).T.reshape(N, L, -1, 2)

ax = plt.subplot()
for i in range(N):
    segs = np.concatenate([points[i][:-1], points[i][1:]], axis=1)
    lc = LineCollection(segs, cmap='viridis')
    lc.set_array(ts[:, i])
    lc.set_linewidth(ts[::-1, i])
    ax.add_collection(lc)

ax.set_xlim(0, 6)
ax.set_ylim(-2, 3)
ax.set_axis_off()  # 取消坐标轴
plt.show()

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值