Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Clear[orbit]; Clear[eqns]; Clear[soln];
- (* fudge an orbit *)
- {x0, y0} = {-1.2, 1.2}; {v0x, v0y} = {0.4, 0.4};
- eqns = {x[0] == x0, y[0] == y0, x'[0] == v0x, y'[0] == v0y,
- x''[t] == -x[t]/(x[t]^2 + y[t]^2)^1.5,
- y''[t] == -y[t]/(x[t]^2 + y[t]^2)^1.5};
- soln = Map[
- Head, {x[t], y[t]} /.
- First[NDSolve[eqns, {x[t], y[t]}, {t, 0, 10}]]];
- eartht = 6.72801;
- earth = {-Cos[2 Pi #/eartht], Sin[2 Pi #/eartht]} &;
- cruithne[t_] :=
- With[{tt = Mod[t, eartht]}, {soln[[1]][eartht tt/5.76],
- soln[[2]][eartht tt/5.76]}];
- bg = RGBColor[0., 0.05, 0.1];
- smoothstep[t_, t0_, t1_] :=
- With[{tt = (t - t0)/(t1 - t0)},
- If[tt < 0, 0, If[tt > 1, 1, 6 tt^5 - 15 tt^4 + 10 tt^3]]];
- smoothstepI[t_, t0_, t1_] :=
- If[(t - t0) (t0 - t1) > 0, 0,
- If[(t - t1) (-t0 + t1) > 0,
- 1/2 (2 (t - t1) + t1 -
- t0), -(((t - t0)^4 (2 t^2 + t0^2 + 2 t (t0 - 3 t1) - 4 t0 t1 +
- 5 t1^2))/(2 (t0 - t1)^5))]];
- t0 = 2.5;
- t1 = 3;
- t2 = 4;
- t3 = 7;
- t4 = 7.5;
- t5 = 8;
- nstars = 20;
- stars = RandomReal[{-3, 3}, {nstars, 2}];
- starsizes = RandomReal[{0, 1}, nstars];
- transform[T_] := RotationTransform[2 Pi (
- smoothstepI[ T/eartht, 2.5, 3]
- - smoothstepI[T/eartht, t4, t5]
- ), {0,
- 0}].ScalingTransform[(1 +
- 0.2 (smoothstep[T/eartht, t0, t1] -
- smoothstep[T/eartht, t4, t5])) {1,
- 1}].TranslationTransform[-(smoothstep[T/eartht, t0, t1] -
- smoothstep[T/eartht, t4, t5]) earth[T]];
- daylight[p_, r_, col_] := {
- Lighter@col, Disk[p, r], Darker@col, EdgeForm[],
- GeometricTransformation[
- Disk[p, r, {0, Pi}],
- RotationTransform[{{0, 1}, Normalize[p]}, p]
- ]
- };
- frame[T_] := (Show[
- Graphics[{},
- Background -> RGBColor[0., 0.05, 0.1],
- PlotRange -> 2.0],
- ParametricPlot[
- transform[T - t][cruithne[T - t]],
- {t, 0,
- Min[eartht,
- Max[0.001, Min[T - t2 eartht, 2 (t3 eartht - T)]]]},
- PlotStyle -> White
- ],
- Graphics[
- GeometricTransformation[
- {
- White,
- {Table[{ColorData["StarryNightColors"][starsizes[[i]]],
- AbsolutePointSize[1 + 2 starsizes[[i]]],
- Point[stars[[i]]]}, {i, nstars}]},
- EdgeForm[Directive[AbsoluteThickness[2], bg]],
- {RGBColor[0.98, 1., 0.83], Disk[{0, 0}, 0.2]},
- {daylight[earth[T], 0.06, RGBColor[0.17, 0.59, 1.]]},
- {daylight[cruithne[T], 0.04, RGBColor[1., 0.8, 0.65]]}
- },
- transform[T]
- ]
- ]
- ]);
- Manipulate[
- frame[T],
- {T, 0, t5 eartht}
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement