Skip to content

Instantly share code, notes, and snippets.

@quephird
Last active August 7, 2017 04:54
Show Gist options
  • Save quephird/786700c97bcd70b4b61b3c89f34ffb96 to your computer and use it in GitHub Desktop.
Save quephird/786700c97bcd70b4b61b3c89f34ffb96 to your computer and use it in GitHub Desktop.
Torus[r1_, r2_, c_] :=
(* Produces a torus with major radius r1 and minor radius r2,
with surface color c and parallel with the xy plane. *)
ParametricPlot3D[
{Cos[t] (r1 + r2 Cos[u]), Sin[t] (r1 + r2 Cos[u]), Sin[u]},
{t, 0, 2 Pi}, {u, 0, 2 Pi},
ColorFunction -> (c &),
Mesh -> None,
PlotPoints -> 10,
PlotRange -> {{-3, 3}, {-3, 3}, {-3, 3}}]
TorusRing[c_, dθ_, dt_] :=
(* Produces a ring of 12 tori with varying major radii.
c - the color of each torus
dθ - the initial angular offset of the entire ring
dt - intended to control the spinning of the ring as well as the
growing and shrinking of each torus. *)
Graphics3D[
Table[
Translate[
First@
Torus[1.5 + 1.5 Sin[2 θ] + 2 dt], 1, c],
{15 Cos[θ] + dθ + dt], 15 Sin[θ] + dθ + dt], 0}],
{θ, 0, 2 Pi, Pi/6}]]
ThreeRings[c1_, c2_, c3_, dt_] :=
(* Produces three intersecting rings, one parallel to the xy plane,
one in the plane that intersects the line y=x,
and the third in the plane that intersect the line y=-x.
c1, c2, c3 - are all Mathematica Hue or name color values
dt - controls the rotation and size of each torus for each of the
rings. *)
Graphics3D[
{First@TorusRing[c1, 0, dt],
Rotate[
First@TorusRing[c2, Pi/2, dt], Pi/2, {1, -1, 0}] ,
Rotate[
First@TorusRing[c3, Pi/2, dt], Pi/2, {-1, -1, 0}]}]
Export["/torus_rings.gif",
Table[
Graphics3D[
First@ThreeRings[
Hue[0.4, 0.7, 0.5],
Hue[0.05, 0.7, 0.9],
Hue[0.6, 0.7, 0.5],
dt],
Background -> Black,
Boxed -> False,
ImageSize -> {600, 600},
ViewAngle -> 0.25,
ViewPoint -> {5 Sin[dt], 5 Cos[dt], 1}],
{dt, 0, 2 Pi, 0.01 Pi}],
"DisplayDurations" -> 0.05]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment