Function Repository Resource:

DropShadow

Source Notebook

Display graphics with a drop shadow

Contributed by: Michael Sollami

ResourceFunction["DropShadow"][graphics]

adds a drop shadow effect to the given graphics object.

Details and Options

ResourceFunction["DropShadow"] is designed to work on expressions of head Graphics or Graph.
ResourceFunction["DropShadow"] preserves the absolute options of the given graphics object.
ResourceFunction["DropShadow"] accepts the following options:
"Blur"8the pixel radius of the shadow blur
"Color"Graythe color of the shadow
ImagePaddingAutomaticspecify extra padding for extended objects
"Offset"{-5,8}the pixel offset {x,y} of the shadow
"Opacity"Automaticthe opacity of the shadow

Examples

Basic Examples (3) 

Add a drop shadow to Graphics:

In[1]:=
ResourceFunction["DropShadow"][
 ChemicalData["Caffeine", "StructureDiagram"]]
Out[1]=

Add a styled drop shadow to the plot of a Molecule:

In[2]:=
m = MoleculePlot[ 
Sequence[
Molecule["O=C(C1CCC1)S[C@@H]1CCC1(C)C"], {
Bond[{"C", "O"}, "Double"], 
Atom["C", "RingAtomQ" -> True]}]];
ResourceFunction["DropShadow"][m, "Blur" -> 20, "Color" -> Blue, "Opacity" -> .8, "Offset" -> {-5, 5}]
Out[3]=

Add a drop shadow to a Graph:

In[4]:=
g = Graph[
Sequence[
Table[
Annotation[
     v, {VertexSize -> 0.2 + 0.2 Mod[v, 5], VertexStyle -> Hue[v/15, 1, 1]}], {v, 0, 14}], 
Table[
UndirectedEdge[v, 
Mod[v + 1, 15]], {v, 0, 14}]]];
Show[ResourceFunction["DropShadow"][g, "Blur" -> 20, "Color" -> Hue[.7], "Offset" -> {5, 5}], ImageSize -> Small, ImagePadding -> 10, Background -> LightGray]
Out[5]=

Scope (3) 

DropShadow returns a Graphics object that you can use with Show:

In[6]:=
Show[ResourceFunction["DropShadow"]@ChemicalData["Caffeine"], ImageSize -> 200]
Out[6]=

Add a drop shadow to an Image with an alpha channel:

In[7]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/0378d115-4d9e-4576-bceb-477786a34ec2"]
Out[7]=

Add a drop shadow to a GraphicsGrid:

In[8]:=
ResourceFunction["DropShadow"]@
 GraphicsGrid[
  Partition[
   Table[Graphics[{Hue[t/24], RandomPolygon[10]}, ImageSize -> 30], {t, 24}], 6], ImageSize -> 250]
Out[8]=

Possible Issues (1) 

DropShadow doesn't work on all types of objects, for example:

In[9]:=
ResourceFunction["DropShadow"][
 TextStructure["The cat sat on the mat."]]
Out[9]=

Publisher

Michael Sollami

Version History

  • 1.0.0 – 02 April 2020

Related Resources

License Information