http://www.mathworks.com/matlabcentral/fileexchange/15987
In my Friday afternoon boredom, I have just modified some aspects of the program to create a function which simulates a pretty flower bed
Some example outputs below - enjoy! Right, now back to work ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function flower_bed(n) | |
% n is the number of internal circles (must be greater than 2 - greater than 10 looks weird) | |
h = figure; | |
hAxs = axes('Parent',h); | |
axis equal; | |
grid off; | |
hold on; | |
V = 0:2*pi/n:2*pi; | |
V = V +pi/2; | |
cV = cos(V); | |
sV = sin(V); | |
d = sqrt(diff(cV).^2+diff(sin(V)).^2); | |
r = d(1)/2; | |
ratio = max(max(max(abs(cV+r)),max(abs(sV+r))),... | |
max(max(abs(cV-r)),max(abs(sV-r)))); | |
cV = cV/ratio; | |
sV = sV/ratio; | |
r = r/ratio; | |
r_inner1 = sqrt(cV(1).^2+sV(1).^2) - r; | |
for k=1:2:11 | |
for j=1:2:11 | |
S(1).x = [k,k,k+cV(1:end-1)]; | |
S(1).y = [j,j,j+sV(1:end-1)]; | |
S(1).r = [1,r_inner1,r*ones(1,n)]; | |
hAxs = plot_circles(hAxs,S,1); | |
end | |
end | |
axis off | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
function hAxs = plot_circles(hAxs,S,n,display_style) | |
hold on | |
for t=1:size(S(n).x,2) | |
rectangle('Position',[S(n).x(t)-S(n).r(t),... | |
S(n).y(t)-S(n).r(t),2*S(n).r(t),2*S(n).r(t)],... | |
'Curvature',[1,1],'LineWidth',0.5,... | |
'tag',num2str(n),'Parent',hAxs,'EdgeColor','k','FaceColor',[rand rand rand]); | |
% plot(S(n).x(t),S(n).y(t),'k+','tag',num2str(n)); | |
end |


No comments:
Post a Comment