Show only the outlines of graphic primitives

A little simpler & shorter, but effectively the same as the answer by ybeltukov:

g = Graphics[{Red, Rectangle[{0, 0}, {1, 3}], Blue, 
     Polygon[{{1, 1}, {3, 1}, {2, 2}}]}, Frame -> True];

g /. c_RGBColor :> Sequence[EdgeForm[c], Transparent]

enter image description here


Based on the excellent comments, a version that works for all color directives, draws no faces instead of transparent ones and uses Directive, which is more typical for Graphics, instead of the more general Sequence.

g /. c_?ColorQ :> Directive[EdgeForm[c], FaceForm[]]

There is a brute force solution with substitution all colors to EdgeForm colors and putting FaceForm[None] at the beginning

g = Graphics[{Red, Rectangle[{0, 0}, {1, 3}], Blue, 
    Polygon[{{1, 1}, {3, 1}, {2, 2}}]}, Frame -> True];
Graphics[Prepend[#, FaceForm[None]] /. c_RGBColor :> EdgeForm[c], ##2] & @@ g

enter image description here


An even bruter force approach using new region functions

g1 = Graphics[{Red, Rectangle[{0, 0}, {1, 3}], Blue, 
    Polygon[{{1, 1}, {3, 1}, {2, 2}}]}, Frame -> True];

Show[
 RegionPlot[
    ImplicitRegion[
     RegionMember[#[[1]], {x, y}],
     {x, y}],
    PlotStyle -> None,
    BoundaryStyle -> #[[2]]] & /@
  Thread[{
    Cases[g1, r_?(RegionQ[#] &), Infinity],
    Cases[g1, rgb_RGBColor, Infinity]}],
 PlotRange -> All]

enter image description here

Tags:

Graphics