This version was saved 2023-03-10 at 9:00 am.
Run this first cell, which defines the functions.  Then go to the next cell to make an animation.
If you want to save animated gifs, use “Insert file path” to put in the directory where you want them saved.  Do this in the first line of this first cell.

SetDirectory["/Users/jimswift/Library/CloudStorage/Dropbox/classes/MAT 667 2023.1/mathematica stuff/"];SetDirectory["C:\\Users\\jws8\\Dropbox\\classes\\MAT 667 2023.1\\mathematica stuff\\"];frame[θ0_, ω0_, n_] := (* Global variables: Δω, T *)
Module[{θ, ω, k = Δω T, iMin, iMax, r = 0.1 (* radius of ball which gets kicked *), xyBall, framesPerIteration = 10 T},
ω = ω0 - Δω Sin[θ0];  (* ω = ω1 in the unscaled standard map*)
θ = θ0 + ω (n/framesPerIteration) T; (* θ = θ1 in the unscaled standard map when n = framesPerIteration *)
(* Arm of the rotor at angle Θ, measured CCW from straight down *)
xyBall = {Sin[θ], -Cos[θ]};
iMin = Ceiling[((-π)/(2k))];
iMax = Floor[(π/(2k))-(1/2)];
Graphics[{Yellow,
Table[Disk[{0,0}, 1, {-π/2  + 2i k, -π /2+ (2i+1)k}], {i,iMin,iMax}],
Green, 
Table[Disk[{0,0}, 1, {-π/2  - 2i k, -π /2- (2i+1)k}], {i,iMin,iMax}],
Black, Text[Style["Standard Map with k = "<>ToString[Δω T], Large], {0, 1+ 3r}],Thickness[0.02],CapForm["Round"],Line[{{0,0}, {Sin[θ], -Cos[θ]}}], 
(*If[n==0, Red, Null],*)
Disk[xyBall, r],
If[n==0, {Red,Arrowheads[r],Arrow[{xyBall + {0, 4r}, xyBall+{0, r}}]}, Null](* make the ball orange when it gets the kick at 0th frame *)
}, PlotRange ->(1.05+r){{-1,1}, {-1,1+2r}}]
];
f[θ_, ω_] :=(* The kicked rotor map, with the single parameter k = Δω T , and the scaled momentum p = ωT.  Note that k is a global variable. *)
Module[{ωp}, 
ωp = ω - Δω* Sin[θ]; 
{θ+ωp*T, ωp}];
makeMovie := (* Global variables: movieFrames, θ, ω, function f[ , ], exportGif, movieName*)
Module[{exportTime, dummy, framesPerIteration = 10 T}, 
movieFrames = {};
Do[AppendTo[movieFrames,
Table[frame[θ, ω, n], {n, 0, framesPerIteration-1}] ];
{θ, ω} = f[θ, ω],
numIterations];
movieFrames = Flatten[movieFrames];
Print["k = Δω T = ", Δω T]; 
Print["The number of frames is  T * numInterations * 10 framesPerSecond = ",  Length[movieFrames]];
If[exportGif, Print["Exporting animated gif. This may take a while."];{exportTime, dummy} =Timing[Export[movieName, movieFrames]];
Print["That took ", exportTime, " seconds."]];
ListAnimate[movieFrames, 10] 
];

Now for an animation.  First define the global variables listed, then run the cell.  If you want to export an animated gif
Beware that it takes a while to export a movie with many frames, and the file can be large.

Δω = Pi/20.; (* the maximum change of angular velocity from the kick, which occurs when sin(θ) = -1 *)
T = 5; (* the time between kicks, in seconds.*)
(* Note that k = Δω T is the angle traversed between kicks if ω = Δω *)
numIterations = 2;  (* number of iterations (or kicks) in the whole animation *)
θ = Pi;  (* Initial angle, in radians *)
ω =π/5; (* initial angular velocity, in radians per second.*)

exportGif = False;  
(* If you make this true, either give a unique name or change name after it is exported. Export will over-write the file silently. *)
movieName = "kanythingPeriod2.gif";

makeMovie

Δω = 2Pi/5; (* the maximum change of angular velocity from the kick, which occurs when sin(θ) = -1 *)
T = 5; (* the time between kicks, in seconds.  The movie is made with 10 frames per second*)
(* Note that k = Δω T is the angle traversed between kicks if ω = Δω *)
numIterations = 2;  (* number of iterations (or kicks) in the whole animation *)
θ = Pi/2;  (* Initial angle, in radians *)
ω =Pi/5; (* initial angular velocity, in radians per second.*)

exportGif = False;  
(* If you make this true, either give a unique name or change name after it is exported. Export will over-write the file silently. *)
movieName = "k2piPeriod2.gif";

(* Change the parameters above this line *)

makeMovie

Δω = 0.35; (* the maximum change of angular velocity from the kick, which occurs when sin(θ) = -1 *)
T = 2; (* the time between kicks, in seconds.*)
(* Note that k = Δω T is the angle traversed between kicks if ω = Δω *)
numIterations = 10;  (* number of iterations (or kicks) in the whole animation *)
θ = 2.0505;  (* Initial angle, in radians *)
ω =0.15095; (* initial angular velocity, in radians per second.*)

exportGif = False;  
(* If you make this true, either give a unique name or change name after it is exported. Export will over-write the file silently. *)
movieName = "k7period10.gif";

makeMovie

This cell shows how the angle of the yellow and green sectors are k = Δω T.  
Before the first kick, the angle is θ = -π/2 and the angular velocity is ω = 0.  After the kick, the angular velocity is ω  = Δω.  In time T, the angle changes by k = Δω T, to θ = 0.

Δω = π/6.; (* the maximum change of angular velocity from the kick, which occurs when sin(θ) = -1 *)
T = 3; (* the time between kicks, in seconds.*)
(* Note that k = Δω T is the angle traversed between kicks if ω = Δω *)
numIterations = 6;  (* number of iterations (or kicks) in the whole animation *)
θ = -π/2;  (* Initial angle, in radians *)
ω =0; (* initial angular velocity, in radians per second.*)

exportGif = False;  
(* If you make this true, either give a unique name or change name after it is exported. Export will over-write the file silently. *)
movieName = "kpi2period6.gif";

makeMovie

The next cell finds an approximate solution to the ODE.  There is a kick every frame.  I

Δω = .5; (* the maximum change of angular velocity from the kick, which occurs when sin(θ) = -1 *)
T = .1; (* the time between kicks, in seconds.*)
(* Note that k = Δω T is the angle traversed between kicks if ω = Δω *)
numIterations = 60;  (* number of iterations (or kicks) in the whole animation *)
θ = 0;  (* Initial angle, in radians *)
ω =4.408; (* initial angular velocity, in radians per second.*)

exportGif = False;  
(* If you make this true, either give a unique name or change name after it is exported. Export will over-write the file silently. *)
movieName = "k05period60.gif";

makeMovie

GraphicsRow[{movieFrames[[-1]],
movieFrames[[1]],
movieFrames[[2]]}]

This next one shows the mass going over the top.  I didn’t have enough space to save this animated gif to my web site!

Δω = .5; (* the maximum change of angular velocity from the kick, which occurs when sin(θ) = -1 *)
T = .1; (* the time between kicks, in seconds.*)
(* Note that k = Δω T is the angle traversed between kicks if ω = Δω *)
numIterations = 40;  (* number of iterations (or kicks) in the whole animation *)
θ = 0;  (* Initial angle, in radians *)
ω =4.458; (* initial angular velocity, in radians per second.*)

exportGif = False;  
(* If you make this true, either give a unique name or change name after it is exported. Export will over-write the file silently. *)
movieName = "k05period40.gif";

makeMovie

GraphicsRow[{movieFrames[[-1]],
movieFrames[[1]],
movieFrames[[2]]}]