How to move a white square through a black grid
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
ATHANASIOS KONSTANTAKOPOULOS
el 5 de En. de 2021
Comentada: ATHANASIOS KONSTANTAKOPOULOS
el 5 de En. de 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 comentarios
Respuesta aceptada
KALYAN ACHARJYA
el 5 de En. de 2021
Editada: KALYAN ACHARJYA
el 5 de En. de 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
Más respuestas (0)
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!