%导入轮廓数据并存储到元胞数组
Sakura=cell(11,1);
Sakura{1}=importdata('petal_profile.txt');
Sakura{2}=importdata('surround_data.txt');
Sakura{3}=importdata('stamen_profile1.txt');
Sakura{4}=importdata('stamen_profile2.txt');
Sakura{5}=importdata('stamen_profile3.txt');
Sakura{6}=importdata('stamen_profile4.txt');
Sakura{7}=importdata('stamen_profile5.txt');
Sakura{8}=importdata('stamen_profile6.txt');
Sakura{9}=importdata('stamen_profile7.txt');
Sakura{10}=importdata('stamen_profile8.txt');
Sakura{11}=0.125;
%调用函数绘制图形
x=linspace(0,2*pi,20)';
y=sin(x);
for i=1:size(y,1)
petal_plot(Sakura,x(i),y(i),0.1,2*pi*rand)
end
function petal_plot(Sakura,center_x,center_y,scale,theta)
%程序用于绘制樱花
%Sakura为存储樱花坐标数据的元胞数组
%center_x代表花瓣中心坐标x
%center_y代表花瓣中心坐标y
%scale代表相对于原图放大的比例
%theta为花瓣旋转的角度(弧度制)
%将数据进行旋转变换
for i=1:10
Sakura{i}=Sakura{i}*[cos(theta) sin(theta);-1*sin(theta) cos(theta)];
end
%将数据进行比例缩放
for i=1:11
Sakura{i}=Sakura{i}*scale;
end
%将数据进行平移变换
for i=1:10
Sakura{i}(:,1)=Sakura{i}(:,1)+center_x;
Sakura{i}(:,2)=Sakura{i}(:,2)+center_y;
end
%绘制樱花图形
patch(Sakura{1}(:,1),Sakura{1}(:,2),[255/255 205/255 224/255],...
'LineWidth',3,...
'EdgeColor',[255/255 128/255 178/255]);
axis equal
hold on
patch(Sakura{2}(:,1),Sakura{2}(:,2),[255/255 124/255 177/255],...
'EdgeColor','None',...
'FaceAlpha',0.5)
for i=3:10
plot(Sakura{i}(:,1),Sakura{i}(:,2),...
'Color',[220/255 25/255 103/255],...
'LineWidth',3)
end
%绘制圆形
for i=3:10
rectangle('Position',[Sakura{i}(end,1)-Sakura{11} ...
Sakura{i}(end,2)-Sakura{11} ...
2*Sakura{11} 2*Sakura{11}],...
'Curvature',[1 1],'FaceColor',[255/255 133/255 52/255],...
'EdgeColor',[255/255 126/255 41/255],...
'LineWidth',2);
end
end