AI编程正在让小白瞬间成为高手(ai软件编程)

AI编程正在让小白瞬间成为高手(ai软件编程)

技术教程gslnedu2025-08-03 3:47:543A+A-

AI编程太让人亮眼了。

看到一个好玩的MATLAB程序,可以生成游动的水母,


公式如下:

给出的MATLAB程序如下:


  1. x=0:1:14*2*pi; y=0:1:30*2*pi;
  2. [x y]=meshgrid(x, y); x=x(:); y=y(:);

  3. k=5*cos(x/14).*cos(y/30);
  4. e=y/8-13;
  5. a=atan2(k,e);
  6. d=(k.^2+e.^2)/59+4;

  7. for t=0:1:120
  8. c=d/2+e/99-t/18;
  9. q=60-sin(a.*e)+k.*(3+4./d.*sin(d.^2-2*t));
  10. X=q.*sin(c); Y=(q+9*d).*cos(c);

  11. h=plot(X, Y, '.'); set(h, 'markersize', 1); set(gcf,'color','w');
  12. xlim([-150 150]); ylim([-150 150]); axis off;

  13. % if(t==0) pars={'LoopCount', inf}; else pars={'WriteMode', 'append'};end
  14. % frame=getframe(1); im=frame2im(frame); [img, map]=rgb2ind(im, 256);
  15. % imwrite(img, map, 'jellyfish.gif', 'gif', pars{:}, 'DelayTime', 0.1);

  16. pause(0.1);
  17. end

程序用豆包AI编程可以转成python:

import numpy as np
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

# 生成x和y数据
x = np.arange(0, 14 * 2 * np.pi + 1, 1)  # 0到14*2π,步长为1
y = np.arange(0, 30 * 2 * np.pi + 1, 1)  # 0到30*2π,步长为1

# 创建网格并展平为一维数组
x_grid, y_grid = np.meshgrid(x, y)
x_flat = x_grid.flatten()
y_flat = y_grid.flatten()

# 计算初始参数
k = 5 * np.cos(x_flat / 14) * np.cos(y_flat / 30)
e = y_flat / 8 - 13
a = np.arctan2(k, e)
d = (k ** 2 + e ** 2) / 59 + 4

# 设置图形
fig, ax = plt.subplots(figsize=(8, 8))
fig.patch.set_facecolor('white')  # 设置背景为白色
scat = ax.scatter([], [], s=1, marker='.')  # 初始散点图
ax.set_xlim(-150, 150)
ax.set_ylim(-150, 150)
ax.axis('off')  # 关闭坐标轴


# 动画更新函数
def update(t):
    c = d / 2 + e / 99 - t / 18
    # 处理d为0的情况,避免除零错误
    with np.errstate(divide='ignore', invalid='ignore'):
        q = 60 - np.sin(a * e) + k * (3 + 4 / d * np.sin(d ** 2 - 2 * t))
    X = q * np.sin(c)
    Y = (q + 9 * d) * np.cos(c)

    # 更新散点图数据
    scat.set_offsets(np.column_stack((X, Y)))
    return scat,


# 创建动画
ani = FuncAnimation(fig, update, frames=np.arange(0, 121),
                    interval=100, blit=True)

plt.show()

# 如果需要保存为GIF,请取消下面的注释
#ani.save(r'e:\jellyfish.gif', writer='pillow', fps=10)

如果人工比照 MATLAB程序写python,高手也要半个小时以上,慢一点要一天,AI几乎瞬间完成。

点击这里复制本文地址 以上内容由朽木教程网整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

朽木教程网 © All Rights Reserved.  蜀ICP备2024111239号-8