plot a smily in matlab

To plot a smily face in Matlab, we can use the plot function to plot circles and lines. Here's a code snippet:

main.m
% define x and y coordinates for different parts of the smily face
x1 = linspace(-1, 1, 100); % left and right edges of the face
x2 = linspace(-0.5, 0.5, 100); % top and bottom edges of the face
x3 = linspace(-0.5, 0.5, 100); % mouth
y1 = sqrt(1 - x1.^2);
y2 = sqrt(0.25 - x2.^2) - 0.75;
y3 = -0.25*sin(2*pi*x3);

% plot the smily face
figure;
hold on;
plot(x1, y1, 'k', 'LineWidth', 3); % face outline
plot(x2, y2, 'k', 'LineWidth', 3); % face outline
plot(x3, y3, 'k', 'LineWidth', 3); % mouth
plot([-0.5 -0.15], [0.25 0.25], 'k', 'LineWidth', 3); % left eye
plot([0.15 0.5], [0.25 0.25], 'k', 'LineWidth', 3); % right eye
hold off;
axis equal;
axis([-1 1 -1 1]);
666 chars
20 lines

This code will create a black smily face with a circle for the face and a curved line for the mouth, and two circles for the eyes. The result should look like this:

smily_face

related categories

gistlibby LogSnag