例如,您可以查看 Alexandra Baumgart 和 Hazuki Okuda 使用 Mathematica 完成的示例。这是通过Manipulate有效地创建基本 UI 来实现的。
代码:
Manipulate[
Grid[{{Show[
ParametricPlot3D[{1.25Cos[t], 1.25 Sin[t],s+2-2w},{s,0,.25},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Gray],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{r Cos[t], r Sin[t],2.25-2w},{r,0,1.25},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Gray],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{r Cos[t], r Sin[t],2-2w},{r,0,1.25},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Gray],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{1.25Cos[t], 1.25 Sin[t],s-2.25+2w},{s,0,.25},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Gray],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{r Cos[t], r Sin[t],-2.25+2w},{r,0,1.25},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Gray],Mesh->None],
ParametricPlot3D[{r Cos[t], r Sin[t],-2+2w},{r,0,1.25},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Gray],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{(1-s/2) Cos[t],(1-s/2) Sin[t],Max[0,-s+2 ]},{s,Min[2-(2^(2/3) (2 \[Pi]-Min[2Pi,3 V((w^2)/(.04))])^(1/3))/\[Pi]^(1/3)-w,1.99],2},{t,0, 2 Pi},PlotStyle->Directive[Opacity[1],Hue[a]],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{r Cos[t], r Sin[t],Max[0,(2^(2/3) (2 \[Pi]-Min[2Pi,3 V((w^2)/(.04))])^(1/3))/\[Pi]^(1/3)-w]},{r,0, .000000000001+w+((2^(2/3) (2 \[Pi]-Min[2Pi,3 V((w^2)/(.04))])^(1/3))/\[Pi]^(1/3)-w)/2},{t,0,2Pi},PlotStyle->Directive[Opacity[1], Hue[a]],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{r Cos[t], r Sin[t], Min[0,-(2^(2/3) (2 \[Pi]-Min[2Pi,3 V((w^2)/(.04))])^(1/3))/\[Pi]^(1/3)]},{r, 0, .00000000001+w+((2^(2/3) (2 \[Pi]-Min[2Pi,3 V((w^2)/(.04))])^(1/3))/\[Pi]^(1/3)-w)/2},{t,0,2Pi},PlotStyle->Directive[Opacity[1],Hue[a]],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{(1-s/2) Cos[t],(1-s/2) Sin[t],Min[0,s -2 ]},{s,w,2},{t,0, 2 Pi},PlotStyle->Directive[Opacity[.2],Gray],Mesh->None, Lighting->"Neutral"],ParametricPlot3D[{(1-s/2) Cos[t],(1-s/2) Sin[t],Max[0,-s + 2 - w]},{s,w,2},{t,0, 2 Pi},PlotStyle->Directive[Opacity[.2],Gray],Mesh->None, Lighting->"Neutral"],
ParametricPlot3D[{(1-s/2) Cos[t],(1-s/2) Sin[t],Min[0,s-2+ w]},{s,w,Min[2-(2^(2/3) (2 \[Pi]-Min[2Pi,3 V((w^2)/(.04))])^(1/3))/\[Pi]^(1/3)-w,2]},{t,0, 2 Pi},Mesh->None, PlotStyle->Directive[Opacity[1],Hue[a]], Lighting->"Neutral"], ParametricPlot3D[{(w/2) Cos[t],(w/2) Sin[t], b},{t,0,2Pi}, {b, -2 + w, 0}, PlotStyle->Directive[Opacity[1], Hue[a]],Mesh->None, Lighting->"Neutral"],PlotRange->All,ImageSize->{300,300}, SphericalRegion-> True]},{Row[{Text["time to empty = "], Text[2Pi (.04)/(3w^2)],Text[" seconds"]}]}}],{start,ControlType->None},{end,ControlType->None},
{{V,.01,"time (seconds)"},0.01,34,.01,ControlType->Animator,AnimationRate->1,AnimationRunning->False,ImageSize->Small},
{{w,.05,"neck width (millimeters)"}, .05, .3,.01,Appearance->"Labeled"},
{{a,0,"color of sand"}, 0, 1,Appearance->"Labeled"}]
资料来源:http ://demonstrations.wolfram.com/FlowTimeInAnHourglass/