Thursday, November 10, 2011

Polar Bear

This is cool (found here):

function polarbear
% plots a polar bear in Matlab

function ec(h,k,a,b,ang)
% (h,k) is the center of the ellipse or circle
xp=a*cos(ang);
yp=b*sin(ang);
plot(h+xp,k+yp,'LineWidth',3,'Color','blue');hold on
end

% First plot curves that use theta between 0 and 2pi
ang=0:0.01:2*pi;
ec(5,0,2,2,ang),ec(-5,0,2,2,ang) % plot the feet
ec(2,0,1,1,ang),ec(-2,0,1,1,ang) % plot the hands
ec(0,9,4,3,ang) % plot the head
ec(1,10,0.25,0.25,ang),ec(-1,10,0.25,0.25,ang) % plot the eyes
ec(0,8,1,0.5,ang) % plot the nose

% Plot remaining curves for specific theta
ang=0:0.01:pi/2+3*pi/180; ec(5,0,2,5,ang) % plot the right legs
ang=pi/2-3*pi/180:0.01:pi; ec(-5,0,2,5,ang) % plot the left legs
ang1=pi:0.01:240*pi/180; ang2=-60*pi/180:0.01:0; ec(0,4,3,3.60,ang1),ec(0,4,3,3.60,ang2) % plot the arms
ang1=-24*pi/180:0.01:45*pi/180; ang2=pi-45*pi/180:0.01:pi+24*pi/180; ang3=254*pi/180:0.01:286*pi/180; ec(0,4,5,5,ang1),ec(0,4,5,5,ang2),ec(0,4,5,5,ang3) % plot the body
ang=0:0.01:155*pi/180; ec(2,11,1,2,ang) % plot the right inside ear
ang=26*pi/180:0.01:pi; ec(-2,11,1,2,ang) % plot the left inside ear
ang=-5*pi/180:0.01:156*pi/180; ec(2,11,1.25,2.25,ang) % plot the right outside ear
ang=25*pi/180:0.01:185*pi/180; ec(-2,11,1.25,2.25,ang) % plot the left outside ear
ang=pi/4:0.01:pi/2; ec(1,10,1,1,ang) % plot the right eyebrow
ang=pi/2:0.01:135*pi/180; ec(-1,10,1,1,ang) % plot the left eyebrow
ang=119*pi/180:0.01:2*pi+61*pi/180; ec(0,7,2,1,ang) % plot the mouth
ang=200*pi/180:0.01:320*pi/180; ec(0.75,8,0.75,1.5,ang) % plot the right smile
ang=220*pi/180:0.01:340*pi/180; ec(-0.75,8,0.75,1.5,ang) % plot the left smile
end

No comments: