使用matlab实现类似windows系统中的画图小软件,带GUI界面

简介: 使用matlab实现类似windows系统中的画图小软件,带GUI界面

1.仿真效果预览
matlab2022a仿真结果如下:

image.png

2.MATLAB核心程序

function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global flg mark rgb x0 y0 x y rect graph h;
if flg
    switch(graph)
        case '点线'
            currPt=get(gca, 'CurrentPoint');
            x=currPt(1,1);
            y=currPt(1,2);
            line(x,y, 'marker', mark,'color',rgb);
        case '线形'
            x0=x;y0=y;
            currPt=get(gca, 'CurrentPoint');
            x=currPt(1,1);
            y=currPt(1,2);
            line([x0 x], [y0,y],'LineStyle',mark,'color',rgb);
        case '矩形'
            currPt=get(gca, 'CurrentPoint');
            x=currPt(1,1);
            y=currPt(1,2);
            if x~=x0
                if ~isempty(h)
                    set(h,'Visible','off')
                end
                rect=[min([x0,x]),min([y0,y]),abs(x-x0),abs(y-y0)];
                if rect(3)*rect(4)~=0
                    h=rectangle('Position',rect,'LineStyle',':');
                end
            end
        case '椭圆'
            currPt=get(gca, 'CurrentPoint');
            x=currPt(1,1);
            y=currPt(1,2);
            if x~=x0
                if ~isempty(h)
                    set(h,'Visible','off')
                end
                rect=[min([x0,x]),min([y0,y]),abs(x-x0),abs(y-y0)];
                if rect(3)*rect(4)~=0
                    h=rectangle('Position',rect,'Curvature',[1,1],'LineStyle',':');
                end
            end
    end
    set(handles.edit1,'string',num2str(x));
    set(handles.edit2,'string',num2str(y));
    set(handles.text3,'string','Mouse is moving!');
end
 
function figure1_WindowButtonUpFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global flg rgb mark h graph rect;
flg=0;
switch(graph)
    case '矩形'
        set(h,'Visible','off');h=[];
        if rect(3)*rect(4)~=0
            rectangle('Position',rect,'edgecolor',rgb,'LineStyle',mark)
        end
    case '椭圆'
        set(h,'Visible','off');h=[];
        if rect(3)*rect(4)~=0
            rectangle('Position',rect,'Curvature',[1,1],'edgecolor',rgb,'LineStyle',mark)
        end
end
set(handles.text3,'string','Mouse up!');
function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 
% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double
 
 
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
 
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
相关文章
|
5月前
|
供应链 算法 新能源
高比例可再生能源电力系统的调峰成本量化与分摊模型(Matlab代码实现)
高比例可再生能源电力系统的调峰成本量化与分摊模型(Matlab代码实现)
135 4
|
5月前
|
数据采集 算法 安全
多接地配电系统的基于PMU的系统状态估计(Matlab代码实现)
多接地配电系统的基于PMU的系统状态估计(Matlab代码实现)
172 0
|
4月前
|
Java 测试技术 网络安全
Burp Suite Professional 2025.10 for Windows x64 - 领先的 Web 渗透测试软件
Burp Suite Professional 2025.10 for Windows x64 - 领先的 Web 渗透测试软件
180 0
Burp Suite Professional 2025.10 for Windows x64 - 领先的 Web 渗透测试软件
|
5月前
|
NoSQL IDE MongoDB
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
361 1
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
5月前
|
机器学习/深度学习 传感器 算法
【无人车路径跟踪】基于神经网络的数据驱动迭代学习控制(ILC)算法,用于具有未知模型和重复任务的非线性单输入单输出(SISO)离散时间系统的无人车的路径跟踪(Matlab代码实现)
【无人车路径跟踪】基于神经网络的数据驱动迭代学习控制(ILC)算法,用于具有未知模型和重复任务的非线性单输入单输出(SISO)离散时间系统的无人车的路径跟踪(Matlab代码实现)
353 2
|
5月前
|
监控
基于MATLAB/Simulink的单机带负荷仿真系统搭建
使用MATLAB/Simulink平台搭建一个单机带负荷的电力系统仿真模型。该系统包括同步发电机、励磁系统、调速系统、变压器、输电线路以及不同类型的负荷模型。
809 5
|
4月前
|
传感器 机器学习/深度学习 算法
【无人机协同】动态环境下多无人机系统的协同路径规划与防撞研究(Matlab代码实现)
【无人机协同】动态环境下多无人机系统的协同路径规划与防撞研究(Matlab代码实现)
293 0
|
5月前
|
机器学习/深度学习 算法 新能源
【无功优化】“碳中和”目标下电气互联系统有功-无功协同优化模型(Matlab代码实现)
【无功优化】“碳中和”目标下电气互联系统有功-无功协同优化模型(Matlab代码实现)
118 5
|
5月前
|
算法
【电力系统潮流】5节点系统潮流计算-牛拉法和PQ分解法(Matlab代代码实现)
【电力系统潮流】5节点系统潮流计算-牛拉法和PQ分解法(Matlab代代码实现)
530 3

热门文章

最新文章