基于matlab绘制滚动点阵字幕(跑马灯)
function dotmatrix2 %仿矩阵字模 % copyright @baby_wolf qq:654832919 % $date 2011-11-14$ $version 2.0$ % $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ %% 图形窗口,坐标轴准备 hfig=figure('position',[300 355 477 325],'color','k','name','dotmatrix','menubar','none'); %%figure背景颜色 axis off ;axis equal [X Y]=meshgrid(linspace(1,16,128)); h=zeros(size(X)); %存放所有“点”的句柄 str='我们毕业啦!'; %%%%【将此处修改成你要显示的文字】 DATA=[]; for i=1:length(str) %调用字模提取函数文件,生成点阵数据 temp=getwordmatrix(str(i)); DATA=[DATA flipud(temp)]; end DATA=[zeros(16,60) DATA zeros(16,60)]; %%微调显示效果,让文字从右出现 for i=1:16%创建点阵 for j=1:64 h(i,j)=line(X(i,j),Y(i,j),'marker','s','markersize',3,'markerfacecolor','none'); set(h(i,j),'buttondownfcn','buttondown','markeredgecolor','none'); end end % while ishandle(hfig) % 循环改变点阵 % Z=DATA(:,1:64); % for i=1:16 % for j=1:64 % if Z(i,j)==1 % set(h(i,j),'markerfacecolor','g'); % else % set(h(i,j),'markerfacecolor','none'); % end % end % end % pause(1/24); % DATA=DATA(:,[2:end 1]); % end %% 循环显示 numFrames=0; while numFrames<(size(DATA,2)-64)/2 %while ishandle(hfig) % 循环改变点阵 Z=DATA(:,1:64); for i=1:16 for j=1:64 if Z(i,j)==1 set(h(i,j),'markerfacecolor','g'); %%%%更改文字颜色。'g'为绿色 else set(h(i,j),'markerfacecolor','none'); end end end pause(.02); DATA=DATA(:,[3:end 1:2]); numFrames=numFrames+1; %%%%% frames(numFrames)=getframe;%%%%% end function y=getwordmatrix(word) %%getwordmatrix(word)生成一个16*16的字模矩阵数据。1表示亮点,0表示暗点 h=figure('visible','off'); hold on imshow(ones(16,16)); htext=text(10,10,word); set(htext,'HorizontalAlignment','center','VerticalAlignment','middle','margin',eps); axis equal frame=getframe; cdata=frame.cdata; cdata=im2bw(cdata); %cdata 80*81 y=zeros(16,16); for i=1:16 for j=1:16 if cdata(i,j)==1 y(i,j)=1; end end end y=1-y; close(h); %%back %{ function y=getwordmatrix(word) %%getwordmatrix(word)生成一个16*16的字模矩阵数据。1表示亮点,0表示暗点 for i=1:5:76 for j=1:5:76 if sum(sum(cdata(i:i+4,j:j+4)))>=21 y((i+4)/5,(j+4)/5)=1; end end end
版本:2014a
完整代码或代写加1564658423