• Remix
  • Share
  • New Entry

on 26 Oct 2021
  • 10
  • 160
  • 0
  • 0
  • 278
% Sweet Lightning : A speckled breed of pumpkin
% This script updates the og pumpkin script, and adds a discrete
% colormap and color speckles, much like the real version of the
% Sweet Lightning pumpkin.
% This particular breed is quite small and decorative, but
% auto-scale limits make it look the same size as the og pumpkin
% script.
[X,Y,Z]=sphere(200);
% This computes ridges around the pumpkin.
R=1-(1-mod(0:.1:20,2)).^2/12;
% Normally I'd do this inline with the surf command, but I need to
% use the values twice, once in surf, and once to compute the color c.
x=R.*X;
y=R.*Y;
z=Z.*R;
c=hypot(hypot(x,y),z);
% Several pumpkin breeds with speckles have a different color in
% the dents than on the ridges. To start off, set the CData of the
% surface to be == distance from center iff the pumpkin were round.
% Thus, c is for round (inclusive of ridges) and we squish it into
% a pumpkin shape below in the Z component of the surf call.
% To add speckles, add scaled random noise which will only be
% visible near the boundary of the two colors.
surf(x,y,(.8+(0-(1:-.01:-1)'.^4)*.3).*z,c+randn(201)*.03)
% This command is a bit shorter than specifying the face and edge
% colors in the surface command.
shading interp
% As we build the stem, we need to specify CData even though it
% isn't used. That forces the automatic CLim of the axes to be
% specified in a way we control. The alternative would be to add
% a command like: caxis([.8 1]) or some-such to force the
% boundary between the discrete colors to work correctly for the
% speckles. Saves about 13 chars. In this case, our 2 color
% colormap would have the boundary right in the middle, but we want
% to sink it back into the ridges, so extend the clim downwards here.
surface(X/12,Y/12,Z*.7+.4,c-.11,FaceC='#080',EdgeC='n')
% Use a discreet colormap so that we can simulate speckles.
% Looks like the RGB version is shorter than using validatecolor
% like this:
% colormap(validatecolor({'#ff7518' '#ffffbb'},'multiple'))
colormap([1 .4 .1
1 1 .7])
axis equal off
% The lighting Model
% Pumpkin lights matter, but this speckled punkin looks ok 'flat' lit
% which is the default, so that, and not specifying all the material
% parameters saves a bunch of characters which were needed to make room for
% the speckle logic.
% lighting g
material([.6 1 .3])
camlight
Remix Tree