Matlab에서 2D AVI 애니메이션을 만들었습니다. 녹색 점 하나와 파란색 점 하나가 선을 따라 다른 방향으로 움직입니다. 하지만 이제는이 AVI 애니메이션 비디오에 다른 점을 추가하고 싶습니다.이 점은 다른 두 점과 함께 무작위로 이동하며, 여기에 코드를 작성해야합니까? 첨부 된 코드는 내 코드입니다. 도와 주셔서 대단히 감사합니다!Matlab에서 2D avi 애니메이션 생성
clc; clear;
%time steps
N=20;
%start position of one moving object
x_pos=10;
y_pos=10;
x1_pos=100;
y1_pos=100;
%speed of the moving object
speed_x=3;
speed_y=2;
speed_x1=-4;
speed_y1=-2;
%ini white image with size 100 x 150
image=ones(100,150,3);
%initialization of videowriter
outputVideo = VideoWriter('test.avi');
outputVideo.FrameRate = 5; %set frame rate of the image
open(outputVideo)
%drawing a moving object on an image plane and creating the video
size=2;
for i=1:N
%update states of moving object
x_pos=x_pos+speed_x;
y_pos=y_pos+speed_y;
x1_pos=x1_pos+speed_x1;
y1_pos=y1_pos+speed_y1;
%draw the measurement on the image using a green point with specific size size=4;
image((x_pos-size/2):(x_pos+size/2),(y_pos-size/2):(y_pos+size/2),1)=0;
image((x_pos-size/2):(x_pos+size/2),(y_pos-size/2):(y_pos+size/2),3)=0;
image((x1_pos-size/2):(x1_pos+size/2),(y1_pos-size/2):(y1_pos+size/2),2)=0;
image((x1_pos-size/2):(y1_pos+size/2),(y1_pos-size/2):(y1_pos+size/2),1)=0;
%give the image to the video writer object
writeVideo(outputVideo,image)
end
close(outputVideo);
어, "임의"의미는 무엇입니까? 무작위로 시작하여 무작위로 이동합니까? –
@HunterJiang 네, 맞습니다. 같은 비디오 이미지에서 라인 패스가 아닌 다른 두 개와 함께 움직이기는하지만 무작위로 움직입니다. –