How can I create interactive board?

조회 수: 11 (최근 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 CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by