Code covered by the BSD License

# Chess with "Greedy Edi"

### Wolfgang Garn (view profile)

07 Nov 2009 (Updated )

Play chess against "Greedy Edi".

TransparencyProblem.m
```clc;
% Transparent image with patch as background color
% How do I accomplish that?

%------------------------------------
%Image
% create an empty image (or read it)
X = zeros(100,100,3); %100x100 RGB image

%blue rectangle
X(20:80,20:80,3) = ones(61)*200;
% range [0,255], 0...no blue color, 255 totaly blue

% cast to classic image format
X = uint8(X);

% set transparency of figure
% 0 ... invisible (completly transparent)
% 255 ... not at all transparent
myalpha = zeros(100,100);
myalpha(20:80,20:80) = ones(61)*123; % half transparent
myalpha(40:60,40:60) = ones(21)*255; % not transparent

%display image
shift=.5;
hi = image([0 1]+shift,[0 1], X); % scale to unit square and set position
% set transparency for figure
% An alphamap must have values between 0 and 1!!
alphamap([0:1:255]/255');

% activate transparency
set(hi,'AlphaDataMapping','direct'); %seems not to be necessary
%What's the difference between scaled and direct?
% With an 'scaled' alphamap it adapts to the figure settings
% Actually its not that easy!
% uint8 makes a difference

ax=gca;
temp=get(ax,{'color','xlim','ylim'});
axx=axes({'color','xlim','ylim'},temp); %overlay axes
set(axx,'xtick',[],'ytick',[]) % remove the ticks
set(ax,'color','none'); % set color of current axes
uistack(axx,'bottom'); % send to bottom
%------------------------------------
% Patch as background
% a red unit square
hp = patch([0 1 1 0],[0 0 1 1],-[1 1 1 1],'FaceColor',[1 0 0]);
%Note:
% a) z coordinate does not work
% b) The Face color has range between [0,1]

set(hp,'FaceAlpha',.9);
%set(hp,'AlphaDataMapping','scaled'); %seems not to be necessary
%set(hp,'FaceAlpha','flat');
%set(hp,'FaceAlpha','interp');