1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| function anim
figure('doublebuffer','on','keypressfcn',@kpfcn)
colormap(cool)
axes('xlim',[-50 50],'ylim',[-50 50])
fv.vertices=[-5 -5 ; 5 -5 ; 0 5];
fv.faces=1:3;
fv.facecolor='interp';
fv.facevertexcdata=rand(3,1);
fv.tag='triangle';
patch(fv);
function kpfcn(obj,event)
h=findobj('type','patch','tag','triangle');
xy=get(h,{'xdata','ydata'});
switch get(obj,'currentcharacter')
case 28 % Gauche
xy{1}=xy{1}-1;
case 29 % Droite
xy{1}=xy{1}+1;
case 30 % Haut
xy{2}=xy{2}+1;
case 31 % Bas
xy{2}=xy{2}-1;
case 27 % Esc
xy{1}=[-5 ; 5 ; 0 ];
xy{2}=[-5 ; -5 ; 5];
end
set(h,{'xdata','ydata'},xy) |
Partager