Skip to content

Instantly share code, notes, and snippets.

@matthen
Created August 27, 2024 11:01
Show Gist options
  • Save matthen/3c4d7ec21c2798c95e526fa0639194f9 to your computer and use it in GitHub Desktop.
Save matthen/3c4d7ec21c2798c95e526fa0639194f9 to your computer and use it in GitHub Desktop.
(* code for https://x.com/matthen2/status/1828043142592934302 *)
n2 = 1.4;
f2 = 0.6;
dx = 0.05;
bgcolor = RGBColor[0., 0.03, 0.06];
wave[x_] := Sin[2 Pi x];
Manipulate[
Graphics[{
GeometricTransformation[{
{
(* stationary wave *)
RGBColor[0.98, 0.98, 0.18],
Thick,
Line[Table[{x, wave[ f2 n2 x]}, {x, 0, 20, dx}]]
},
{
(*moving wave*)
RGBColor[0.5, 0.91, 1.],
Thick,
{Line[Table[{x, wave[ ((x + t/n2) - t)]}, {x, 0, 20, dx}]]},
EdgeForm[Directive[Thick, bgcolor]],
Table[
Disk[{t + i - 0. - t/n2, 0}, 0.15],
{i, -2, 20, 1}]
}
},
TranslationTransform[{0, 3}]
],
GeometricTransformation[
{
(* interference wave *)
RGBColor[0.04, 0.95, 0.53],
Thick,
{Line[
Table[{x, wave[ f2 n2 x] + wave[ ((x + t/n2) - t)]}, {x, 0, 20,
dx}]]},
EdgeForm[bgcolor],
Table[Disk[{12.5 (i - 0.25) + 1.8 t, 0}, 0.3], {i, -2, 2, 0.5}]
},
TranslationTransform[{0, -1}]
],
GeometricTransformation[
{Thickness[0.01],
{RGBColor[0.04, 0.95, 0.53], Line[{{0, 0}, {2, 0}}]},
{White, Text[Style["=", FontSize -> 18], {3, 0}]},
{
RGBColor[0.98, 0.98, 0.18], Line[{{4, 0}, {6, 0}}]},
{White, Text[Style["+", FontSize -> 18], {7, 0}]},
{RGBColor[0.5, 0.91, 1.], Line[{{8, 0}, {10, 0}}]}
},
TranslationTransform[{5, -6}]
]
},
PlotRange -> {{0, 20}, {-8, 8}},
Background -> bgcolor,
ImageSize -> 512
],
{t, 0, 3.5}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment