Matlab painting animation

Source: Internet
Author: User

In general, there are four ways in which Matlab makes animations. first, the way of the trajectory of the particle motion displayUsing the comet, Comet3 function, the former is two-dimensional, the latter is a three-dimensional comet (Y) shows a particle around the vector y,comet (x, y) shows a particle around the vector y and X,comet (x,y,p), which is the length of the trajectory tail with comet (x, y) as an example, showing the horizontal parabolic motion   VX = 40;   t = 0:0.001:10;   x = vx*t;   y = -9.8*T.^2/2; Comet (x, y)
Show missile launch VX =100*cos (1/4*PI);   VY =100*sin (1/4*PI);   t = 0:0.001:15;   x = vx*t;   Y =VY*T-9.8*T.^2/2;   Comet (x, Y) uniform circular motions SITA =0:0.0001:2*pi;   R = 10;   X=r*cos (SITA);   Y=r*sin (SITA);      Comet (x, y) Comet3 is similar to the use of comet, and can be used in the Help file for example t = -10*PI:PI/250:10*PI; Comet3 ((cos (2*t). ^2). *sin (t), (Sin (2*t). ^2). *cos (t), T)
second, show by the way the movie playsSave the picture you want to animate, stored as a series of two-dimensional, three-dimensional graphs of various types, and then play them out in sequence as you would a movie. The step is to capture the current picture as a picture of the movie by the GetFrame function and the movie function to display the animation. such as: [x, Y] = Meshgrid ([ -1.05:.2:3.75]), z = X.*exp (-x.^2-y.^2), Axis tight;set (GCA, ' nextplot ', ' Replacechildren '); for j =      1:40 Surf (X*sin (pi*j/100), Y*sin (pi*j/100), Z*sin (-pi*j/100)); M (j) = Getframeendmovie (M) third, display the object waySets the object's properties Erasemode, updates the object to produce a new diagram, and the Drawnow () function overwrites the old graph, which keeps the shape constantly changing. Example: x =-pi:pi/30:pi;h =plot (x,cos (x), ' O ', ' markeredgecolor ', ' k ', ' Markerfacecolor ', ' r ', ' Markersize ', 8, ' Erasemode ', '      Xor ') for j = 1:10000 y = 1/2*sin (3*x+0.006*j);      Set (H, ' ydata ', y); Drawnow;end Iv. Display in a rotating color modeHow to output AVI format movie file in matlab
The above article, "Fly through graphics animation example" as the basis, the screen display of the animation to the AVI format file. CLC % clear screen clear all; % clear all variables load wind; % load matlab comes with data program wind_speed = sqrt (u.*u + v.*v + w.*w),  % calculates wind speed Hpatch=patch (Isosurface (x,y,z,wind_speed,35)); Isosurface calculates wind_speed=45 's equipotential surface%patch command to draw equipotential surface isonormals (x,y,z,wind_speed,hpatch),%isonormals calculates the orthogonal vectors of the same potential plane, making the picture smoother set ( Hpatch, ' facecolor ', ' Red ', ' edgecolor ', ' none '),% setting equipotential surface the surface color is red daspect ([1 1 1]);? ta Aspect[fverts]=reducepatch ( Isosurface (x,y,z,wind_speed,45),. Reducepatch, reduce the number of surfaces required to depict equipotential surface, reducing to 5%hcone=coneplot (X,y,z,u,v,w,verts (:, 1), Verts (:, 2), Verts (:, 3), 2);% draws a cone fluid set across the equipotential surface (hcone, ' facecolor ', ' Blue ', ' edgecolor ', ' none '); Camproj perspective  % sets the projection of the shape as a perspective camva (25); % Set angle of view is 25 degrees Hlight = camlight (' headlight '); % creates a light source in the camera. Set (Hpatch, ' ambientstrength ',. 1,...  % set ambient light to a luminosity of 0.1, the surface ambient light is near black     ' specularstrength ', 1, ... % set the specular intensity of the block object to 1    ' diffusestrength ', 1);   % set fast object with diffuse intensity of 1set (Hcone, ' specularstrength ', 1);  % sets the specular intensity of the conical fluid to 1set (GCF, ' Color ', ' K '); % sets the color of the image window to black LiGhting Phong  %sets The lighting tophong.set (GCF, ' Renderer ', ' zbuffer ');% set the shading property of the light source to ZBuffer, or you can try opengl  Hsline=streamline (x,y,z,u,v,w,80,30,11);  % creates a streamline xd = Get (hsline, ' Xdata ') starting from the point (80,30,11);  % obtains the X, y of this streamline, z-coordinate yd = Get (hsline, ' ydata '); ZD = Get (Hsline, ' zdata ');d elete (hsline); The% streamline has been useless, can be removed  % following the core part of this animation aviobj=avifile (' Fly_through.avi ', ' fps ', 3);% create Avi object, named Fly_through.avi, 3 frames per second for I=1: Length (XD) -50  % starts at point (80,30,11) and ends at 50 points before the end point.    campos ([XD (i), yd (i), ZD (i)]);  % set the camera position to the current point position    camtarget ([XD (I+5), yd (i), ZD (i)]),  % set the target position of the camera, 5 points forward at the camera position     Camlight (hlight, ' headlight ');  % Light source is also moved to the camera     drawnow % draw the moved graphics     Frame=getframe (GCF)  % get current frame    Aviobj=addframe (aviobj,frame);  % adds the current image to the AVI object Endaviobj=close (aviobj);  % closing AVI object% Note that this method, the runtime cannot move or change the size of the animation window. function Makeavi (filepath,frames,format)% This function make AVI video from images% filepath:    the locationof Target IMAGe% Frames:     The Numbles offrame that's want to use  % Fromat:     The format ofimages%===== =========== Setting related properties ======================location=filepath; fig=figure; set (Fig, ' DoubleBuffer ', ' on ');  set (GCA, ' Xlim ', [ -80], ' Ylim ', [ -80],...      ' nextplot ', ' replace ', ' Visible ', ' off ')   Aviobj=avifile (' Examples.avi '); % Create a new AVI file aviobj.quality = 100; % valid only for compression format,[0,100],default:75 aviobj.fps=1;    %the speedof the AVI movie in frames per second (fps), default:15 fps aviobj.compression= ' None ';  % COMPRESSIONCODEC Specifies the compression codec%======= set black-and-white image properties ===========%cola=0:1/255:1;    %cola=[cola;cola;cola];%cola=cola ';  %aviobj.colormap=cola;% ===== multi-frame loop start, read sequence image =========== ======for num=1:frames     Im_origin = Imread (strcat (location, ' \ ', NUM2STR (num), '. ', format));      Im=im2uint8 (im_origin);    % F =getframe (GCA);     Aviobj =addFRAME (Aviobj,uint8 (Im));  end aviobj=close (aviobj);  mov = Aviread (' Examples.avi ');  movie (MOV) ;  close all;  reprinted from: http://blog.sina.com.cn/s/blog_6b7d710b0101m39u.html

Matlab Painting animation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.