h = 3.5; Needs["VariationalMethods`"]; Unset[x]; frame[dip_] := Module[{eqn, soln}, c[x_] := 1 - dip ((1 + Tanh[5 (x + 0.7)])/2 - (1 + Tanh[5 (x - 0.7)])/2 + 0.1 Exp[-10 x^2]); eqn = EulerEquations[Sqrt[1 + y'[x]^2]/c[x], y[x], x]; soln = First[NDSolve[{eqn, y[-1] == 0, y[1] == h}, y[x], {x, -1, 1}]]; Show[ Graphics[{ Table[ {Lighter@ColorData["LightTemperatureMap"][1 - c[x]], Rectangle[{x, -0.1}, {x + 0.1, h + 0.1}]} , {x, -1.1, 1.1, 0.05}], {RGBColor[0.62, 0.15, 0.2], Disk[{-1, 0}, 0.1], Disk[{1, h}, 0.1]} } , PlotRange -> {{-1.1, 1.1}, {-0.1, h + 0.1}}, AspectRatio -> h/2], Plot[{Evaluate[y[x] /. soln], Evaluate[y[x] /. soln]}, {x, -1, 1}, PlotStyle -> {Directive[Thickness[0.05], RGBColor[0.62, 0.15, 0.2]], Directive[White]}] ] ]; frame[0.3]