No BSD License  

Magic Cards

by

 

17 Aug 2003 (Updated )

Magic Card Game - You must try it.

magiccards()
function dummy = magiccards()
% This Program performs a Magic Game using Playing Cards
% It tries to Detect the secret card that is in Your Mind
% You Choose a certain card from a group of six cards
% You Concentrate on it for five seconds
% After that You Press (Enter) Key
% The cards disappear and then They are displayed again
% WITHOUT the card that is in Your Mind

% Programmed by: Mina Ayman (mina_ayman@yahoo.com)
% Using MATLAB R12 on 15/08/2003
% Enjoy Your Play !!!

% Loading Images for Out of Display Period
load imdemos trees
load imdemos saturn
load imdemos flower

% Setting the Background for the Cards

clear h
figure
set(gca,'Position',[0 0 1 1])
set(gca,'Xtick',[],'Ytick',[])
set(gca,'Box','on')
set(gca,'Color',[1 0 1])
axis equal
axis([0 9 0 5])

hold on

% Introduction
p = title('Welcome to MAGIC CARDS');
set(p,'Color',[0 0.5 0])
set(p,'FontWeight','bold')
set(p,'FontSize',26)

% Setting initial Cards
pause(0.4);
h(1,:) = cardplot(0.3,2,2,6,'h');
toot
pause(0.3);
h(2,:) = cardplot(1.7,2,2,8,'s');
toot
pause(0.3);
h(3,:) = cardplot(3.1,2,2,7,'c');
toot
pause(0.3);
h(4,:) = cardplot(4.5,2,2,8,'d');
toot
pause(0.3);
h(5,:) = cardplot(5.9,2,2,6,'c');
toot
pause(0.3);
h(6,:) = cardplot(7.3,2,2,7,'h');
toot
pause(0.7);

% Displaying Rules of the game
set(p,'String','Concentrate on ONE Card')
pause(3);
set(p,'String','Keep it in Your Mind for 5 seconds')
set(p,'FontSize',21)
pause(3);
set(p,'String','When You finish, Press (Enter)')
set(p,'FontSize',23)
pause;
close;
pause(0.5);
figure
imshow(flower,'notruesize');
toot2
pause(4);
close;
pause(0.5);
figure
imshow(saturn,'notruesize');
toot2
pause(4);
close;
pause(0.5);
figure
imshow(trees,'notruesize');
toot2
pause(4);
close;

% Displaying The Answer
% Setting the Background for the Cards

clear h
figure
set(gca,'Position',[0 0 1 1])
set(gca,'Xtick',[],'Ytick',[])
set(gca,'Box','on')
set(gca,'Color',[1 0 1])
axis equal
axis([0 9 0 5])

hold on

% Introduction
p = title('The Card in Your Mind is not here');
set(p,'Color',[0 0.5 0])
set(p,'FontWeight','bold')
set(p,'FontSize',22)

% Setting final Cards
pause(0.4);
h(1,:) = cardplot(0.4,2,2,6,'s');
toot
pause(0.3);
h(2,:) = cardplot(2.1,2,2,8,'c');
toot
pause(0.3);
h(3,:) = cardplot(3.8,2,2,6,'d');
toot
pause(0.3);
h(4,:) = cardplot(5.5,2,2,7,'s');
toot
pause(0.3);
h(5,:) = cardplot(7.2,2,2,8,'h');
toot
pause(0.7);

set(p,'String','Did I pick the Right Card?')
set(p,'FontSize',25)
pause(6)
close;

 % End of Program
fprintf('\n\n\n Thank You for using this Program')
fprintf('\n Programmed by MINA AYMAN')
fprintf('\n Questions or Comments : e-mail ( mina_ayman@yahoo.com )\n')
clear

% Importing the cardplot function
% Copyright (c) 2003-08-05, B. Rasmus Anthin.
function [H,x1,y1]=cardplot(x,y,siz,val,suit)

h0=8.7;  %cm,  total height
w0=5.75; %cm,  total width
h1=8;    %cm,  height before arc
w1=5.05; %cm,  width before arc

h0s=siz;
w0s=w0/h0*siz;
h1s=h1/h0*siz;
w1s=w1/h0*siz;
dl=(h0s-h1s)/2;   % = (w0s-w1s)/2
r=dl;

bottom=x+dl+linspace(0,w1s) + ...
   i*y;
top=x+dl+linspace(0,w1s) + ...
   i*(y+h0s);
left=x + ...
   i*(y+dl+linspace(0,h1s));
right=x+w0s + ...
   i*(y+dl+linspace(0,h1s));
alb=x+dl+r*cos(linspace(pi,pi*3/2)) + ...
   i*(y+dl+r*sin(linspace(pi,pi*3/2)));
arb=x+w1s+dl+r*cos(linspace(-pi/2,0)) + ...
   i*(y+dl+r*sin(linspace(-pi/2,0)));
alt=x+dl+r*cos(linspace(pi/2,pi)) + ...
   i*(y+h1s+dl+r*sin(linspace(pi/2,pi)));
art=x+w1s+dl+r*cos(linspace(0,pi/2)) + ...
   i*(y+h1s+dl+r*sin(linspace(0,pi/2)));

L=[bottom arb right art top alt left alb];
xx=real(L);
yy=imag(L);

h(1)=patch(xx,yy,'w');
ax=axis;

switch(lower(suit(1)))
case 'c'
   sstr='\clubsuit';
   col='k';
case 'd'
   sstr='\diamondsuit';
   col='r';
case 'h'
   sstr='\heartsuit';
   col='r';
case 's'
   sstr='\spadesuit';
   col='k';
otherwise    %turned
   sstr='';
   col='k';
end
h=[h plotsuit(x,y,h0,w1s,h1s,dl,siz,sstr,col)];

switch(upper(val))
case {1,'A'}, vstr='A';
case {2,3,4,5,6,7,8,9,10}, vstr=num2str(val);
case {11,'J'}, vstr='J';
case {12,'Q'}, vstr='Q';
case {13,'K'}, vstr='K';
otherwise, vstr='';
end
h=[h plotvalue(x,y,h0,w1s,h1s,dl,siz,vstr,col)];


fsiz=2/h0*siz/diff(ax(3:4));
%tile up as many suit symbols that corresponds to the card's value
hsc=linspace(.17,.88,13); 
wsc=linspace(.31,.71,3);
hh=[];
if any(upper(val)==[1 'A' 3 5 9])
   hh=[hh text(x+w0s*wsc(2),y+h0s*hsc(7),sstr,'fontunits','norm','horiz','c','vert','m')];
end
if any(val==[2 3])
   hh=[hh text(x+w0s*wsc(2),y+h0s*hsc(13),sstr,'fontunits','norm','horiz','c','vert','m')];
   hh=[hh text(x+w0s*wsc(2),y+h0s*hsc(1)-dl,sstr,'fontunits','norm','horiz','c','vert','m','rot',180)];
end
if any(val==[4:10])
   hh=[hh text(x+w0s*wsc(1),y+h0s*hsc(13),sstr,'fontunits','norm','horiz','c','vert','m')];
   hh=[hh text(x+w0s*wsc(3),y+h0s*hsc(13),sstr,'fontunits','norm','horiz','c','vert','m')];
   hh=[hh text(x+w0s*wsc(1),y+h0s*hsc(1)-dl,sstr,'fontunits','norm','horiz','c','vert','m','rot',180)];
   hh=[hh text(x+w0s*wsc(3),y+h0s*hsc(1)-dl,sstr,'fontunits','norm','horiz','c','vert','m','rot',180)];
end
if any(val==[6:8])
   hh=[hh text(x+w0s*wsc(1),y+h0s*hsc(7),sstr,'fontunits','norm','horiz','c','vert','m')];
   hh=[hh text(x+w0s*wsc(3),y+h0s*hsc(7),sstr,'fontunits','norm','horiz','c','vert','m')];
end
if any(val==[7:8])
   hh=[hh text(x+w0s*wsc(2),y+h0s*hsc(10),sstr,'fontunits','norm','horiz','c','vert','m')];
end
if val==8
   hh=[hh text(x+w0s*wsc(2),y+h0s*hsc(4)-dl,sstr,'fontunits','norm','horiz','c','vert','m','rot',180)];
end
if any(val==[9:10])
   hh=[hh text(x+w0s*wsc(1),y+h0s*hsc(9),sstr,'fontunits','norm','horiz','c','vert','m')];
   hh=[hh text(x+w0s*wsc(3),y+h0s*hsc(9),sstr,'fontunits','norm','horiz','c','vert','m')];
   hh=[hh text(x+w0s*wsc(1),y+h0s*hsc(5)-dl,sstr,'fontunits','norm','horiz','c','vert','m','rot',180)];
   hh=[hh text(x+w0s*wsc(3),y+h0s*hsc(5)-dl,sstr,'fontunits','norm','horiz','c','vert','m','rot',180)];
end
if val==10
   hh=[hh text(x+w0s*wsc(2),y+h0s*hsc(11),sstr,'fontunits','norm','horiz','c','vert','m')];
   hh=[hh text(x+w0s*wsc(2),y+h0s*hsc(3)-dl,sstr,'fontunits','norm','horiz','c','vert','m','rot',180)];   
end
if any(upper(val)==['J' 'Q' 'K'])
   hh(1)=text(x+w0s*wsc(1),y+h0s*hsc(13),sstr,'fontunits','norm','horiz','c','vert','m');
   hh(2)=text(x+w0s*wsc(3),y+h0s*hsc(1),sstr,'fontunits','norm','horiz','c','vert','m');
end
switch(upper(val))
case {11,'J'}
   h=[h text(x+w0s*wsc(2),y+h0s*hsc(6),'J','fontunits','norm','fontsize',6/h0*siz/diff(ax(3:4)),'horiz','c','vert','m','color',col)];
case {12,'Q'}
   h=[h text(x+w0s*wsc(2),y+h0s*hsc(6),'Q','fontunits','norm','fontsize',6/h0*siz/diff(ax(3:4)),'horiz','c','vert','m','color',col)];
case {13,'K'}   
   h=[h text(x+w0s*wsc(2),y+h0s*hsc(6),'K','fontunits','norm','fontsize',6/h0*siz/diff(ax(3:4)),'horiz','c','vert','m','color',col)];
end
if ~any(upper(val)==[1:13 'J' 'Q' 'K' 'A'])
   h=[h patch(xx,yy,[.8 .8 .8])];
   hh(1)=text(x+w0s/2,y+h0s/2,'','fontunits','norm','horiz','c','vert','m');
end
for i=1:length(hh)
   set(hh(i),'fontsize',fsiz,'color',col)
end
h=[h hh];
h(end+1:19)=text(x,y,'');
if nargout, H=h;end

if nargout, x1=x+w0s;end
y1=y+h0s;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function h=plotvalue(x,y,h0,w1s,h1s,dl,siz,str,col)
ax=axis;
fsiz=1/h0*siz/diff(ax(3:4));
h(1)=text(x+1.7*dl,y+dl+h1s,str,'fontunits','norm','fontsize',fsiz,'fontweight','norm','horiz','c','vert','t','color',col);
h(2)=text(x+0.3*dl+w1s,y+dl+h1s,str,'fontunits','norm','fontsize',fsiz,'fontweight','norm','horiz','c','vert','t','color',col);
h(3)=text(x+1.7*dl,y+dl,str,'fontunits','norm','fontsize',fsiz,'fontweight','norm','horiz','c','vert','t','rot',180,'color',col);
h(4)=text(x+0.3*dl+w1s,y+dl,str,'fontunits','norm','fontsize',fsiz,'fontweight','norm','horiz','c','vert','t','rot',180,'color',col);


function h=plotsuit(x,y,h0,w1s,h1s,dl,siz,str,col)
ax=axis;
fsiz=1/h0*siz/diff(ax(3:4));
offs=0.8*fsiz*diff(ax(3:4));
h(1)=text(x+1.7*dl,y+dl+h1s-offs,str,'fontunits','norm','fontsize',fsiz,'horiz','c','vert','t','color',col);
h(2)=text(x+0.3*dl+w1s,y+dl+h1s-offs,str,'fontunits','norm','fontsize',fsiz,'horiz','c','vert','t','color',col);
h(3)=text(x+1.7*dl,y+dl+offs,str,'fontunits','norm','fontsize',fsiz,'horiz','c','vert','t','rot',180,'color',col);
h(4)=text(x+0.3*dl+w1s,y+dl+offs,str,'fontunits','norm','fontsize',fsiz,'horiz','c','vert','t','rot',180,'color',col);

% End of cardplot function

function adum = toot()
% Whistle Generator Program
t = 0 : 1/2000 : 0.3;
sig = 0.7 * chirp(t,0,0.3,10000);
sound(sig,2000,8)

function adum2 = toot2()
% Whistle Generator Program
t = 0 : 1/2000 : 1;
sig = 0.7 * chirp(t,0,0.3,10000);
sound(sig,2000,8)

Contact us