How can I create interactive board?

10 ビュー (過去 30 日間)
Rex Onious
Rex Onious 2020 年 3 月 26 日
回答済み: Tommy 2020 年 3 月 27 日
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;

回答 (1 件)

Tommy
Tommy 2020 年 3 月 27 日
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!

カテゴリ

Help Center および File ExchangeLanguage Fundamentals についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by