Matlab實現繪制玫瑰線的示例代碼
繪制效果
實際上就是在進行曲線:
的可視化,代碼非常簡單哈:
基礎代碼
function roseCurve1 set(gcf,'position',get(0,'ScreenSize')); % 坐標區域修飾 ax=gca; hold on ax.XLim=[-.5,7.5]; ax.YLim=[-.5,10.5]; ax.Color=[0 0 0]; ax.DataAspectRatio=[1,1,1]; ax.XTick=[]; ax.YTick=[]; % 屬性列表 textProp1={'FontSize',14,'FontName','Cambria','Color',[1,1,1].*.8,'HorizontalAlignment','center'}; textProp2={'FontSize',15,'FontName','Cambria','Color',[255,227,147]./255,'HorizontalAlignment','center'}; circProp={'o','Color',[1,1,1].*.8,'MarkerSize',18,'LineWidth',1.5}; % 繪制數字 plot(1:1:7,10.*ones(1,7),circProp{:}) plot(zeros(1,10),0:9,circProp{:}) for i=1:7,text(i,10,num2str(i),textProp1{:});end for i=1:10,text(0,10-i,num2str(i),textProp1{:});end text(0+.2,10+.2,'q',textProp2{:}) text(0-.2,10-.2,'p',textProp2{:}) text(0,10,'\\',textProp2{:},'FontSize',18) [XMesh,YMesh]=meshgrid(1:7,1:10); qpMesh=XMesh./YMesh; % 循環繪圖 for i=1:10 for j=1:7 lineMat(i,j)=plot(XMesh(i,j),10-YMesh(i,j),'Color',[1,1,1,.4],'LineWidth',1.2); end end thetaList=linspace(0,20*pi,1000); for t=1:length(thetaList) for i=1:10 for j=1:7 r=cos(qpMesh(i,j)*thetaList(1:t)); x=XMesh(i,j)+cos(thetaList(1:t)).*r.*.4; y=10-YMesh(i,j)+sin(thetaList(1:t)).*r.*.4; lineMat(i,j).XData=x; lineMat(i,j).YData=y; end end pause(.01) end end
土味代碼
來個彩虹配色的土味代碼
function roseCurve2 set(gcf,'position',get(0,'ScreenSize')); % 坐標區域修飾 ax=gca; hold on ax.XLim=[-.5,7.5]; ax.YLim=[-.5,10.5]; ax.Color=[0 0 0]; ax.DataAspectRatio=[1,1,1]; ax.XTick=[]; ax.YTick=[]; % 屬性列表 textProp1={'FontSize',14,'FontName','Cambria','Color',[1,1,1].*.8,'HorizontalAlignment','center'}; textProp2={'FontSize',15,'FontName','Cambria','Color',[255,227,147]./255,'HorizontalAlignment','center'}; circProp={'o','Color',[1,1,1].*.8,'MarkerSize',18,'LineWidth',1.5}; % 繪制數字 plot(1:1:7,10.*ones(1,7),circProp{:}) plot(zeros(1,10),0:9,circProp{:}) for i=1:7,text(i,10,num2str(i),textProp1{:});end for i=1:10,text(0,10-i,num2str(i),textProp1{:});end text(0+.2,10+.2,'q',textProp2{:}) text(0-.2,10-.2,'p',textProp2{:}) text(0,10,'\\',textProp2{:},'FontSize',18) [XMesh,YMesh]=meshgrid(1:7,1:10); qpMesh=XMesh./YMesh; disMesh=XMesh-YMesh+10; maxDis=max(disMesh,[],[1,2]); disMesh=mod(disMesh+6,maxDis)+1; % 構造hsv配色 colList=hsv2rgb([linspace(0,1,maxDis)',ones(maxDis,1),ones(maxDis,1).*.7]); % colList=pink(maxDis); % 循環繪圖 for i=1:10 for j=1:7 lineMat(i,j)=plot(XMesh(i,j),10-YMesh(i,j),'Color',[colList(disMesh(i,j),:),.5],'LineWidth',1.2); end end thetaList=linspace(0,20*pi,1000); for t=1:length(thetaList) for i=1:10 for j=1:7 r=cos(qpMesh(i,j)*thetaList(1:t)); x=XMesh(i,j)+cos(thetaList(1:t)).*r.*.4; y=10-YMesh(i,j)+sin(thetaList(1:t)).*r.*.4; lineMat(i,j).XData=x; lineMat(i,j).YData=y; end end pause(.01) end end
哈哈哈果然彩虹色畫出來還是太土瞭:
若是將代碼
colList=hsv2rgb([linspace(0,1,maxDis)',ones(maxDis,1),ones(maxDis,1).*.7]);
修改為:
colList=pink(maxDis);
以上就是Matlab實現繪制玫瑰線的示例代碼的詳細內容,更多關於Matlab玫瑰線的資料請關註WalkonNet其它相關文章!