Function Repository Resource:

ShadowShow

Source Notebook

Show a graphics object with simulated background shadow

Contributed by: Jon McLoone

ResourceFunction["ShadowShow"][gr]

displays 2D Graphics with a simulated background shadow.

Details and Options

ResourceFunction["ShadowShow"] supports the usual options of Show, together with:
"ShadowBlur"10how many pixels to blur the shadow cast
"ShadowBrightness"0.the GrayLevel of the Shadow cast
"SunAltitude"75 Degreethe elevation angle of the light source casting the shadow
"SunAzimuth"210 Degreethe direction of light creating the shadow
"Location"Herethe GeoLocation used to calculate automatic altitude and azimuth
"Time"Nowthe time used to calculate automatic altitude and azimuth
"FacingDirection"0 (North)the direction the viewer faces the Graphics
BackgroundAutomaticthe Background color

Examples

Basic Examples (1) 

Create a drop shadow for a BarChart:

In[1]:=
ResourceFunction["ShadowShow"][BarChart[{3, 2, 1}, BarSpacing -> 1]]
Out[1]=

Scope (2) 

Any Graphics object can be used:

In[2]:=
ResourceFunction["ShadowShow"][
 Graphics[{Red, Disk[], Green, Rectangle[{0, 0}, {2, 2}], Blue, Disk[{2, 2}]}], Axes -> True]
Out[2]=

Opacity affects shadows:

In[3]:=
ResourceFunction["ShadowShow"][
 Graphics[{Opacity[0.5], Red, Disk[], Green, Rectangle[{0, 0}, {2, 2}], Blue, Disk[{2, 2}]}], Axes -> True]
Out[3]=

Options (3) 

You can control how sharp the shadow is with "ShadowBlur" which is defined in pixels of shadow image:

In[4]:=
ResourceFunction["ShadowShow"][BarChart[{3, 2, 1}, BarSpacing -> 1], "ShadowBlur" -> 40]
Out[4]=

The intensity of the shadow is controlled with "ShadowBrightness":

In[5]:=
ResourceFunction["ShadowShow"][BarChart[{3, 2, 1}, BarSpacing -> 1], "ShadowBrightness" -> 0]
Out[5]=

The angle and length of the shadow are controlled by "SunAltitude" and "SunAzimuth":

In[6]:=
ResourceFunction["ShadowShow"][BarChart[{3, 2, 1}, BarSpacing -> 1], "SunAltitude" -> 85 Degree, "SunAzimuth" -> 140 Degree]
Out[6]=

If "SunAltitude" and "SunAzimuth" are set to Automatic, their values are calculated by the real sun position at "Location" and "Time" which default to Here and Now:

In[7]:=
ResourceFunction["ShadowShow"][BarChart[{3, 2, 1}, BarSpacing -> 1], "SunAltitude" -> Automatic, "SunAzimuth" -> Automatic, "Location" -> Entity["City", {"Oxford", "Oxfordshire", "UnitedKingdom"}], "Time" -> DateObject[{2019, 8, 7}, TimeObject[{11, 0, 0}], TimeZone -> 0]]
Out[7]=

Possible Issues (2) 

If the sun is below the horizon or in front of the viewer (who faces north by default) then no shadow is produced:

In[8]:=
ResourceFunction["ShadowShow"][BarChart[{3, 2, 1}, BarSpacing -> 1], "SunAltitude" -> Automatic, "SunAzimuth" -> Automatic, "Location" -> Entity["City", {"Sydney", "NewSouthWales", "Australia"}], "Time" -> DateObject[{2019, 8, 7}, TimeObject[{11, 0, 0}], TimeZone -> 12]]
Out[8]=

The viewer can change their orientation to face south to create a shadow:

In[9]:=
ResourceFunction["ShadowShow"][BarChart[{3, 2, 1}, BarSpacing -> 1], "SunAltitude" -> Automatic, "SunAzimuth" -> Automatic, "Location" -> Entity["City", {"Sydney", "NewSouthWales", "Australia"}], "Time" -> DateObject[{2019, 8, 7}, TimeObject[{11, 0, 0}], TimeZone -> 12],
 "FacingDirection" -> 180 Degree]
Out[9]=

Publisher

Jon McLoone

Version History

  • 1.0.1 – 20 June 2024
  • 1.0.0 – 21 October 2019

License Information