'Filling in plot animation (polar function)

enter image description here

I have a set of videos shown in an assignment. How is this animation created? I am trying to create something similar. Below is my attempt; it is only drawing lines because I believe it is not filling in the correct inputs. Guidance would be much appreciated

clear;close all;

th = 0:0.1:pi*2
r = cos(2*th) .* sin(2*th);
x = r .* cos(th);
y = r .* sin(th);
plot(x,y);
hold on

for th = 0:0.1:pi*2
  x0 = [r .* cos(th)];
  y0 = [r .* sin(th)];
  fill(x0,y0,'b');
  pause (0.5);
end
hold off


Solution 1:[1]

A similar animation can be drawn by filling from lists. Putting clf in the for-loop is optional.

This following code animates the drawing process of a small flower. The flower will look proportionally bigger or smaller by changing the axis.

X = 0:0.01:pi*2;
r = cos(2*X).*sin(2*X);

x=r.*(cos(X));
y=r.*(sin(X));

x_1 = []; y_1 = [];

for i=1:629                    %629 is the size of x and of y
    x_1 = [x(i), x_1];
    y_1 = [y(i), y_1];
    
    fill(x_1,y_1,'b'); hold on;
    axis([-2 2 -2 2]); hold on;
    pause(0.01);
end

Solution 2:[2]

I managed to draw the function in polar coordinates with polarplot(th, radius), I could not fill with yellow color and neither animate the graph, I'm sorry.

clear;close all;

th = linspace(0, 2*pi, 1000);

r = cos(2 .* th) .* sin(2 .* th);

polarplot(th,r)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 P.Y.C.
Solution 2 KarloKalenda