Make the heart bounce in and out

前端 未结 1 600
广开言路
广开言路 2021-01-29 10:29

I was able to make a heart in matlab as:

n=100;
x=linspace(-3,3,n);
y=linspace(-3,3,n);
z=linspace(-3,3,n);
[X,Y,Z]=ndgrid(x,y,z);
F=((-(X.^2) .* (Z.^3) -(9/80).         


        
相关标签:
1条回答
  • 2021-01-29 11:03

    try this

    step = 0.05;
    x = -1.5 : step : 1.5;
    y =   -1 : step : 1;
    z = -1.5 : step : 1.5;
    
    [X,Y,Z] = meshgrid(x, y, z);
    
    f = (X.^2 + 9/4 .* Y.^2 + Z.^2 - 1).^3 - X.^2 .* Z.^3 - 9/80 .* Y.^2 .* Z.^3;
    
    isosurface(X,Y,Z,f,0)
    
    axis tight
    axis equal
    colormap flag
    axis manual
    
    ax = gca;
    
    k=1.25;
    ax.XLim = ax.XLim*k;
    ax.YLim = ax.YLim*k;
    ax.ZLim = ax.ZLim*k;
    
    tempLims.XLim = ax.XLim;
    tempLims.YLim = ax.YLim;
    tempLims.ZLim = ax.ZLim;
    
    t=0;
    
    heartData = sin((1:250)/100*2*pi)/6.*hamming(250)';
    heartData(251:400) = 0;
    
    while 1
        t=t+1;
        t=mod(t, length(heartData))+1;
    
        k = 1 + heartData(t);
    
        ax.XLim = tempLims.XLim * k;
        ax.YLim = tempLims.YLim * k;
        ax.ZLim = tempLims.XLim * k;
        pause(0.01);
    end
    
    0 讨论(0)
提交回复
热议问题