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!