# Show only the outlines of graphic primitives

I want to go from

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


to

I have rather clumsily written:

RectangleToLines[r_] := With[{n = Flatten @ r},
Line[{{n[[1]], n[[2]]}, {n[[3]], n[[2]]}, {n[[3]], n[[4]]}, {n[[1]],n[[4]]}, {n[[1]], n[[2]]}}]
]

RectangleToLines[{{0, 0}, {1, 3}}]


Line[{{0, 0}, {1, 0}, {1, 3}, {0, 3}, {0, 0}}]

and similar with the triangle. Terrible, because I would end up with many "FormToLines"-definitions.

I feel - that especially with V10 - there should be a much cleverer way to do this.

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]


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[]]

• +1 You could also use Directive – Simon Woods Sep 7 '14 at 14:58
• You can also use FaceForm[] instead of Transparent. – Algohi Sep 7 '14 at 17:56
• You can also use c_?ColorQ so that Hue, CMYKColor, GrayLevel, etc. are all recognized. – rm -rf Sep 8 '14 at 0:45

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


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]]] & /@
Cases[g1, r_?(RegionQ[#] &), Infinity],
Cases[g1, rgb_RGBColor, Infinity]}],
PlotRange -> All]


Why not just use EdgeForm and FaceForm directly instead?

points = {{0, 0}, {4, 0}, {3, 3}};
triangle = Triangle[points];
circle = Insphere[points];

Graphics[{
circle,
{
FaceForm[{Yellow,Opacity[0]}],
EdgeForm[{Thick,Black}],
triangle
}
}]