Advertisement
Matthen

Interference

Feb 14th, 2015
1,141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. dx = 0.05;
  2. xmax = Pi;
  3. colorscheme = "BlueGreenYellow";
  4. (*t, (y, \[Theta])*)
  5. points = {
  6. {0, {2.5, 0}},
  7. {1, {0.5, 0}},
  8. {2, {2.5, 0}},
  9. {3, {2.5, 0.448}},
  10. {4, {0.5, 0.448}},
  11. {5, {2.5, 0.448}},
  12. {6, {2.5, 0.5}},
  13. {7, {0.5, 0.5}},
  14. {8, {2.5, 0.5}},
  15. {9, {2.5, 1}}
  16. };
  17. f = Interpolation[points, InterpolationOrder -> 1];
  18. \[Tau][t_] := Sum[0.5 + 0.5 Tanh[6 (t - i - 0.5)], {i, 0, 9}];
  19. frame[t_] :=
  20.  
  21. With[{y = f[\[Tau][t]][[1]], \[Theta] = f[\[Tau][t]][[2]]},
  22. Graphics[{
  23. (*wave 2*){
  24. EdgeForm[Black],
  25. Table[{
  26. FaceForm[ColorData[colorscheme][0.5 + 0.5 Sin[2 Pi x]]],
  27. Rectangle[{x,
  28. Max[y , 1 + 0.5 Sin[2 Pi (x - \[Theta])]]}, {x + dx,
  29. Max[y , 1 + 0.5 Sin[2 Pi (x - \[Theta])]] +
  30. 1 + 0.5 Sin[2 Pi x]}]
  31. }
  32. , {x, 0, xmax, dx}]
  33. },
  34. (*wave 1*){
  35. EdgeForm[Black],
  36. Table[{
  37. FaceForm[
  38. ColorData[colorscheme][0.5 + 0.5 Sin[2 Pi (x - \[Theta])]]],
  39. Rectangle[{x, 0}, {x + dx,
  40. 1 + 0.5 Sin[2 Pi ( x - \[Theta])]}]
  41. }
  42. , {x, 0, xmax, dx}]
  43. }
  44. }, PlotRange -> {{0, xmax}, {0, 4}}, AspectRatio -> 0.6]
  45. ];
  46. Manipulate[frame[t], {t, 0, 9}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement