通过十个参数绘制大象曲线
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.animation as animation
num=101
k=np.arange(1,6)
t=np.linspace(0,2*np.pi,num)
Ax=[0,0,12,0,-14]
Bx=[50,18,0,0,0]
Ay=[-60,0,0,0,0]
By=[-30,8,-10,0,0]
eye=20
x=(np.matmul(np.array(Ax).reshape(1,5),np.cos(k.reshape(5,1)*t.reshape(1,101)))+np.matmul(np.array(Bx).reshape(1,5),np.sin(k.reshape(5,1)*t.reshape(1,101)))).reshape((101,))
y=(np.matmul(np.array(Ay).reshape(1,5),np.cos(k.reshape(5,1)*t.reshape(1,101)))+np.matmul(np.array(By).reshape(1,5),np.sin(k.reshape(5,1)*t.reshape(1,101)))).reshape((101,))
plt.plot(y,-x,eye,eye,'o')
plt.show()
让大象的鼻子动起来
num=101
k=np.arange(1,6)
t=np.linspace(0,2*np.pi,num)
Ax=[-60,0,0,0,0]
Bx=[-30,8,-10,0,0]
Ay=[0,0,-12,0,14]
By=[-50,-18,0,0,0]
eye=20
wigg=40
x=(np.matmul(np.array(Ax).reshape(1,5),np.cos(k.reshape(5,1)*t.reshape(1,101)))+np.matmul(np.array(Bx).reshape(1,5),np.sin(k.reshape(5,1)*t.reshape(1,101)))).reshape((101,))
y=(np.matmul(np.array(Ay).reshape(1,5),np.cos(k.reshape(5,1)*t.reshape(1,101)))+np.matmul(np.array(By).reshape(1,5),np.sin(k.reshape(5,1)*t.reshape(1,101)))).reshape((101,))
A=20
nose=np.where(x>wigg)
nose_m=np.where(x>=np.max(x))
class Scope:
def __init__(self,ax):
self.ax=ax
self.move_num=100
self.i=0
def paint(self,j):
if self.i==self.move_num:
self.i=0
y0=np.zeros((101,))
y0[nose]=A*np.sin(2*np.pi*self.i/self.move_num)*np.exp(-np.power((nose[0]-nose_m[0]),2)/40)
self.ax.cla()
self.ax.plot(x,y+y0,eye,eye,'o')
self.i+=1
fig,ax=plt.subplots()
scope=Scope(ax)
ani=animation.FuncAnimation(fig,scope.paint,interval=100)
plt.show()
参考链接:
使用matplotlib的动画模块快速更新曲线
在Python MatPlotLib中使用动画时,如何更改绘制曲线的颜色?
如何用四个参数画一头大象?
创建于2407101112,修改于2407101112
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
2020-07-10 用React写井字棋游戏
2020-07-10 最简单的QT程序