Code covered by the BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Animations

Be the first to rate this file! 13 Downloads (last 30 days) File Size: 7.19 KB File ID: #24058 Version: 1.6
image thumbnail

Animations

by

 

09 May 2009 (Updated )

Some animations in MATLAB

| Watch this File

File Information
Description

Function creating simple animation in MATLAB. These include epitrochoid, hypotrochoid, cycloid, double pendulum , falling ball, spring mass system, Belousov-Zhabotinsky Reaction.

Required Products Image Processing Toolbox
MATLAB
MATLAB release MATLAB 7.1.0 (R14SP3)
MATLAB Search Path
/
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
08 May 2016 Ankur Pawar

BZ reaction link http://discovery.ucl.ac.uk/17241/1/17241.pdf

Comment only
02 Oct 2012 Anton Semechko

Hi Ankur,

your submission inspired this:

http://www.mathworks.com/matlabcentral/fileexchange/38473-belousov-zhabotinsky-reaction-on-2-manifold

Comment only
01 Oct 2012 Anton Semechko

Hi Ankur. I made some changes to your BZanimation script that make it run much faster. Specifically, I vectorized two of the innermost loops using linear indices.

function BZreaction
%BZreaction animation
%Belousov-Zhabotinsky Reaction animation
%This MATLAB code is converted from Processing code available in this link
%http://www.aac.bartlett.ucl.ac.uk/processing/samples/bzr.pdf

%version 2. Corrected the drift of pixels as suggested
% by Jonh.

xres=256; %x resolution
yres=256; %y resolution

a=rand(xres,yres,2);
b=rand(xres,yres,2);
c=rand(xres,yres,2);
p = 1;
q = 2;
img=zeros(xres,yres,3);

mm = mod((1:xres+2)+xres,xres)+1;
nn = mod((1:yres+2)+yres,yres)+1;
[mm,nn]=meshgrid(mm,nn);
idx=sub2ind([yres xres],nn(:),mm(:));
idx=reshape(idx,[yres xres]+2);

figure
for k=1:1000

c_a = zeros(xres,yres);
c_b = zeros(xres,yres);
c_c = zeros(xres,yres);

for m=1:xres
for n=1:yres

idx_temp=idx(m:m+2,:);
idx_temp=idx_temp(:,n:n+2);
idx_temp=idx_temp(:);
if p==2
idx_temp=idx_temp+(xres+0)*(yres+0);
end

c_a(m,n) =c_a(m,n)+ sum(a(idx_temp));
c_b(m,n) =c_b(m,n)+ sum(b(idx_temp));
c_c(m,n) =c_c(m,n)+ sum(c(idx_temp));

end
end

%correction of pixel drift
c_a = circshift(c_a,[2 2]);
c_b = circshift(c_b,[2 2]);
c_c = circshift(c_c,[2 2]);

c_a =c_a/ 9.0;
c_b =c_b/ 9.0;
c_c =c_c/ 9.0;

a(:,:,q) = double(uint8(255*(c_a + c_a .* (c_b - c_c))))/255;
b(:,:,q) = double(uint8(255*(c_b + c_b .* (c_c - c_a))))/255;
c(:,:,q) = double(uint8(255*(c_c + c_c .* (c_a - c_b))))/255;

img(:,:,1)=c(:,:,q);
img(:,:,2)=b(:,:,q);
img(:,:,3)=a(:,:,q);

if p == 1
p = 2; q = 1;
else
p = 1; q = 2;
end

image(uint8(255*hsv2rgb(img)))
axis equal off
drawnow
end

Comment only
11 Mar 2012 John Bullinga

The BZ animation has a drift of two pixels up and left per cycle that may be corrected by adding

c_a = circshift(c_a,[2 2]);
c_b = circshift(c_b,[2 2]);
c_c = circshift(c_c,[2 2]);

before the 'c_a =c_a/ 9.0;' line

Comment only
Updates
16 May 2009 1.2

remove these comments to convert the animation to movie.
%M = moviein(91);
%M(:,n+1)=getframe;

17 Jul 2009 1.3

I want suggestion.
how to increase the speed of animation without decreasing the pause?

07 May 2010 1.4

Included more animations

01 Oct 2012 1.5

Pixel drift in BZanimation3.m was corrected as suggested by John.

08 May 2016 1.6

- Code improvements.
- Correct number of rotations for epitrochoid and hypotrochoid.

Contact us