- 积分
- 0
- 注册时间
- 2008-6-4
- 仿真币
-
- 最后登录
- 1970-1-1
|
% MakingShrinkingSquareMovie.m
%
% Discussion:
%
% This is a simple program to create an
% Audio Video Interleaved (AVI) movie that can be played
% independently of Matlab. We capture NUMFRAMES frames for shrinking/Enlarging square to/from the center
% for the ADHD research
% Before running this program close all figures and don't interfere
% with the generated figures until the recording process is done.
%
close all;
clear all;
fprintf ( 1, '\n' );
fprintf ( 1, 'MAKEING MOVIES FRAMES FOR AVI FILE \n' );
fprintf ( 1, ' Create an AVI animation of simple graphics,\n' );
fprintf ( 1, ' generating one frame at a time.\n' );
%
% Control resolution of and graph default
%
pixel_x=360;
pixel_y=360;
A= zeros([pixel_y pixel_x]);
max_square_bandwidth = 20;
min_square_bandwidth = 8;
min_square_side = 20; % center target size equal to side x side;
A(max_square_bandwidth : pixel_y - max_square_bandwidth , max_square_bandwidth : pixel_x-max_square_bandwidth)=255;
A((pixel_y-min_square_side)/2:(pixel_y+min_square_side)/2, (pixel_x-min_square_side)/2:(pixel_x+min_square_side)/2) = 0;
imshow(A)
%
% Set the total number of frames that we will generate.
%
numframes = 180;
sliding_axes = sqrt(((pixel_y-min_square_side)/2 - max_square_bandwidth)^2 + ((pixel_x-min_square_side)/2-max_square_bandwidth)^2);
hp = sliding_axes / numframes;
%
% Control how fast final movie will play; total time
% of movie in seconds will be about (numframes)/(num_frames_per_second)
%
num_frames_per_second = 20;
dur = numframes / num_frames_per_second;
fprintf ( 1, '\n' );
fprintf ( 1, ' This movie will contain %d frames.\n', numframes );
fprintf ( 1, ' The number of frames per second will be %f\n', num_frames_per_second );
fprintf ( 1, ' so the movie should take %f seconds to play.\n', dur );
%
%
% The AVIFILE function creates a new Audio Video Interleaved (AVI) file.
% We specify its name, and we also set the value of "FPS", which is the
% rate at which we will display frames (individual snapshots) per second.
%
aviobj = avifile ( 'flyingsquare.avi', 'fps', num_frames_per_second );
%
% Control resolution of square
%
num_nodes = 100;
i = 1 : num_nodes + 1;
%
% Control speed of contraction/
%
%h1 = i - 1 ; % for equal speed contraction
h2 = exp((i-1) / (num_nodes/2));
h3y = h2/sum(h2) * ((pixel_y-min_square_side)/2 - max_square_bandwidth);
h3x = h2/sum(h2) * ((pixel_x-min_square_side)/2 - max_square_bandwidth);
%%% h = 2 * pi / num_nodes;
%
% Control square band width
%
b2 = exp((i-1) / (num_nodes/2));
band_range = max_square_bandwidth - min_square_bandwidth;
b3 = band_range * b2/sum(b2);
white_band_frames = 20;
%
% Make plots of squares. Each new plot is a frame which
% can be added to the AVI movie using the ADDFRAME function.
%
j=0;k=0;l=0; o=0;
for z = 1 : numframes+1
j=j+1;
if j > num_nodes+1
else
band = max_square_bandwidth - sum(b3(1:j));
p1 = [ sum(h3y(1:j)) + max_square_bandwidth sum(h3x(1:j)) + max_square_bandwidth ];
p2 = [ pixel_y - (sum(h3y(1:j)) + max_square_bandwidth) sum(h3x(1:j)) + max_square_bandwidth ];
p3 = [ sum(h3y(1:j)) + max_square_bandwidth pixel_x - (sum(h3x(1:j)) + max_square_bandwidth) ];
A( p1(1) - band : p2(1) + band , p1(2) - band : p3(2) + band ) = 0;
A(p1(1):p2(1), p1(2):p3(2)) = 255;
end
A(max_square_bandwidth : pixel_y - max_square_bandwidth , max_square_bandwidth : pixel_x-max_square_bandwidth)=255;
if j < white_band_frames
else
k=k+1;
if k > num_nodes+1
else
band2 = max_square_bandwidth - sum(b3(1:k));
p11 = [ sum(h3y(1:k)) + max_square_bandwidth sum(h3x(1:k)) + max_square_bandwidth ];
p12 = [ pixel_y - (sum(h3y(1:k)) + max_square_bandwidth) sum(h3x(1:k)) + max_square_bandwidth ];
p13 = [ sum(h3y(1:k)) + max_square_bandwidth pixel_x - (sum(h3x(1:k)) + max_square_bandwidth) ];
end
if k < white_band_frames
else
l=l+1;
if l > num_nodes+1
else
band3 = max_square_bandwidth - sum(b3(1:l));
p21 = [ sum(h3y(1:l)) + max_square_bandwidth sum(h3x(1:l)) + max_square_bandwidth ];
p22 = [ pixel_y - (sum(h3y(1:l)) + max_square_bandwidth) sum(h3x(1:l)) + max_square_bandwidth ];
p23 = [ sum(h3y(1:l)) + max_square_bandwidth pixel_x - (sum(h3x(1:l)) + max_square_bandwidth) ];
end
if l < white_band_frames
else
o=o+1;
if o > num_nodes+1
else
band4 = max_square_bandwidth - sum(b3(1:o));
p31 = [ sum(h3y(1:o)) + max_square_bandwidth sum(h3x(1:o)) + max_square_bandwidth ];
p32 = [ pixel_y - (sum(h3y(1:o)) + max_square_bandwidth) sum(h3x(1:o)) + max_square_bandwidth ];
p33 = [ sum(h3y(1:o)) + max_square_bandwidth pixel_x - (sum(h3x(1:o)) + max_square_bandwidth) ];
end
A( p31(1) - band4 : p32(1) + band4 , p31(2) - band4 : p33(2) + band4 ) = 0;
A( p31(1) : p32(1), p31(2) : p33(2)) = 255;
end
A( p21(1) - band3 : p22(1) + band3 , p21(2) - band3 : p23(2) + band3 ) = 0;
A( p21(1) : p22(1), p21(2) : p23(2)) = 255;
end
A( p11(1) - band2 : p12(1) + band2 , p11(2) - band2 : p13(2) + band2 ) = 0;
A( p11(1):p12(1), p11(2):p13(2)) = 255;
end
A( p1(1) - band : p2(1) + band , p1(2) - band : p3(2) + band ) = 0;
A(p1(1):p2(1), p1(2):p3(2)) = 255;
A((pixel_y-min_square_side)/2:(pixel_y+min_square_side)/2, (pixel_x-min_square_side)/2:(pixel_x+min_square_side)/2) = 0;
imshow(A);
axis tight
frame = getframe ( gca );
aviobj = addframe ( aviobj, frame );
end
%
% Tell MATLAB we have completed the movie.
%
aviobj = close ( aviobj );
fprintf ( 1, '\n' );
fprintf ( 1, ' Normal end of execution.\n' );
fprintf ( 1, ' The movie file "flyingsquare.avi" has been created.\n' );
-----------------------------------------------------------------------------------------------------------
上面这个是一个渐变方块的图像,如何将其修改为渐变圆的。。大家帮忙看看。。
非常感谢!!
[ 本帖最后由 quyinhong 于 2008-6-6 12:05 编辑 ] |
|