• Remix
  • Share
  • New Entry

on 24 Oct 2021
  • 12
  • 104
  • 3
  • 0
  • 280
% One Ring to Love our MATLABs
% To put text inside our ring, we need to capture a texture
% which we apply to the surface. This keeps the
% text looking mostly square by restricting the axes vertical size.
% Setting the Position (po) makes the texture bigger, getting a
% higher res text out of this small default figure size.
% Good news, this position stays for the drawing of the ring,
% making the final image bigger too.
% Lastly, use P=V syntax in arg list to save 2 quotes per parameter
% across the whole script.
axes(Pl=[3 1 1],Po=[0 0 1 1])
% Unicode for the heart emoji instead of \heartsuit tex code to
% save chars.
% Ba is the background color, and Ma is the margin. This puts a big
% yellow square behind the text, but on top of the axes decorations,
% saving chars such that we don't need to set the Axes color, nor
% somehow recolor the X and Y ruler so they don't show up in the
% texture.
text(0,.25,'I ❤ MATLAB',FontSi=20,Ba='#da4',Ma=350)
g=getframe;
% Call meshgrid with one input. Would prefer 2 to better control where
% textures and stuff go, but that takes up too many characters.
%
% Using colonop here saves a couple characters instead of linspace, but
% the math is imperfect so if you rotate around you might find a
% seam.
% Lastly, make the mesh very dense. That way we can use the
% default lighting option of 'flat' and it still looks good.
[t,p]=meshgrid(pi/2:pi/100:pi*2.5);
% Adding this 'min' call flattens the inside of what would normally
% be a donut. This makes it look like a ring instead.
D=1-min(cos(p),0)/5;
% Draw the surface using 'surf' which resets the axes used
% to create the inscription in the ring. It is also 3 chars
% shorter than 'surface'.
% Inline the computation of X,Y,Z, which saves 2 char per variable
% assignment and 1 per use in the surf command.
% The minus sign on X and Z allows me to not call 'flipud' and
% 'fliplr' on the getframe img which saves many characters
surf(-D.*cos(t),D.*sin(t),-sin(p)/3,g.cdata,FaceC='t',EdgeC='n')
% Turn off axes, keep it square
axis off equal
% Twist things just a bit to center the text.
% Could comment this out, and it looks mostly ok.
view([-45 25])
% Normally I'd like to use this 10 char cmd, but made the mesh dense
% instead so I can use these 10 chars to put the light in a better
% place.
%
% lighting g
% Expensive character wise, but this makes the lighting look nicer,
% brightening up the shadows with more ambient strength, but keeping
% the default level of specular highlighting to save chars.
%
% Check out my 'pumpkin' script for getting a waxy look using
% material command.
% https://www.mathworks.com/matlabcentral/communitycontests/contests/4/entries/6893
material([.6 .9 .9 5 .3])
% Get some lights turned on. Normally I'd use 'camlight', but the
% default position cause colors on the left to obscure the detail
% of the ridge of the ring.
light(Po=[-5 -7 14])
Remix Tree
Load full remix tree