Advertisement
Matthen

Bouncing explosion

Sep 25th, 2012
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. (* this code is really slow, and could be sped up by caching the number of bounces before t calculation*)
  2. g = 0.05;
  3. c = 0.9;
  4. path[vx_, t_] :=
  5.  
  6. Module[{\[Tau] = (2 Sqrt[1 - vx^2])/g, found, m, prev},
  7. found = False; m = 0; prev = 0; While[found == False && m < 100,
  8. found = Sum[(2 c ^n Sqrt[1 - (vx)^2])/g, {n, 0, m}] > t; m++;
  9. If[! found,
  10. prev = Sum[(2 c ^n Sqrt[1 - (vx)^2])/g, {n, 0, m - 1}];];];
  11. \[Tau] = Sum[(2 c ^n Sqrt[1 - (vx)^2])/g, {n, 0, m - 1}];
  12. {vx t, (c^(m - 1) Sqrt[1 - (vx) ^2] tt - 1/2 g tt^2) /. {tt ->
  13. t - prev}}];
  14. xmax = 50;
  15. anim[T_] :=
  16. Show[
  17. Table[
  18. ParametricPlot[path[vx, t], {t, 0, T},
  19. PlotRange -> {{-xmax, xmax}, {-1, 10}}, Axes -> None,
  20. PlotStyle -> RGBColor[0.8, 0.6, 0.3]],
  21. {vx, -0.9, 0.9, 1.8/40}
  22. ],
  23. Graphics[
  24. {Thick, RGBColor[0.6, 0.8, 0.9],
  25. Line[{{-xmax, 0}, {xmax, 0}}],
  26. Black, PointSize[Medium],
  27. Table[
  28. Point[path[vx, T]]
  29. ,
  30. {vx, -0.9, 0.9, 1.8/40}
  31. ]
  32. }]
  33. , ImageSize -> 300, AspectRatio -> 1];
  34. frames = Table[Rasterize@anim[x], {x, 0.01, 100}];
  35. Export["bounces.gif", frames];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement