在屏幕视频上移动一个点
Move a dot across screen video
我无法弄清楚如何在电影中的屏幕上移动绘制的点。所以假设我绘制了一个点:
plot(-1.4,-1.4, '.k', 'MarkerSize', 20)
并初始化一个视频对象
vidObj = VideoWriter('dot.avi');
vidObj.Quality = 100;
vidObj.FrameRate = 10;
open(vidObj);
那怎么让圆点移动到屏幕右边呢?
要使圆点向右移动,您可以编写一个绘制圆点的循环;在每次迭代中,点的 X
坐标都会递增。
在循环中,您还必须捕获每一帧广告并将其添加到视频文件中。
% Define the initial point's coords
P=[-1.4,-1.4];
% First plot
plot(P(1),P(2), '.k', 'MarkerSize', 20)
% Initialize the video
vidObj = VideoWriter('dot.avi');
vidObj.Quality = 100;
vidObj.FrameRate = 10;
open(vidObj);
% set axis properties
set(gca,'nextplot','replacechildren');
% Set xlim (max vaalue to be set according to the desired final position of
% the point)
set(gca,'xlim',[P(1)*2 150]);
% Loop for the point movement: 100 step, each iteration the pont in moved
% to the right of 1x (where x is the unito of measure of the space)
for i = 1:100
plot(P(1)+i,P(2), '.k', 'MarkerSize', 20)
% Capture the current frame
currFrame = getframe;
% Add the current frame to the video file
writeVideo(vidObj,currFrame);
end
% Close the video file (stop recording)
close(vidObj);
希望对您有所帮助。
我无法弄清楚如何在电影中的屏幕上移动绘制的点。所以假设我绘制了一个点:
plot(-1.4,-1.4, '.k', 'MarkerSize', 20)
并初始化一个视频对象
vidObj = VideoWriter('dot.avi');
vidObj.Quality = 100;
vidObj.FrameRate = 10;
open(vidObj);
那怎么让圆点移动到屏幕右边呢?
要使圆点向右移动,您可以编写一个绘制圆点的循环;在每次迭代中,点的 X
坐标都会递增。
在循环中,您还必须捕获每一帧广告并将其添加到视频文件中。
% Define the initial point's coords
P=[-1.4,-1.4];
% First plot
plot(P(1),P(2), '.k', 'MarkerSize', 20)
% Initialize the video
vidObj = VideoWriter('dot.avi');
vidObj.Quality = 100;
vidObj.FrameRate = 10;
open(vidObj);
% set axis properties
set(gca,'nextplot','replacechildren');
% Set xlim (max vaalue to be set according to the desired final position of
% the point)
set(gca,'xlim',[P(1)*2 150]);
% Loop for the point movement: 100 step, each iteration the pont in moved
% to the right of 1x (where x is the unito of measure of the space)
for i = 1:100
plot(P(1)+i,P(2), '.k', 'MarkerSize', 20)
% Capture the current frame
currFrame = getframe;
% Add the current frame to the video file
writeVideo(vidObj,currFrame);
end
% Close the video file (stop recording)
close(vidObj);
希望对您有所帮助。