Graphical input from the grid - similar to game of life

6 vues (au cours des 30 derniers jours)
Uros
Uros le 17 Avr 2011
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

Réponses (1)

Matt Tearle
Matt Tearle le 17 Avr 2011
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 commentaires
Uros
Uros le 17 Avr 2011
First thank you for the answer, it really helped me. When you say
'Use set to update the ZData' for the selected matrix, do you mean that my pictures should be divided as a 100x100 matrix or ?
Matt Tearle
Matt Tearle le 18 Avr 2011
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Conway's Game of Life dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by