draw a cat a dog and a house in matlab

To draw a cat, a dog, and a house in MATLAB, we can use the built-in functions to draw different shapes and add them together to create our images. Here is some sample code to draw a simple version of each:

main.m
% Draw a cat
clf
t = linspace(0, 2*pi, 100);
x = sin(t);
y = cos(t);
head = fill(x*0.5, y*0.5+1, 'k');
ear1 = fill(x*0.1-0.6, y*0.1+1.4, 'k');
ear2 = fill(x*0.1+0.6, y*0.1+1.4, 'k');
nose = fill(x*0.2, y*0.1+0.8, 'k');
eye1 = fill(x*0.1-0.3, y*0.1+1.2, 'w');
eye2 = fill(x*0.1+0.3, y*0.1+1.2, 'w');

% Draw a dog
clf
t = linspace(0, 2*pi, 100);
x = sin(t);
y = cos(t);
face = fill(x*0.6, y*0.6+0.8, 'w');
eye1 = fill(x*0.1-0.3, y*0.1+1, 'k');
eye2 = fill(x*0.1+0.3, y*0.1+1, 'k');
nose = fill(x*0.15, y*0.1+0.6, 'k');
leg1 = fill(x*0.1-0.5, y*0.5-1, 'w');
leg2 = fill(x*0.1+0.5, y*0.5-1, 'w');

% Draw a house
clf
face = fill([-1,-1,1,1],[-1,1,1,-1],'g');
roof = fill([-1,0,1],[-1,-1/2,-1],'r');
door = fill([-.25,-.25,.25,.25],[-1,0,0,-1],'m');
window1 = fill([-0.8,-0.8,-0.6,-0.6],[-0.2,-0.6,-0.6,-0.2],'w');
window2 = fill([0.6,0.6,0.8,0.8],[-0.2,-0.6,-0.6,-0.2],'w');
872 chars
32 lines

In this code, we create a figure for each image using the clf function, which clears any previous content from the figure. We use the fill function to create different shapes, such as circles, rectangles, and polygons, and specify their color using strings like 'k' for black, 'w' for white, 'g' for green, etc. We can adjust the position, size, and orientation of each shape using simple math operations on the x and y vectors, which specify the coordinates of their vertices.

Note that this is just a simple example, and you can customize your images further by adding more shapes, changing their colors, sizes, and positions, and using additional functions like line, text, and image to create more complex graphics.

gistlibby LogSnag