Skip to content

Instantly share code, notes, and snippets.

@Eckankar
Created April 18, 2014 22:33
Show Gist options
  • Select an option

  • Save Eckankar/11067185 to your computer and use it in GitHub Desktop.

Select an option

Save Eckankar/11067185 to your computer and use it in GitHub Desktop.
Making wave animations in Mathematica
circleLine[x_, y_, s_] :=
Module[{d = 3/2*Sin[s + (x/2 + y)/10*Pi] + 3/2},
Graphics[
If[{x, y} == {7, 7}, {LightGray, Line[{{x, y}, {x + 3, y - 3}}],
Red}, {}]~Join~
{Circle[{x + d, y - d}, 0.1]}
]
];
frames = Table[
Show[
Table[circleLine[x, y, s], {x, -5, 20}, {y, -5, 20}],
PlotRange -> {{0, 15}, {0, 15}}
],
{s, 0, 2 Pi, Pi/16}
];
Export[NotebookDirectory[] <> "waves-line.gif", frames,
"DisplayDuration" -> 0.1]
circleCirc[x_, y_, s_] := Module[{s2 = s + (x/2 + y)/10*Pi},
Graphics[
If[{x, y} == {7, 7}, {LightGray, Circle[{x, y}, 2], Red}, {}]~Join~
{Circle[{x + 2*Cos[s2], y + 2*Sin[s2]}, 0.1]}
]
];
frames = Table[
Show[
Table[circleCirc[x, y, s], {x, -5, 20}, {y, -5, 20}],
PlotRange -> {{0, 15}, {0, 15}}
],
{s, 0, 2 Pi, Pi/16}
];
Export[NotebookDirectory[] <> "waves2-circ.gif", frames,
"DisplayDuration" -> 0.1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment