How do I create a rectangular piece image that can be positioned on a game board

조회 수: 4 (최근 30일)
I am currently trying to create the game stratego in matlab. I am not sure how to create the stratego pieces (essentially just a 2-D rectangle that can have numbers/letters on one side) which must be able to go on top of another image (the game board). Is there some chess file that shows how to create pieces like that, or does anyone have any ideas on how to do that? Please let me know

채택된 답변

jonas
jonas 2018년 10월 26일
편집: jonas 2018년 10월 27일
I would just use textboxes. For example:
A = repmat([repmat([1 0],1,5);repmat([0 1],1,5)],5,1)
cmap = [0 0 0;1 1 1;1 0 0;0 0 1;0 1 0];
colormap(cmap)
A(10,10)=4;
pcolor(A)
p(1) = annotation('textbox',[norm2ax(1,1) 0.05 0.05],...
'string','A',...
'backgroundcolor','b',...
'color','w',...
'horizontalalignment','center',...
'verticalalignment','middle')
function out = norm2ax(Xa,Ya)
ax = gca;
Xn = ax.Position(1) + (Xa-ax.XLim(1)) .* ax.Position(3)/(diff(ax.XLim));
Yn = ax.Position(2) + (Ya-ax.YLim(1)) .* ax.Position(4)/(diff(ax.YLim));
out = [Xn,Yn];
end
The input to the custom function "norm2ax" is the location of your piece. To change the location after creating it. Just Change the position property of p(1).
Disclaimer: have never played stretego.
  댓글 수: 1
jonas
jonas 2018년 10월 27일
편집: jonas 2018년 10월 27일
Note that I updated the script and added a function for converting axes coordinates to normalized figure coordinates. Pass the axes coordinates to "norm2ax". Cheers!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Board games에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by