How can I create interactive board?

10 visualizaciones (últimos 30 días)
Rex Onious
Rex Onious el 26 de Mzo. de 2020
Respondida: Tommy el 27 de Mzo. de 2020
I have been trying to create interactive board. I want it to change color when I click on it so I can for example write stuff on it. Lets say I have board of 5x5 and click on its pools to write an A. I have been searching for answer to my question in in internet but I was unable to find anything about such thing all I could find is how to make a checkerboard but not how to make empty board that changes colors on click. Can you please give me some information about it and maybe place where I can read how to do this? Here is the board I was able to create:
colors = [0 0 0; 1 1 1];
inds = 1:25;
color_inds = 1+mod(inds,2);
r = colors(color_inds,1);
g = colors(color_inds,2);
b = colors(color_inds,3);
checkers = cat(2,r,g,b);
checkers = reshape(checkers,[5,5,3]);
imagesc(checkers);
axis equal tight;

Respuestas (1)

Tommy
Tommy el 27 de Mzo. de 2020
It sounds like you want to add a mouse-click callback to your image, which is a function that gets called whenever you click inside the image:
colors = [0 0 0; 1 1 1];
inds = 1:25;
color_inds = 1+mod(inds,2);
r = colors(color_inds,1);
g = colors(color_inds,2);
b = colors(color_inds,3);
checkers = cat(2,r,g,b);
checkers = reshape(checkers,[5,5,3]);
im = imagesc(checkers); % Store the image
axis equal tight;
im.ButtonDownFcn = @clickCallback; % Add the callback
function clickCallback(src, event)
pos = get(gca,'CurrentPoint'); % You can obtain the coordinates of the click like this
disp(pos)
end
Then you'll want to determine which square the user clicked inside and update it's color.
Hopefully this helps!

Categorías

Más información sobre Language Fundamentals en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by