Graphical input from the grid - similar to game of life
6 次查看(过去 30 天)
显示 更早的评论
Hi everyone, I am working on a project and so far in class we have covered a lot in matlab but we have not done anything with GUI. What I am trying to do is to created interactive grid 100x100 represented by squares and then allow user to pick any point on the grid but the coordinates(x,y) have to be integers. Then I would change the color of that one square cell. This is very similar to the interface of Game of life. I know I asked a lot in these couple lines but if someone can just give me a hit where to start or how to create the interactive grid that would really help me.
Thanks,
Uros
0 个评论
回答(1 个)
Matt Tearle
2011-4-17
image or imagesc with a custom three-color colormap to make the image, then ginput to get the point (and round as necessary).
Use set to update the 'ZData' property of the image after you change the value of the selected matrix element.
2 个评论
Matt Tearle
2011-4-18
Right. I'm assuming that you're storing the information as a 100-by-100 matrix -- typical Game of Life kind of thing would be to start with A = zeros(100); Then change any elements to either 1 or 2 (or -1 or 1, or whatever), and your colormap associates 0 with white, 1 with blue, 2 with red (or whatever). After you click on a white square, your program would change the appropriate element of A to 1 or 2. Then you need to update your image. Rather than reissue the image/imagesc command, just update the ZData property to be the new A.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Conway's Game of Life 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!