How to move a white square through a black grid
조회 수: 2 (최근 30일)
이전 댓글 표시
ATHANASIOS KONSTANTAKOPOULOS
2021년 1월 5일
댓글: ATHANASIOS KONSTANTAKOPOULOS
2021년 1월 5일
I have made a black 256x256 grid and i want to move a 8x8 white square in an horizontal line, from the top-left corner to the top-right corner, using for loops and the implay command, so i can view the 36 seperate frames in an order, so it seems like a video is playing,depicting the moving square.
This is the code I tried :
x=zeros(256,256);
for M=8:7:256
for T=2:36
x(1:8,M-7:M,T-1:T)=255;
end
end
implay(x,4)
This code gives me 36 frames, but every one of these 36 frames does not depict the square in a different position as it should, but it depicts all the possible positions.
Can someone help ?
댓글 수: 0
채택된 답변
KALYAN ACHARJYA
2021년 1월 5일
편집: KALYAN ACHARJYA
2021년 1월 5일
Have you tried this way?
x=zeros(256,256);
original_dat=x;
block=ones(8,8);
h=figure,
for i=1:8:256
for j=1:8:256
refresh(h)
x=original_dat;
x(i:i+7,j:j+7)=x(i:i+7,j:j+7)+block;
imshow(x);
pause(0.5); % set as per requirements
end
end
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!