clc;指令可以清除屏幕,所以你可以通过clc指令来清理屏幕
clc
hold on;指令可以将画的图连起来
hold on
clear;清除之前所留的定义
clear
ezpolar('1-sin(t)')
a=1;
theta = 0 : 0.01 : 2 * pi;
r = a*(1 - sin(theta));
polar(theta, r, '-r');
clear
t=-pi:pi/100:pi;
r=abs(t);
x=r.*sin(t);
y=r.*cos(t);
plot(x,y)
title('I love you.')
axis equal
clear
x=-2:0.01:2;
y=sqrt(2*sqrt(x.^2)-x.^2);
z=asin(abs(x)-1)-pi./2;plot(x,y);
grid on;
hold on;
plot(x,z);
axis equal;
clear
x=-2:0.01:2;
y=sqrt(2*sqrt(x.^2)-x.^2);
z=asin(abs(x)-1)-pi./2;plot(x,y);
grid on;
hold on;
plot(x,z);
axis equal;
fill(x,y,'r')
fill(x,z,'r')
t=0:0.1:2*pi;
x=16*sin(t).^3;
y=13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t);
figure;
axis([-10,10,-10,10]);
plot(x,y)
clear
t=0:0.1:2*pi;
x=16*sin(t).^3;
y=13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t);
figure;
h = plot(x(1),y(1),'r');
axis([-20,20,-20,20]);
axis off
for idx = 2:length(t)
h.XData(idx) = x(idx);
h.YData(idx) = y(idx);
drawnow
end
clear
t=0:0.1:2*pi;
x=16*sin(t).^3;
y=13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t);
figure;
h = plot(x(1),y(1),'r');
axis([-20,20,-20,20]);
axis off
[A,map] = rgb2ind(frame2im(getframe),256);
imwrite(A,map,'love.gif','LoopCount',inf,'DelayTime',0.1);
for idx = 2:length(t)
h.XData(idx) = x(idx);
h.YData(idx) = y(idx);
drawnow
%这两句话是为了在本地保存的图片也能显示出来,保存地址默认
[A,map] = rgb2ind(frame2im(getframe),256);
imwrite(A,map,'love.gif','WriteMode','append','DelayTime',0.1);
end
https://blog.csdn.net/lpsl1882/article/details/50806694?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
首先添加函数保存
function ratio=HeartRate(i,heartSpeed)
i=mod(i,heartSpeed);
if i < heartSpeed / 2
ratio=sin( i/heartSpeed*pi);
elseif i >= heartSpeed / 2 && i < heartSpeed * 3/4
ratio=2*cos(i/heartSpeed*2/3*pi);
else
ratio = 0;
end
通过Movie函数进行跳动Heartbeats
clear
gcp=figure;
M=moviein(100,gcp);
heartSpeed=15;
radiusRate=3;
for i = 1:100
axis([-20 20 -20 20]);
axis off
[A,map] = rgb2ind(frame2im(getframe),256);
imwrite(A,map,'1.gif','LoopCount',inf,'DelayTime',0.1);
cla(gcp);
x=[];
y=[];
for t = 0:0.01:2*pi
r=(sin(t)*sqrt(abs(cos(t))))/(sin(t)+7/5)-2*sin(t)+2;
r = radiusRate * r;
x=[x,r*cos(t)*(0.5+0.5*HeartRate(i,heartSpeed))];
y=[y,r*sin(t)*(0.5+0.5*HeartRate(i,heartSpeed))];
end
hold on;
fill(x,y,'r');
M(:,i)=getframe;
[A,map] = rgb2ind(frame2im(getframe),256);
imwrite(A,map,'1.gif','WriteMode','append','DelayTime',0.1);
end
movie(M,1);
既然提到heartbeats天使的跳动,自然是我们的天使(不是天降之物啦,可怕想什么呢)