%制作带有情节的动画
clc; clear all; close all;
x1 = 0; y1 = 0;
r1 = 10;
t = linspace(0, 2*pi);
tx1 = r1*cos(t) + x1;
ty1 = r1*sin(t) + y1;
figure; hold on; box on;
axis equal; axis off;
set(gcf, 'Color', 'w')
plot(tx1, ty1, 'r-', 'LineWidth', 4);
x2 = -3; y2 = 2;
r2 = 2;
tx2 = r2*cos(t) + x2;
ty2 = r2*sin(t) + y2;
plot(tx2, ty2, 'k-', 'LineWidth', 2);
hf1 = fill(0.5*r2*cos(t) + x2, 0.5*r2*sin(t) + y2, 'k');
x3 = 3; y3 = 2;
r3 = 2;
tx3 = r3*cos(t) + x3;
ty3 = r3*sin(t) + y3;
plot(tx3, ty3, 'k-', 'LineWidth', 2);
hf2 = fill(0.5*r3*cos(t) + x3, 0.5*r3*sin(t) + y3, 'k');
x4 = 0; y4 = -6;
r4 = 2;
tx4 = r4*cos(t) + x4;
ty4 = r4*sin(t) + y4;
tx41 = tx4(1:50);
tx42 = ty4(1:50);
tx43 = tx4(51:100);
tx44 = ty4(51:100);
h1 = plot(tx41, tx42, 'k-', 'LineWidth', 1);
for i = 1 : 10
tc = rand(1, 3);
set(h1, 'LineWidth', 1+i/2, 'Color', tc);
title('###, 姐今天杯具啦!', 'FontWeight', 'Bold', 'Color', tc);
flag = randint(1, 1, [-1 1]);
set(hf1, 'XData', 0.5*r2*cos(t) + x2 + flag*i/10, 'YData', 0.5*r2*sin(t) + y2 + flag*i/10);
set(hf2, 'XData', 0.5*r3*cos(t) + x3 + flag*i/10, 'YData', 0.5*r3*sin(t) + y3 + flag*i/10);
pause(0.2);
end
delete(h1);
h2 = plot(tx43, tx44, 'k-', 'LineWidth', 1);
for i = 1 : 10
tc = rand(1, 3);
set(h2, 'LineWidth', 1+i/2, 'Color', tc);
title('###,姐今天高兴啦!', 'FontWeight', 'Bold', 'Color', tc);
flag = randint(1, 1, [-1 1]);
set(hf1, 'XData', 0.5*r2*cos(t) + x2 + flag*i/10, 'YData', 0.5*r2*sin(t) + y2 + flag*i/10);
set(hf2, 'XData', 0.5*r3*cos(t) + x3 + flag*i/10, 'YData', 0.5*r3*sin(t) + y3 + flag*i/10);
pause(0.2);
end