当前位置: 首页 > news >正文

用MATLAB画一只可爱的小熊

本文介绍了一个使用MATLAB绘制可爱小熊的代码实现。

通过定义身体各部分的参数(如头部半径、耳朵位置、四肢尺寸等),利用rectangle函数绘制圆形和圆角矩形,组合成完整的小熊形象。代码设置了不同颜色区分身体(深灰)、脸部(浅灰)、眼睛(黑)和鼻子(棕),并添加微笑曲线作为嘴巴。程序包含缩放比例调整功能,可整体改变小熊大小。最终生成一个600×600像素的白色背景图形,隐藏坐标轴,呈现出一个比例协调的卡通小熊形象。

可爱的小熊

%% MATLAB绘制可爱小熊% 清理工作区
clear; clc; close all;% --- 1. 定义小熊身体各部分的参数 ---
% 这些参数可以调整,以改变小熊的大小和比例
body_scale = 1; % 整体缩放比例% 头部
head_center = [0, 5]; % 头部中心坐标
head_radius = 2.5 * body_scale; % 头部半径% 耳朵
ear_radius = 0.8 * body_scale; % 耳朵半径
ear_offset_x = 1.8 * body_scale; % 耳朵在x方向上的偏移
ear_offset_y = 1.8 * body_scale; % 耳朵在y方向上的偏移% 眼睛
eye_radius = 0.3 * body_scale; % 眼睛半径
eye_offset_x = 1.0 * body_scale; % 眼睛在x方向上的偏移
eye_offset_y = 0.5 * body_scale; % 眼睛在y方向上的偏移% 鼻子
nose_width = 0.6 * body_scale; % 鼻子宽度
nose_height = 0.4 * body_scale; % 鼻子高度% 嘴巴
mouth_width = 1.2 * body_scale; % 嘴巴宽度
mouth_height = 0.5 * body_scale; % 嘴巴高度% 身体
body_width = 3.5 * body_scale; % 身体宽度
body_height = 3.0 * body_scale; % 身体高度% 四肢
limb_width = 0.6 * body_scale; % 四肢宽度
limb_height = 2.0 * body_scale; % 四肢长度% --- 2. 绘制小熊 ---
figure('Color', 'w', 'Position', [100, 100, 600, 600]);
hold on;
axis equal;
axis off; % 隐藏坐标轴% 定义颜色
bear_color = [0.3, 0.3, 0.3]; % 小熊身体颜色 (深灰色)
face_color = [0.9, 0.9, 0.9]; % 小熊脸部颜色 (浅灰色)
eye_color = [0, 0, 0];        % 眼睛颜色 (黑色)
nose_color = [0.7, 0.2, 0.2]; % 鼻子颜色 (棕色)% --- 开始绘制 ---% 绘制身体 (使用rectangle函数绘制圆角矩形)
rectangle('Position', [-body_width/2, 0, body_width, body_height], ...'Curvature', [0.5, 0.5], 'FaceColor', bear_color, 'EdgeColor', 'none');% 绘制头部 (使用rectangle函数绘制一个圆形)
rectangle('Position', [head_center(1)-head_radius, head_center(2)-head_radius, ...2*head_radius, 2*head_radius], ...'Curvature', [1, 1], 'FaceColor', bear_color, 'EdgeColor', 'none');% 绘制脸部 (一个稍小的圆形)
rectangle('Position', [head_center(1)-head_radius+0.5, head_center(2)-head_radius+0.5, ...2*head_radius-1, 2*head_radius-1], ...'Curvature', [1, 1], 'FaceColor', face_color, 'EdgeColor', 'none');% 绘制耳朵
% 左耳
rectangle('Position', [head_center(1)-ear_offset_x-ear_radius, head_center(2)+ear_offset_y-ear_radius, ...2*ear_radius, 2*ear_radius], ...'Curvature', [1, 1], 'FaceColor', bear_color, 'EdgeColor', 'none');
% 右耳
rectangle('Position', [head_center(1)+ear_offset_x-ear_radius, head_center(2)+ear_offset_y-ear_radius, ...2*ear_radius, 2*ear_radius], ...'Curvature', [1, 1], 'FaceColor', bear_color, 'EdgeColor', 'none');% 绘制眼睛
% 左眼
rectangle('Position', [head_center(1)-eye_offset_x-eye_radius, head_center(2)+eye_offset_y-eye_radius, ...2*eye_radius, 2*eye_radius], ...'Curvature', [1, 1], 'FaceColor', eye_color, 'EdgeColor', 'none');
% 右眼
rectangle('Position', [head_center(1)+eye_offset_x-eye_radius, head_center(2)+eye_offset_y-eye_radius, ...2*eye_radius, 2*eye_radius], ...'Curvature', [1, 1], 'FaceColor', eye_color, 'EdgeColor', 'none');% 绘制鼻子 (一个椭圆形)
rectangle('Position', [-nose_width/2, head_center(2)-nose_height/2, nose_width, nose_height], ...'Curvature', [1, 1], 'FaceColor', nose_color, 'EdgeColor', 'none');% 绘制嘴巴 (一个微笑的弧线)
theta = linspace(pi, 2*pi, 100); % 角度从180度到360度
mouth_x = (mouth_width/2) * cos(theta);
mouth_y = -0.2 + (mouth_height/2) * sin(theta); % -0.2是为了让嘴巴位置下移一点
plot(mouth_x, mouth_y, 'k', 'LineWidth', 2);% 绘制四肢
% 左手臂
rectangle('Position', [-body_width/2-limb_width, body_height/2, limb_width, limb_height], ...'Curvature', [0.3, 0.3], 'FaceColor', bear_color, 'EdgeColor', 'none');
% 右手臂
rectangle('Position', [body_width/2, body_height/2, limb_width, limb_height], ...'Curvature', [0.3, 0.3], 'FaceColor', bear_color, 'EdgeColor', 'none');
% 左腿部
rectangle('Position', [-body_width/4-limb_width/2, -limb_height, limb_width, limb_height], ...'Curvature', [0.3, 0.3], 'FaceColor', bear_color, 'EdgeColor', 'none');
% 右腿部
rectangle('Position', [body_width/4-limb_width/2, -limb_height, limb_width, limb_height], ...'Curvature', [0.3, 0.3], 'FaceColor', bear_color, 'EdgeColor', 'none');% 添加标题
title('MATLAB 小熊', 'FontSize', 16, 'FontWeight', 'bold');hold off;

http://www.dtcms.com/a/406471.html

相关文章:

  • Matlab通过GUI实现点云的半径滤波(Radius Outlier Removal)
  • 基于MATLAB的8QAM调制解调仿真与BER性能分析
  • 2025年AI证书报考指南:CAIP/华为/谷歌认证
  • 合肥营销型网站建设开发河南城源建设工程有限公司网站
  • 若依 springboot websocket
  • 开源 C# 快速开发(三)复杂控件
  • Visual Studio使用C++配置OpenCV环境,同时添加模板以4.12为例
  • JUnit 4 + Spring Boot 测试依赖
  • HTML应用指南:利用POST请求获取全国索尼体验型零售店位置信息
  • html网站源码 html网页模板下载
  • 做网站接广告了解基本的php wordpress
  • 房地产手机网站模板网站推广公司ihanshi
  • 推荐一个网站
  • 前端可视化第一章:PixiJS入门指南
  • 时间序列分析新视角:单变量预训练 多变量微调
  • coqui-ai/TTS 安装
  • linux命令dd单刷镜像文件
  • 奔驰押注中国AI,国产大模型上车
  • 笔记(C++篇)—— Day 11
  • Cursor推出全新文档中心:甚至提供详细的中文版本
  • 选择合肥网站建设html的基本结构
  • Linux文件系统调用详解:底层操作到高级应用
  • 基于51单片机的供电保护系统
  • 网站建设技术交流制作公司网页价钱
  • 前端Bug实录:为什么表格筛选条件在刷新时神秘消失?
  • 关于做视频网站的一些代码网站备案号是什么样子
  • 专业定制网站开发上海手机网站建设价格
  • 《postman》软件下载_《postman》安装包下载_《postman》安装教程下载_《postman》网盘下载
  • 双模更超模!飞利浦双模办公娱乐显示器27E2N5900RW优雅登场!
  • TDengine 聚合函数 HYPERLOGLOG 用户手册