一个程序教你花式示爱 1——波动心形线
生活随笔
收集整理的這篇文章主要介紹了
一个程序教你花式示爱 1——波动心形线
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
希望大家使用這個(gè)程序時(shí)回復(fù)一句:愿南宮大大賜予我幸福(滑稽)。和我一樣的恩愛狗,我會(huì)賜予你們i幸福,單身狗的話我會(huì)賜予你一個(gè)女朋友(當(dāng)然是虛擬的,滑稽)。當(dāng)然咯,函數(shù)生成的圖片我才不會(huì)給你們看呢,這是我和我女票的。
PS:程序如果運(yùn)行出錯(cuò),多半屬于沒有及時(shí)更新matplotlib函數(shù)庫(kù),請(qǐng)使用如下語(yǔ)句在cmd控制臺(tái)安裝:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -U matplotlib
import numpy as np import matplotlib.pyplot as plt from matplotlib.animation import FuncAnimation fig, ax = plt.subplots() ln, = ax.plot([], [], '-',color='r', lw=1) time_template = 'LOVE = %.1fs' time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes) def init():ax.set_xlim(-3,3)ax.set_ylim(-2, 3)return ln, def update(ii):xdata, ydata = [], []for i in range(0,183):xi=(182-i)/100xdata.append(0.01*i-1.82)yi=(xi**(2/3))+(0.9*(3.3-xi**2)**0.5)*np.cos(ii*(np.pi)*xi)if type(yi)=='complex':yi=np.around(abs(yi),decimals=4)yi=np.around(yi, decimals=3)ydata.append(yi)for i in range(0,182):xi=i/100xdata.append(xi) yi=(xi**(2/3))+(0.9*(3.3-xi**2)**0.5)*np.cos(ii*(np.pi)*xi)if type(yi)=='complex':yi=np.around(abs(yi),decimals=4)yi=np.around(yi, decimals=3)ydata.append(yi)ln.set_data(xdata, ydata)time_text.set_text(time_template %(ii))return ln, ani = FuncAnimation(fig, update, np.linspace(0, 13.14, 100),init_func=init, interval=100) ani.save('love.gif', writer='imagemagick', fps=10) plt.show()?
總結(jié)
以上是生活随笔為你收集整理的一个程序教你花式示爱 1——波动心形线的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 唠一唠Linux系统入门的方法和经验
- 下一篇: 2017百度之星初赛:A-1002. 数