- /
-
Rose with faux lighting
on 25 Oct 2021
- 19
- 177
- 3
- 0
- 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.
%
% Lastly, I remixed from JR's "somewhere it's spring", but had
% acutally started from scratch before I saw that contribution.
% Thus - I have different and more aggressive chracter
% optimizations to make room for the extra work coloring the rose.
% 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')