I'd like a thick Line to look like ChartElementFunction -> "GlassRectangle"
How can that be accomplished?
Using ParametricPlot with a custom ColorFunction:
ClearAll[parametricCurve, glassGradientCF]
parametricCurve[curve_, width_][x_, u_] := curve[x] +
(1 - 2 u) width/2 Cross @ Normalize[curve'[x]];
glassGradientCF[color_: Red] := Module[{}, BarChart[{1}];
SystemBarFunctionDumpGlassGradient[color] @ #4]&;
Examples:
c1[x_] := {x + 1, 2 x}
pp1 = ParametricPlot[parametricCurve[c1, 1][x, u], {x, 1, 4}, {u, 0, 1},
BoundaryStyle -> Red, ColorFunction -> glassGradientCF[], Axes -> False]
c2[x_] := {x, Sin[x] + x/2}
pp2 = ParametricPlot[parametricCurve[c2, .5][x, u], {x, 0, 3 Pi}, {u, 0, 1},
BoundaryStyle -> Green, ColorFunction -> glassGradientCF[Green], Axes -> False]
c3[x_] := 3 {Cos @ x + 2, Sin @ x + 2}
pp3 = ParametricPlot[parametricCurve[c3, -.5][x, u], {x, 0, 3 Pi/2}, {u, 0, 1},
BoundaryStyle -> Blue, ColorFunction -> glassGradientCF[Blue], Axes -> False]
Show[pp1, pp2, pp3, PlotRange -> All]
Borrowing from the technique in the glowing edges answer, you can create polygons and texture them with any image:
texturedLine[p1_, p2_, teximg_, width_] :=
Module[{s = width, vec = p2 - p1, perp}, perp = Cross[vec];
{Texture[teximg],
Polygon[{p1 - perp*s, p1 + perp*s, p2 + perp*s, p2 - perp*s},
VertexTextureCoordinates -> {{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}];
glassTex = Import["https://i.stack.imgur.com/R6vZR.png"];
glassTex = ImageTake[glassTex, {20, 30}, {15, -15}];
Graphics[{
(* create a line from 0,0 to 1,1 with thickness .05 *)
texturedLine[{0, 0}, {1, 1}, glassTex, .05],
(* create lots of lines around a circle *)
texturedLine[#[[1]], #[[2]], glassTex, .3] & /@
Partition[CirclePoints[50], 2, 1]
}]
Is there an easy way to map such a rectangle to a sector of a circle. Or to a segment of a ring when mapping to a function such as sin x?
– Gannicus May 15 '21 at 19:27
What is the best way to get a clean edge? – Gannicus May 15 '21 at 12:18
BarFunctionDumpGlassGradient[][0],SystemBarFunctionDumpGlassGradient[][1/19],SystemBarFunctionDumpGlassGradient[] ... [8/19],SystemBarFunctionDumpGlassGradient[][9/19],<<10>>} is not a valid list of colors or images, or pairs of a real number and a color or an image. – Gannicus May 15 '21 at 12:49glassGradientCFworks in v12.2. – kglr May 15 '21 at 17:09One more question: How do you possibly know about 'GlassGradient' ?
Wolfram comes up empty, ditto for Google (which already finds this contribution)
– Gannicus May 15 '21 at 19:19GlassGradientis thru a spelunking expedition: UsedClearAttributes[ChartElementDataFunction, {Protected, ReadProtected}]; ?? ChartElementDataFunctionto discover that we can get the internal function that constructs the graphics primitives usingChartElementData["GlassRectangle", "InternalChartElementFunction"](which givesSystem`BarFunctionDump`GlassGradientBar). Then??System`BarFunctionDump`GlassGradientBarreveals that this function calls ... – kglr May 15 '21 at 21:25System`BarFunctionDump`GradientBarwhich in turn callsSystem`BarFunctionDump`GlassGradientto construct a color function that gives the glass look/feel. – kglr May 15 '21 at 21:25