突然发现cla函数也可以应用到app designer控件上,因而对部分内容做出更改。


手痒,用matlab app designer复刻了一款举牌加油小人生成器,效果如下:


该程序可以生成正方形和长方形举牌小人,并且可以自己设置背景颜色(点击那些有颜色的小框框),点击绿色旋转按钮可以刷新生成的图片。


目前需要存图还是需要通过uiaxes自带的toolbar(下图右上角所示):

使用该程序需要小人的素材包,我已经将素材整理为materials.mat文件,网盘下载链接如下:
链接:https://pan.baidu.com/s/1rjmX0qxmF_0VYQYZYsnH-A
提取码:0veb
使用时需要把materials.mat和m文件放在同一文件夹

完整代码

function upup
global textMsg bkgColor colorList axesType
global textArea
textMsg=[];
axesType=2;
bkgColor=[1,1,1];
colorList=[0.9000         0    0.07000.9200    0.3300    0.08000.9600    0.6200    0.75000.9600    0.9400    0.55000.7600    0.8400    0.25000.3800    0.7600    0.73000.4700    0.8100    0.94000.6000    0.0500    0.49001         1         1     ];%load pic and create pic ==================================================
materials=load('materials.mat');
if ~exist('materials','dir')mkdir('materials');
end
for i=1:size(colorList,1)Rc=zeros(60,60);Rc(11:50,11:50)=255.*colorList(i,1);Gc=zeros(60,60);Gc(11:50,11:50)=255.*colorList(i,2);Bc=zeros(60,60);Bc(11:50,11:50)=255.*colorList(i,3);cPic(:,:,1)=Rc;cPic(:,:,2)=Gc;cPic(:,:,3)=Bc;imwrite(uint8(cPic),['materials\bkg',num2str(i),'.png'])
end
imwrite(materials.imgSet.cover,'materials\cover.jpg')
imwrite(materials.imgSet.square,'materials\square.jpg')
imwrite(materials.imgSet.refresh.CData,'materials\refresh.png','Alpha',materials.imgSet.refresh.AData)%==========================================================================
upFig=uifigure('units','pixels',...'position',[320 50 400 600],...'Numbertitle','off',...'menubar','none',...'resize','off',...'name','upup',...'color',[0.93 0.6 0]);%==========================================================================
textAreaLabel=uilabel(upFig);
textAreaLabel.Position=[55 445 290 100];
textAreaLabel.Text='';
textAreaLabel.BackgroundColor=[0,0,0];
textArea=uitextarea(upFig,'ValueChangedFcn',@changeText);
textArea.Position=[60 450 280 90];
textArea.FontSize=23;%text label hdl part=======================================================
textLabel_1=uilabel(upFig);
textLabel_1.Position=[52 517 296 106];
textLabel_1.Text='YOUR MESSAGE HERE';
textLabel_1.FontSize=24;
textLabel_1.FontWeight='bold';
textLabel_1.HorizontalAlignment='center';textLabel_2=uilabel(upFig);
textLabel_2.Position=[52 367 296 106];
textLabel_2.Text='BACKGROUND COLORS';
textLabel_2.FontSize=24;
textLabel_2.FontWeight='bold';
textLabel_2.HorizontalAlignment='center';textLabel_3=uilabel(upFig);
textLabel_3.Position=[10 310 60 50];
textLabel_3.Text='SIZE';
textLabel_3.FontSize=20;
textLabel_3.FontWeight='bold';
textLabel_3.HorizontalAlignment='center';%bkg color hdl part========================================================
for i=1:size(colorList,1)CL(i)=uiimage(upFig);CL(i).Position=[10+i*35,365,30,30];CL(i).UserData=i;CL(i).ImageSource=['materials\bkg',num2str(i),'.png'];
end
set(CL,'ImageClickedFcn',@bkgChange)%reset Size hdl part=======================================================
sizeBtn(1)=uiimage(upFig);
sizeBtn(1).Position=[70 320 168 30];
sizeBtn(1).UserData=1;
sizeBtn(1).ImageSource='materials\cover.jpg';sizeBtn(2)=uiimage(upFig);
sizeBtn(2).Position=[245 320 80 30];
sizeBtn(2).UserData=2;
sizeBtn(2).ImageSource='materials\square.jpg';
set(sizeBtn,'ImageClickedFcn',@sizeChange)%==========================================================================
refreshBtn=uiimage(upFig);
refreshBtn.Position=[340 317.5 35 35];
refreshBtn.ImageSource='materials\refresh.png';
set(refreshBtn,'ImageClickedFcn',@changeText)%==========================================================================
upAx=uiaxes('Units','pixels',...'parent',upFig,...'Position',[50 10 300 300],...'Color',[0.99 0.99 0.99],...'Box','on', ...'XTick',[],...'YTick',[],...'XLimMode','manual',...'YLimMode','manual',...'XLim',[0 300],...'YLim',[0 300], ...'BackgroundColor',[0,0,0],...'YDir','reverse');
hold(upAx,'on')%==========================================================================function bkgChange(~,event)objNum=event.Source.UserData;upAx.Color=colorList(objNum,:); endfunction sizeChange(~,event)axesType=event.Source.UserData;switch axesTypecase 1upAx.Position=[10 120 380 141];upAx.XLim=[0 380];upAx.YLim=[0 141];     case 2upAx.Position=[50 10 300 300];upAx.XLim=[0 300];upAx.YLim=[0 300];endendfunction changeText(~,~)cla(upAx)
%         hold(upAx,'off')
%         image(upAx,[-1,0],[-1,0],ones(1,1,3),'visible','off');
%         hold(upAx,'on')textMsg=textArea.Value;for ii=1:length(textMsg)tempStr=textMsg{ii};for jj=1:length(tempStr)if tempStr(jj)~=' 'roleType=randi(24);image(upAx,[0,103*0.4]+110+28*(jj-1)-27*(ii-1),...[0,198*0.4]+10+12*(jj-1)+22*(ii-1),...materials.imgSet.CData{roleType},...'AlphaData',materials.imgSet.AData{roleType},...'Interpolation','bilinear')text(upAx,21+110+28*(jj-1)-27*(ii-1),...10+10+12*(jj-1)+22*(ii-1),...tempStr(jj),'rotation',-38,'FontSize',16,...'FontWeight','bold','Color',[0.4,0.3,0.3],...'FontAngle','italic','HorizontalAlignment','center');endendendend
end

另:完整素材包+mat文件+m文件可以在下面下载
百度网盘链接:https://pan.baidu.com/s/1FpY94OsNoF3qfde57eBC2A
提取码:hjre

CSDN站内下载链接:
https://download.csdn.net/download/slandarer/19794995


注:代码和素材仅作学习用途,勿做他用

若matlab是版本为R2016a以后,R2019a之前,会因为uiimage未被推出而无法正常使用,可以尝试以下代码,该代码依旧需要materials.mat和m文件在同一文件夹:

function upupUiBtn
global textMsg bkgColor colorList axesType
global textArea
textMsg=[];
axesType=2;
bkgColor=[1,1,1];
colorList=[0.9000         0    0.07000.9200    0.3300    0.08000.9600    0.6200    0.75000.9600    0.9400    0.55000.7600    0.8400    0.25000.3800    0.7600    0.73000.4700    0.8100    0.94000.6000    0.0500    0.49001         1         1     ];
%load pic and create pic ==================================================
materials=load('materials.mat');
if ~exist('materials','dir')mkdir('materials');
end
for i=1:size(colorList,1)Rc=zeros(60,60);Rc(11:50,11:50)=255.*colorList(i,1);Gc=zeros(60,60);Gc(11:50,11:50)=255.*colorList(i,2);Bc=zeros(60,60);Bc(11:50,11:50)=255.*colorList(i,3);cPic(:,:,1)=Rc;cPic(:,:,2)=Gc;cPic(:,:,3)=Bc;imwrite(uint8(cPic),['materials\bkg',num2str(i),'.png'])
end
imwrite(materials.imgSet.cover,'materials\cover.jpg')
imwrite(materials.imgSet.square,'materials\square.jpg')
imwrite(materials.imgSet.refresh.CData,'materials\refresh.png','Alpha',materials.imgSet.refresh.AData)%==========================================================================
upFig=uifigure('units','pixels',...'position',[320 50 400 600],...'Numbertitle','off',...'menubar','none',...'resize','off',...'name','upup',...'color',[0.93 0.6 0]);%==========================================================================
textAreaLabel=uilabel(upFig);
textAreaLabel.Position=[55 445 290 100];
textAreaLabel.Text='';
textAreaLabel.BackgroundColor=[0,0,0];
textArea=uitextarea(upFig,'ValueChangedFcn',@changeText);
textArea.Position=[60 450 280 90];
textArea.FontSize=23;%text label hdl part=======================================================
textLabel_1=uilabel(upFig);
textLabel_1.Position=[52 517 296 106];
textLabel_1.Text='YOUR MESSAGE HERE';
textLabel_1.FontSize=24;
textLabel_1.FontWeight='bold';
textLabel_1.HorizontalAlignment='center';textLabel_2=uilabel(upFig);
textLabel_2.Position=[52 367 296 106];
textLabel_2.Text='BACKGROUND COLORS';
textLabel_2.FontSize=24;
textLabel_2.FontWeight='bold';
textLabel_2.HorizontalAlignment='center';textLabel_3=uilabel(upFig);
textLabel_3.Position=[10 310 60 50];
textLabel_3.Text='SIZE';
textLabel_3.FontSize=20;
textLabel_3.FontWeight='bold';
textLabel_3.HorizontalAlignment='center';%bkg color hdl part========================================================
for i=1:size(colorList,1)CL(i)=uibutton(upFig);CL(i).Position=[10+i*35,365,30,30];CL(i).BackgroundColor=[0 0 0];CL(i).Text='';CL(i).UserData=i;CL(i).Icon=['materials\bkg',num2str(i),'.png'];
end
set(CL,'ButtonPushedFcn',@bkgChange)%reset Size hdl part=======================================================
sizeBtn(1)=uibutton(upFig);
sizeBtn(1).Position=[80 320 145 32];
sizeBtn(1).UserData=1;
sizeBtn(1).Text='';
sizeBtn(1).BackgroundColor=[0 0 0];
sizeBtn(1).Icon='materials\cover.jpg';sizeBtn(2)=uibutton(upFig);
sizeBtn(2).Position=[235 320 78 32];
sizeBtn(2).UserData=2;
sizeBtn(2).Text='';
sizeBtn(2).BackgroundColor=[0 0 0];
sizeBtn(2).Icon='materials\square.jpg';
set(sizeBtn,'ButtonPushedFcn',@sizeChange)refreshBtn=uibutton(upFig);
refreshBtn.Position=[330 318 35 35];
refreshBtn.Text='';
refreshBtn.BackgroundColor=[0.93 0.6 0];
refreshBtn.Icon='materials\refresh.png';
set(refreshBtn,'ButtonPushedFcn',@changeText)
%==========================================================================
upAx=uiaxes('Units','pixels',...'parent',upFig,...'Position',[50 10 300 300],...'Color',[0.99 0.99 0.99],...'Box','on', ...'XTick',[],...'YTick',[],...'XLimMode','manual',...'YLimMode','manual',...'XLim',[0 300],...'YLim',[0 300], ...'BackgroundColor',[0,0,0],...'YDir','reverse');
hold(upAx,'on')%==========================================================================function bkgChange(~,event)objNum=event.Source.UserData;upAx.Color=colorList(objNum,:); endfunction sizeChange(~,event)axesType=event.Source.UserData;switch axesTypecase 1upAx.Position=[10 120 380 141];upAx.XLim=[0 380];upAx.YLim=[0 141];     case 2upAx.Position=[50 10 300 300];upAx.XLim=[0 300];upAx.YLim=[0 300];endendfunction changeText(~,~)cla(upAx)
%         hold(upAx,'off')
%         image(upAx,[-1,0],[-1,0],ones(1,1,3),'visible','off');
%         hold(upAx,'on')textMsg=textArea.Value;for ii=1:length(textMsg)tempStr=textMsg{ii};for jj=1:length(tempStr)if tempStr(jj)~=' 'roleType=randi(24);image(upAx,[0,103*0.4]+110+28*(jj-1)-27*(ii-1),...[0,198*0.4]+10+12*(jj-1)+22*(ii-1),...materials.imgSet.CData{roleType},...'AlphaData',materials.imgSet.AData{roleType},...'Interpolation','bilinear')text(upAx,21+110+28*(jj-1)-27*(ii-1),...10+10+12*(jj-1)+22*(ii-1),...tempStr(jj),'rotation',-38,'FontSize',16,...'FontWeight','bold','Color',[0.4,0.3,0.3],...'FontAngle','italic','HorizontalAlignment','center');endendendend
end

非uiimage版按钮长这样:

超火的举牌加油小人生成器MATLAB复刻版(app designer)相关推荐

  1. 我用 MATLAB 复刻了抖音爆火小游戏 苹果蛇

    最近抖音上苹果蛇小游戏大火,为了证明MATLAB无所不能,咋能不跟风做一个?于是就有了这一篇. 还是提一句这个小游戏开始玩的心路历程: 第1-5关:?这不就是有重力的贪吃蛇,有任何难度嘛?? 第6关: ...

  2. 【程序员趣味】用Python制作带字小人举牌

    一.安装selenium库 pip install selenium 结果如下: 1.chromedriver驱动的配置 如果你想要驱动谷歌浏览器,自动打开浏览器,必须匹配chromedriver驱动 ...

  3. 趣味实践 利用Python定制可爱的举牌小人

    温一壶风尘的酒,独饮往事昭昭. 一.前言 有一些网站可以在线生成举牌小人,看起来很可爱,也比较有趣.生成的图片用来做素材是个不错的选择! upuptoyou是一款非常有创意的小工具,可以用于表白,或节 ...

  4. 用 Python 定制可爱的举牌小人

    有一些网站可以在线生成举牌小人,看起来很可爱,也比较有趣.生成的图片用来做素材是个不错的选择! upuptoyou是一款非常有创意的小工具,可以用于表白,或节日送祝福等场景,举牌是一种支持的态度,是一 ...

  5. 5G最完整的PPT,朋友圈超火

    分享一份这几天在朋友圈超火的5G PPT. 该PPT作者为王喜文.王喜文博士是国内第一本"工业4.0"方面专著的作者,这个课件是王喜文博士给地方政府和企业家讲座的完整内容,通过对5 ...

  6. 白嫖我常用的 11 个超火的前端必备在线工具,终于有时间上班摸鱼了

    大家好,我是你们的 猫哥,一个不喜欢吃鱼.又不喜欢喵 的超级猫 ~ 前言 猫哥是一个常年混迹在 GitHub 上的猫星人,所以发现了不少好的前端开源项目,在此分享给大家. 公众号:前端GitHub,专 ...

  7. 前端技巧:如何使用nodejs实现举牌人表情包?

    最近网络上流行起了一个举牌人的表情包,在里面我们想要显示任何文字都可以.今天小千就来教大家使用nodejs实现这个效果,如下图所示,拿好小本本,下面开始了. 需要使用到的插件 text-to-svg: ...

  8. aspnet还有人用吗_别盲目跟风!理性分析:超火的小香风外套真的适合你吗?

    别盲目跟风!理性分析:超火的小香风外套真的适合你吗? 要说到小香风的话,其实就是啊老生常谈了.小香风作为香奶奶家最为经典的款式无疑代表着品牌文化魅力特有的优雅和端庄.不管是在上世纪还是现在都是时尚界的 ...

  9. Github标星35K+超火的Spring Boot实战项目(附项目地址+教程文档)

    今天给大家推荐一个Github上面超火的SpringBoot实战电商项目mall,目前在Github上面已经有35k+Star.该项目拥有全套教程,对学习者特别友好.全套教程的获取方式已经放在文末! ...

最新文章

  1. android:themes.xml
  2. 完美解决tar文件window解压问题
  3. 邮件服务 交换空间(虚拟内存) 配置链路聚合 配置IPv6地址
  4. 【收藏】解决mac问题:打不开,因为它来自身份不明的开发者
  5. c/c++格式化字符串的标识
  6. android 代码 截取屏幕,如何以编程方式在Android上截取屏幕截图?
  7. 用jekyll制作高大上的网站(二)——实际应用
  8. 微信红包随机数字_微信红包随机算法转载
  9. word中的图片设定成统一文字环绕格式
  10. 计算机专业英语 侯进,06年的录取名单,谁知道麻烦发到这里,谢谢啦!!!
  11. 代理ip如何使用_为什么在使用代理IP爬虫时会出现超时?
  12. java string内部实现_Redis知识总结--string的内部实现
  13. wap push概述
  14. 修改32位的AutoCAD2012,使其能在64位系统上安装
  15. ionic自定义图标
  16. LearnGL - 05 - Texture
  17. 川土微电子 | 如何隔离 RS-485 系统
  18. 智能停车场(可检测车牌通过oled屏幕显示车牌号)语音+LED灯提示该车辆所停车位
  19. 哪个邮箱好用又安全?最安全的邮箱排名是?
  20. 在Vue中使用 createjs

热门文章

  1. Python中的bbox_overlaps()函数详解
  2. AWS S3 挂载到EC2
  3. C++笔试试题讲解(~~~可能是全站唯独一份有解析的~~~)
  4. 如何把PDF转换成Word文档?这几种方法看一遍就会
  5. 基于TCP的服务器端/客户端的C语言代码实现和工作原理
  6. hashmap中的key是有序的么_Java中的HashMap,为什么输出竟然是有序的
  7. mysql 查询每天某个时间段的数据_mysql 中,统计一个时间段内每天8时到12时的数据的查询语句怎么写?...
  8. 软件测试 瀑布模式 v模型
  9. 云存储——360云盘
  10. Mac——开启键盘F1 - F12功能键