Spring is here in Natick and the tulips are blooming! While tulips appear only briefly here in Massachusetts, they provide a lot of bright and diverse colors and shapes. To celebrate this cheerful flower, here's some code to create your own tulip!
This script uses some fun tricks, like extracting a subset of the 'hot' colormap for a red-to-yellow colormap, and specifying several material properties to give it a more sunny day look. There's also the
sinpi and cospi functions that Mike likes so much!
Explore the code and create some new breeds of tulips for your MATLAB.
np = 3; % number of petals
n=np*20+1; % Theta resolution
theta=linspace(0, np*(1/np)*2,n);
for k=[0 1/np] % 2 layers of petals
x=1-(.8*(1-mod(np*(theta+k),2)).^3-.05).^2/2;
X=R2.*cospi(theta)-R3.*cospi(theta);
Y=R2.*sinpi(theta)-R3.*sinpi(theta);
surface(X,Y,Z1*2,C,FaceColor="interp",EdgeColor="none",FaceLighting="gouraud");
line(X(end,:),Y(end,:),Z1(end,:)*2,Color="#cc0",LineWidth=1);
surface(CX*.1,CY*.1,(CZ-1)*2,[],FaceColor="#9b8",EdgeColor="none");
cmap=hot(200); % Colors of tulip
colormap(cmap(80:150,:)) % Extract subset of hot colormap.
material([.6 .9 .3 2 .5])
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.