给我一个用matlab绘制小猫的代码
时间: 2024-05-13 15:18:04 浏览: 188
以下是一个简单的用 MATLAB 绘制小猫的代码:
```matlab
% 清空画图窗口
clf;
% 设置画笔颜色和线宽
lineWidth = 2;
faceColor = 'b';
edgeColor = 'k';
% 绘制猫头
headRadius = 1;
headCenter = [0, 0];
head = viscircles(headCenter, headRadius, 'LineWidth', lineWidth, ...
'FaceColor', faceColor, 'EdgeColor', edgeColor);
% 绘制猫耳朵
earRadius = 0.5;
earCenter1 = [-0.8, 0.8];
earCenter2 = [0.8, 0.8];
ear1 = viscircles(earCenter1, earRadius, 'LineWidth', lineWidth, ...
'FaceColor', faceColor, 'EdgeColor', edgeColor);
ear2 = viscircles(earCenter2, earRadius, 'LineWidth', lineWidth, ...
'FaceColor', faceColor, 'EdgeColor', edgeColor);
% 绘制猫眼睛
eyeRadius = 0.2;
eyeCenter1 = [-0.4, 0.2];
eyeCenter2 = [0.4, 0.2];
eye1 = viscircles(eyeCenter1, eyeRadius, 'LineWidth', lineWidth, ...
'FaceColor', 'w', 'EdgeColor', edgeColor);
eye2 = viscircles(eyeCenter2, eyeRadius, 'LineWidth', lineWidth, ...
'FaceColor', 'w', 'EdgeColor', edgeColor);
% 绘制猫嘴巴
mouthRadius = 0.4;
mouthCenter = [0, -0.4];
mouth = viscircles(mouthCenter, mouthRadius, 'LineWidth', lineWidth, ...
'FaceColor', 'w', 'EdgeColor', edgeColor);
% 绘制猫身体
bodyWidth = 2;
bodyHeight = 2;
bodyCenter = [0, -3];
body = rectangle('Position', [bodyCenter(1)-bodyWidth/2, bodyCenter(2)-bodyHeight/2, bodyWidth, bodyHeight], ...
'LineWidth', lineWidth, 'Curvature', [1, 1], 'FaceColor', faceColor, 'EdgeColor', edgeColor);
% 绘制猫尾巴
tailWidth = 0.2;
tailHeight = 1.5;
tailCenter = [0, -3-tailHeight/2];
tail = rectangle('Position', [tailCenter(1)-tailWidth/2, tailCenter(2)-tailHeight/2, tailWidth, tailHeight], ...
'LineWidth', lineWidth, 'Curvature', [1, 1], 'FaceColor', faceColor, 'EdgeColor', edgeColor);
% 设置坐标轴范围和比例
axis([-2.5, 2.5, -5, 1]);
axis equal;
```
运行上述代码,会在画图窗口中显示出一只小猫的图像。你也可以根据需要自行修改参数来调整小猫的各个部分形状和位置。
阅读全文