% JOYEUX LURON

%Tête = sphère
R=1;
a=0;
b=2*pi;
c=-pi/2;
d=pi/2;
[t,u] = meshgrid(a:(b-a)/50:b,c:(d-c)/50:d);
xs=cos(t).*cos(u);
ys=sin(t).*cos(u);
zs=sin(u);
tete=surfl(10*xs,10*ys,10*zs);


% +les yeux
hold on
oeilg=surfl(2*xs-3,2*ys+7,2*zs+7);
oeild=surfl(2*xs+3,2*ys+7,2*zs+7);


%+le cou
R = 1.5;
L = 3;
a = -R;
b = R;
c = -L;
d = L;

[xs,ys] = meshgrid(a:(b-a)/50:b,c:(d-c)/50:d);

zs = sqrt(R.^2-xs.^2);

cou = surfl(zs,xs-.1,ys-13);
cou = surfl(-zs,xs-.1,ys-13);

%+ la bouche (=Bouée)
R=2;
r=0.6;

a=0;
b=2*pi;
c=0;
d=2*pi;

[t,u] = meshgrid(a:(b-a)/50:b,c:(d-c)/50:d);

xb=(R+r.*cos(u)).*cos(t);
yb=(R+r.*cos(u)).*sin(t);
zb=r*sin(u);

bouche = surfl(1.9*yb,zb+10,xb-3);

%+ les oreilles droite(=1/2Bouée)
R=2.5;
r=0.8;
a=-pi;
b=pi;
c=0;
d=2*pi;

[t,u] = meshgrid(a:(b-a)/50:b,c:(d-c)/50:d);

xb=(R+r.*cos(u)).*cos(t);
yb=(R+r.*cos(u)).*sin(t);
zb=r*sin(u);

oreilled = surfl(yb+9,zb,-xb+3.5);

%+ oreille gauche(=1/2Bouée)
R=2.5;
r=0.8;
a=0;
b=-2*pi;
c=0;
d=2*pi;

[t,u] = meshgrid(a:(b-a)/50:b,c:(d-c)/50:d);

xb=(R+r.*cos(u)).*cos(t);
yb=(R+r.*cos(u)).*sin(t);
zb=r*sin(u);

oreilleg = surfl(yb-9,zb,-xb+3.5);

%+ le chapeau(=cône)

R=5;
a=0;
b=R;
c=0;
d=2*pi;

[R,t] = meshgrid(a:(b-a)/10:b,c:(d-c)/50:d);
xc=R.*cos(t);
yc=R.*sin(t);
zc=-R;
chapeau = surfl(xc,yc,3*zc+20);

shading interp
axis image


ctete=get(tete,'Cdata');
coeilg=get(oeilg,'Cdata');
coeild=get(oeild,'Cdata');
cchapeau=get(chapeau,'CData');
cbouche=get(bouche,'CData');
c=(0:63)./63;
nul=zeros(1,64);
perso=[c nul nul; nul c nul;nul nul c]';
colormap autumn
corange = colormap;
colormap gray
cgris = colormap;
perso = [perso;corange;cgris];
set(tete,'CData',ctete+0);
set(oeilg,'CData',coeilg+1);
set(oeild,'CData',coeild+1);
set(chapeau,'CData',cchapeau+4);
set(bouche,'CData',cbouche+3);

colormap(perso)
caxis([0 5])
axis off
for az = 0:10:360
    view(az+180,30)
    zoom(1.0111)
    drawnow
end

%bouche = surfl(1.9*yb,zb+10,xb-3)

xbouche = get(bouche,'XData');
for t = 0:pi/10:pi
    coeff = sin(t)+1;
    set(bouche,'XData',coeff*xbouche);
    drawnow
end