How to move a white square through a black grid
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
ATHANASIOS KONSTANTAKOPOULOS
il 5 Gen 2021
Commentato: ATHANASIOS KONSTANTAKOPOULOS
il 5 Gen 2021
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 Commenti
Risposta accettata
KALYAN ACHARJYA
il 5 Gen 2021
Modificato: KALYAN ACHARJYA
il 5 Gen 2021
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
Più risposte (0)
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!