How can I create interactive board?
10 views (last 30 days)
Show older comments
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;
0 Comments
Answers (1)
Tommy
on 27 Mar 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.
More about the mouse-click callback: https://www.mathworks.com/help/matlab/ref/matlab.graphics.primitive.image-properties.html#d120e595216
More about CurrentPoint: https://www.mathworks.com/help/matlab/ref/matlab.graphics.axis.axes-properties.html#d120e60454
Hopefully this helps!
0 Comments
See Also
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!