• Remix
  • Share
  • New Entry

on 12 Oct 2022
  • 48
  • 154
  • 1
  • 1
  • 273
% A Fancy Rose
% I originally found the code on the MW Facebook feed.
% I also saw a version on Paul Nylander's math artwork page.
% I used a variant of this for last years mini-hack
% This colonop will be used again for the colormap
m=0:.01:1;
% Crunched up algorithm from the online post. Find the original
% for a more legible version of this mess.
% I shrank this down mostly by factoring out pi so it showed up
% less often, using colonop instead of linspace, and taking
% advantage of operator precidence to remove parenthisis.
[R,T]=ndgrid(m,-.6:.01:20);
x=1-(5/4*(1-mod(3.6*T, 2)).^2-1/4).^2/2;
P=pi*exp(-T/8)/2;
s=sin(P);
c=cos(P);
y=2*R.^2.*(1.3*R-1).^2.*s;
S=x.*(R.*s+y.*c);
X=S.*sin(T*pi);
Y=S.*cos(T*pi);
% Geom for Z needed x.* - but to save 2 chars on the parens
% do it inline in the surf command, but NOT for the color array.
% The color array looked close enough without it.
Z=R.*c-y.*s;
% Display the arrays with colors starting black inside the rose
% so we don't need to spend chars on using lights.
surf(X,Y,x.*Z,hypot(hypot(X,Y),Z*.9));
shading interp
axis equal off
% This bit of trickery recycles 'm' from above which happened to
% be the same colonop needed for the colormap.
% Use this trick to quickly add the g,b as 0 to the red colormap.
m(2:3,:)=0;
colormap(m')
Image
Remix Tree