- /
-
Snowman
on 2 Dec 2023
- 14
- 109
- 0
- 2
- 1085
drawframe(1);
Write your drawframe function below
function drawframe(f)
cla
tiledlayout(1,1,"Padding","none")
nexttile
[x,y,z]=sphere(50);
s=@(x,y,z,c) surf(x,y,z,'FaceColor',c,'EdgeColor','none','FaceLighting','gouraud');
% body
s(x,y,z,'w')
hold on
s(x/1.5,y/1.5,z/1.5+1.5,'w')
s(x/3-1,y/3,z/3+0.5,'w')
s(x/3+1,y/3,z/3+0.5,'w')
% face
s(x/8-0.3,y/8-0.5,z/8+1.7,'k')
s(x/8+0.3,y/8-0.5,z/8+1.7,'k')
s(x/10,y/10-0.7,z/10+1.5,'r')
s(x/7,y/10-0.5,z/10+1.2,'r')
% button
d=[.64 .08 .18];
s(x/10,y/10-0.8,z/10+0.5,d)
s(x/10,y/10-0.9,z/10+0.2,d)
s(x/10,y/10-0.92,z/10-0.1,d)
% scarf
r = 0.7;
[x2,y2,z2] = cylinder(r);
s(x2,y2,z2,d)
for i=1:100
plot3([-1 -1],[1 2],[0.8 0.8+(i-50)*0.015],'-','linewidth',2,'color',d)
hold on
end
% hat
t = 0:pi/10:pi/2;
r2 = 0.6*exp(t).*cos(t).^2;
[x3,y3,z3] = cylinder(r2);
s(x3,y3,z3+1.9,d)
% skirt
r3 = 1.1*cos(t);
[x3,y3,z3] = cylinder(r3);
s(x3,y3,z3-1,d)
% snow
rng(1)
n=4*(rand(500,3)-0.5);
plot3(n(:,1),n(:,2),n(:,3)*2-f/24,'wp','markersize',2,'markerfacecolor','w')
% broom
s(x2/10-1,2*z2-1,y2/10+0.8,'k')
for i=1:100
plot3([-1 -1],[1 2],[0.8 0.8+(i-50)*0.015],'-','linewidth',2,'color',d)
hold on
end
daspect([5 5 1])
light
lightangle(-45,30)
view(-f,5)
axis equal tight off
xlim([-2 2])
ylim([-2 2])
zlim([-1 3])
g=gcf;
g.Color=[.09 .09 .71];
end