# Untitled

a guest
Apr 10th, 2021
2,151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. Clear[orbit]; Clear[eqns]; Clear[soln];
2. (* fudge an orbit *)
3. {x0, y0} = {-1.2, 1.2}; {v0x, v0y} = {0.4, 0.4};
4. eqns = {x[0] == x0, y[0] == y0, x'[0] == v0x, y'[0] == v0y,
5. x''[t] == -x[t]/(x[t]^2 + y[t]^2)^1.5,
6. y''[t] == -y[t]/(x[t]^2 + y[t]^2)^1.5};
7. soln = Map[
9. First[NDSolve[eqns, {x[t], y[t]}, {t, 0, 10}]]];
10. eartht = 6.72801;
11. earth = {-Cos[2 Pi #/eartht], Sin[2 Pi #/eartht]} &;
12. cruithne[t_] :=
13. With[{tt = Mod[t, eartht]}, {soln[[1]][eartht tt/5.76],
14. soln[[2]][eartht tt/5.76]}];
15. bg = RGBColor[0., 0.05, 0.1];
16. smoothstep[t_, t0_, t1_] :=
17. With[{tt = (t - t0)/(t1 - t0)},
18. If[tt < 0, 0, If[tt > 1, 1, 6 tt^5 - 15 tt^4 + 10 tt^3]]];
19. smoothstepI[t_, t0_, t1_] :=
20. If[(t - t0) (t0 - t1) > 0, 0,
21. If[(t - t1) (-t0 + t1) > 0,
22. 1/2 (2 (t - t1) + t1 -
23. t0), -(((t - t0)^4 (2 t^2 + t0^2 + 2 t (t0 - 3 t1) - 4 t0 t1 +
24. 5 t1^2))/(2 (t0 - t1)^5))]];
25. t0 = 2.5;
26. t1 = 3;
27. t2 = 4;
28. t3 = 7;
29. t4 = 7.5;
30. t5 = 8;
31. nstars = 20;
32. stars = RandomReal[{-3, 3}, {nstars, 2}];
33. starsizes = RandomReal[{0, 1}, nstars];
34.
35. transform[T_] := RotationTransform[2 Pi (
36. smoothstepI[ T/eartht, 2.5, 3]
37. - smoothstepI[T/eartht, t4, t5]
38. ), {0,
39. 0}].ScalingTransform[(1 +
40. 0.2 (smoothstep[T/eartht, t0, t1] -
41. smoothstep[T/eartht, t4, t5])) {1,
42. 1}].TranslationTransform[-(smoothstep[T/eartht, t0, t1] -
43. smoothstep[T/eartht, t4, t5]) earth[T]];
44. daylight[p_, r_, col_] := {
45. Lighter@col, Disk[p, r], Darker@col, EdgeForm[],
46. GeometricTransformation[
47. Disk[p, r, {0, Pi}],
48. RotationTransform[{{0, 1}, Normalize[p]}, p]
49. ]
50. };
51.
52. frame[T_] := (Show[
53. Graphics[{},
54. Background -> RGBColor[0., 0.05, 0.1],
55. PlotRange -> 2.0],
56. ParametricPlot[
57. transform[T - t][cruithne[T - t]],
58. {t, 0,
59. Min[eartht,
60. Max[0.001, Min[T - t2 eartht, 2 (t3 eartht - T)]]]},
61. PlotStyle -> White
62. ],
63. Graphics[
64. GeometricTransformation[
65. {
66. White,
67. {Table[{ColorData["StarryNightColors"][starsizes[[i]]],
68. AbsolutePointSize[1 + 2 starsizes[[i]]],
69. Point[stars[[i]]]}, {i, nstars}]},
70. EdgeForm[Directive[AbsoluteThickness[2], bg]],
71. {RGBColor[0.98, 1., 0.83], Disk[{0, 0}, 0.2]},
72. {daylight[earth[T], 0.06, RGBColor[0.17, 0.59, 1.]]},
73. {daylight[cruithne[T], 0.04, RGBColor[1., 0.8, 0.65]]}
74. },
75. transform[T]
76. ]
77. ]
78. ]);
79. Manipulate[
80. frame[T],
81. {T, 0, t5 eartht}
82. ]