# How to animate flow particles like on windy

42 views (last 30 days)
Robert on 2 Dec 2023
Answered: Avni Agrawal on 19 Dec 2023
I am reposting this question from 2017. No real answer since. So let's try again.
Have a look at www.windy.com that animates wind speed and direction. Is there a way to generate an animation such as this for a given flow field in MATLAB?
Thanks
##### 3 CommentsShow 1 older commentHide 1 older comment
Robert on 4 Dec 2023
Right, however animatedline is very limited, you can't set alpha values to fade it out, you can't remove a set of points to make it look like it is moving. I guess the answer is no? there is no simple way to do this.
Dyuman Joshi on 4 Dec 2023
Edited: Dyuman Joshi on 4 Dec 2023
You can add quiver points on the animated line and adjust the properties accordingly. But I guess that would require a good amount of effort.
Does it have to be live animation (with some delay)?

Avni Agrawal on 19 Dec 2023
Hi Robert,
I understand that you want to create a similar animation to that of www.windy.com in a particular direction. MATLAB provides several tools and functions that can be used to create animations similar to the wind speed and direction visualization seen on websites like www.windy.com. To animate a given flow field, you can use MATLAB's built-in functions such as ‘quiver’, ‘streamline’, or ‘streamribbon’ for visualizing vector fields, and then create an animation by updating the data in a loop and capturing frames for a video or GIF.
Here is a simple example of how to create an animation of a flow field using the quiver function:
% Define the grid points where the flow field is computed
[x, y] = meshgrid(0:0.2:10, 0:0.2:10);
% Define the flow field (u and v are the velocity components in the x and y directions)
% Here we use a simple example of a rotating flow field
u = -y;
v = x;
% Create a figure window
figure;
% Number of frames in the animation
numFrames = 120;
% Preallocate the array for storing the frames
frames(numFrames) = struct('cdata', [], 'colormap', []);
% Loop to create each frame of the animation
for k = 1:numFrames
% Update the flow field or any parameters for animation
u = -y * cos(k * 2 * pi / numFrames);
v = x * sin(k * 2 * pi / numFrames);
% Clear the axes for the new frame
cla;
% Plot the flow field using the quiver function
quiver(x, y, u, v);
% Set the axis limits
axis([0 10 0 10]);
% Capture the frame for the animation
frames(k) = getframe(gcf);
end
% Create an animation (video or GIF)
% For a video:
videoFile = VideoWriter('flowFieldAnimation.mp4', 'MPEG-4');
open(videoFile);
writeVideo(videoFile, frames);
close(videoFile);
% For a GIF:
% Use the imwrite function with 'DelayTime' and 'LoopCount' options in a loop
% to write each frame to the GIF file.
In the example above, we create a simple rotating flow field and animate it over numFrames frames. The quiver function is used to plot the velocity vectors of the flow field. The getframe function captures each frame, which can then be compiled into a video using MATLAB's VideoWriter class or into a GIF using the imwrite function.

### Categories

Find more on Animation in Help Center and File Exchange

R2023b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!