Manipulate[
(* locator's vertical position for the incident height 'd' *)
(* horizontal position for the ray-line thickness 'th' between 0 and .01 *)
ref=1;(*"normal refractiveness"*)
If[Qangle,Which[nr==0,h={-3.9,1.0},nr==1,h={-3.9,0.86},nr==2,h={-3.9,-0.946},nr==3,h={-3.9,-0.973},nr==4,h={-3.9,0.98337},nr==5,h={-3.9,0.988627},nr==6,h={-3.9,-0.99172}]];
d=h[[2]];
(*nRays=If[ray1,1];*)
th=((.01)/3) (h[[1]]+5);
r01={-(Sqrt[1-(d^2)]),d};
r02=backReflection1[d,n0];

Which[
nr==0,
r03=r02+10 RotationTransform[ArcSin[d/n0]-ArcSin[d]][r02-r01],
nr==1,
r03=RotationTransform[2 ArcSin[d/n0],r02][r01];
r04=r03+10 RotationTransform[ArcSin[d/n0]-ArcSin[d]][r03-r02],
nr==2,
r03=RotationTransform[2 ArcSin[d/n0],r02][r01];
r04=RotationTransform[2 ArcSin[d/n0],r03][r02];
r05=r04+10 RotationTransform[ArcSin[d/n0]-ArcSin[d]][r04-r03],
nr==3,
r03=RotationTransform[2 ArcSin[d/n0],r02][r01];
r04=RotationTransform[2 ArcSin[d/n0],r03][r02];
r05=RotationTransform[2 ArcSin[d/n0],r04][r03];
r06=r05+10 RotationTransform[ArcSin[d/n0]-ArcSin[d]][r05-r04],
nr==4,
r03=RotationTransform[2 ArcSin[d/n0],r02][r01];
r04=RotationTransform[2 ArcSin[d/n0],r03][r02];
r05=RotationTransform[2 ArcSin[d/n0],r04][r03];
r06=RotationTransform[2 ArcSin[d/n0],r05][r04];
r07=r06+10 RotationTransform[ArcSin[d/n0]-ArcSin[d]][r06-r05],
nr==5,
r03=RotationTransform[2 ArcSin[d/n0],r02][r01];
r04=RotationTransform[2 ArcSin[d/n0],r03][r02];
r05=RotationTransform[2 ArcSin[d/n0],r04][r03];
r06=RotationTransform[2 ArcSin[d/n0],r05][r04];
r07=RotationTransform[2 ArcSin[d/n0],r06][r05];
r08=r07+10 RotationTransform[ArcSin[d/n0]-ArcSin[d]][r07-r06],
nr==6,
r03=RotationTransform[2 ArcSin[d/n0],r02][r01];
r04=RotationTransform[2 ArcSin[d/n0],r03][r02];
r05=RotationTransform[2 ArcSin[d/n0],r04][r03];
r06=RotationTransform[2 ArcSin[d/n0],r05][r04];
r07=RotationTransform[2 ArcSin[d/n0],r06][r05];
r08=RotationTransform[2 ArcSin[d/n0],r07][r06];
r09=r08+10 RotationTransform[ArcSin[d/n0]-ArcSin[d]][r08-r07]
];

Graphics[Which[
nr==0,
{
Lighter[ColorData["Legacy"]["LightSkyBlue"],.6],
Disk[{0,0},1],Blue,Circle[{0,0},1],Thickness[th],GrayLevel[.7],Line[{
(* mother ray starts ... *){-7,d},
(* penetrates ... *)r1={-(Sqrt[1-(d^2)]),d}}],
(* unweaves to children rays ... *)
Table[{n=ref (indexLength[λ]-1.338)+n0;
If[ref==0||nRays==1,Hue[0.8(n0-1.332)/0.011],ColorData["VisibleSpectrum"][λ]],Line[{
(* refraction I. *)r1,
(* backreflection *)r2=backReflection1[d,n],
(* *)r3=r2+10 RotationTransform[ArcSin[d/n]-ArcSin[d]][r2-r1] }]},

{λ,If[nRays==1,550,400],If[nRays==1,550,680],If[nRays==1,1,280/(nRays-1)]}
],
Thickness[0.001],Black,Dashed,If[inf,Line[{{0,0},1.4r1}]],If[inf,Line[{{0,0},1.4r2}]]
},
nr==1,
{
Lighter[ColorData["Legacy"]["LightSkyBlue"],.6],
Disk[{0,0},1],Blue,Circle[{0,0},1],Thickness[th],GrayLevel[.7],Line[{
(* mother ray starts ... *){-7,d},
(* penetrates ... *)r1={-(Sqrt[1-(d^2)]),d}}],
(* unweaves to children rays ... *)
Table[{n=ref (indexLength[λ]-1.338)+n0;
If[ref==0||nRays==1,Hue[0.8(n0-1.332)/0.011],ColorData["VisibleSpectrum"][λ]],Line[{
(* refraction I. *)r1,
(* backreflection *)r2=backReflection1[d,n],
(*  *)r3=RotationTransform[2 ArcSin[d/n],r2][r1],
(* *)r4=r3+10 RotationTransform[ArcSin[d/n]-ArcSin[d]][r3-r2] }]},

{λ,If[nRays==1,550,400],If[nRays==1,550,680],If[nRays==1,1,280/(nRays-1)]}
],
Thickness[0.001],Black,Dashed,If[inf,Line[{{0,0},1.4r1}]],If[inf,Line[{{0,0},1.4r2}]],If[inf,Line[{{0,0},1.4r3}]]
},
nr==2,
{
Lighter[ColorData["Legacy"]["LightSkyBlue"],.6],
Disk[{0,0},1],Blue,Circle[{0,0},1],Thickness[th],GrayLevel[.7],Line[{
(* mother ray starts ... *){-7,d},
(* penetrates ... *)r1={-(Sqrt[1-(d^2)]),d}}],
(* unweaves to children rays ... *)
Table[{n=ref (indexLength[λ]-1.338)+n0;
If[ref==0||nRays==1,Hue[0.8(n0-1.332)/0.011],ColorData["VisibleSpectrum"][λ]],Line[{
(* refraction I. *)r1,
(* backreflection *)r2=backReflection1[d,n],
(*  *)r3=RotationTransform[2 ArcSin[d/n],r2][r1],
(* *)r4=RotationTransform[2 ArcSin[d/n],r3][r2],
(* the end *)r5=r4+10 RotationTransform[ArcSin[d/n]-ArcSin[d]][r4-r3]}]},
{λ,If[nRays==1,550,400],If[nRays==1,550,680],If[nRays==1,1,280/(nRays-1)]}
],
Thickness[0.001],Black,Dashed,If[inf,Line[{r1/3,1.4r1}]],If[inf,Line[{r2/3,1.4r2}]],If[inf,Line[{r3/3,1.4r3}]],If[inf,Line[{r4/3,1.4r4}]],If[inf,Line[{r5/3,1.4r5}]]
},
nr==3,
{
Lighter[ColorData["Legacy"]["LightSkyBlue"],.6],
Disk[{0,0},1],Blue,Circle[{0,0},1],Thickness[th],GrayLevel[.7],Line[{
(* mother ray starts ... *){-7,d},
(* penetrates ... *)r1={-(Sqrt[1-(d^2)]),d}}],
(* unweaves to children rays ... *)
Table[{n=ref (indexLength[λ]-1.338)+n0;
If[ref==0||nRays==1,Hue[0.8(n0-1.332)/0.011],ColorData["VisibleSpectrum"][λ]],Line[{
(* refraction I. *)r1,
(* backreflection *)r2=backReflection1[d,n],
(*  *)r3=RotationTransform[2 ArcSin[d/n],r2][r1],
(* *)r4=RotationTransform[2 ArcSin[d/n],r3][r2],
(* *)r5=RotationTransform[2 ArcSin[d/n],r4][r3],
(* the end *)r6=r5+10 RotationTransform[ArcSin[d/n]-ArcSin[d]][r5-r4]}]},
{λ,If[nRays==1,550,400],If[nRays==1,550,680],If[nRays==1,1,280/(nRays-1)]}
],
Thickness[0.001],Black,Dashed,If[inf,Line[{r1/3,1.4r1}]],If[inf,Line[{r2/3,1.4r2}]],If[inf,Line[{r3/3,1.4r3}]],If[inf,Line[{r4/3,1.4r4}]],If[inf,Line[{r5/3,1.4r5}]],If[inf,Line[{r6/3,1.4r6}]]
},
nr==4,
{
Lighter[ColorData["Legacy"]["LightSkyBlue"],.6],
Disk[{0,0},1],Blue,Circle[{0,0},1],Thickness[th],GrayLevel[.7],Line[{
(* mother ray starts ... *){-7,d},
(* penetrates ... *)r1={-(Sqrt[1-(d^2)]),d}}],
(* unweaves to children rays ... *)
Table[{n=ref (indexLength[λ]-1.338)+n0;
If[ref==0||nRays==1,Hue[0.8(n0-1.332)/0.011],ColorData["VisibleSpectrum"][λ]],Line[{
(* refraction I. *)r1,
(* backreflection *)r2=backReflection1[d,n],
(*  *)r3=RotationTransform[2 ArcSin[d/n],r2][r1],
(* *)r4=RotationTransform[2 ArcSin[d/n],r3][r2],
(* *)r5=RotationTransform[2 ArcSin[d/n],r4][r3],
(* *)r6=RotationTransform[2 ArcSin[d/n],r5][r4],
(* the end *)r7=r6+10 RotationTransform[ArcSin[d/n]-ArcSin[d]][r6-r5]}]},
{λ,If[nRays==1,550,400],If[nRays==1,550,680],If[nRays==1,1,280/(nRays-1)]}
],
Thickness[0.001],Black,Dashed,If[inf,Line[{r1/3,1.4r1}]],If[inf,Line[{r2/3,1.4r2}]],If[inf,Line[{r3/3,1.4r3}]],If[inf,Line[{r4/3,1.4r4}]],If[inf,Line[{r5/3,1.4r5}]],If[inf,Line[{r6/3,1.4r6}]],If[inf,Line[{r7/3,1.4r7}]]
},
nr==5,
{
Lighter[ColorData["Legacy"]["LightSkyBlue"],.6],
Disk[{0,0},1],Blue,Circle[{0,0},1],Thickness[th],GrayLevel[.7],Line[{
(* mother ray starts ... *){-7,d},
(* penetrates ... *)r1={-(Sqrt[1-(d^2)]),d}}],
(* unweaves to children rays ... *)
Table[{n=ref (indexLength[λ]-1.338)+n0;
If[ref==0||nRays==1,Hue[0.8(n0-1.332)/0.011],ColorData["VisibleSpectrum"][λ]],Line[{
(* refraction I. *)r1,
(* backreflection *)r2=backReflection1[d,n],
r3=RotationTransform[2 ArcSin[d/n],r2][r1],
(* *)r4=RotationTransform[2 ArcSin[d/n],r3][r2],
(* *)r5=RotationTransform[2 ArcSin[d/n],r4][r3],
(* *)r6=RotationTransform[2 ArcSin[d/n],r5][r4],
(* *)r7=Evaluate[RotationTransform[2 ArcSin[d/n],r6][r5]],
(* the end *)r8=r7+10 RotationTransform[ArcSin[d/n]-ArcSin[d]][r7-r6]}]},
{λ,If[nRays==1,550,400],If[nRays==1,550,680],If[nRays==1,1,280/(nRays-1)]}
],
Thickness[0.001],Black,Dashed,If[inf,Line[{r1/3,1.4r1}]],If[inf,Line[{r2/3,1.4r2}]],If[inf,Line[{r3/3,1.4r3}]],If[inf,Line[{r4/3,1.4r4}]],If[inf,Line[{r5/3,1.4r5}]],If[inf,Line[{r6/3,1.4r6}]],If[inf,Line[{r7/3,1.4r7}]],If[inf,Line[{r8/3,1.4r8}]]
},
nr==6,
{
Lighter[ColorData["Legacy"]["LightSkyBlue"],.6],
Disk[{0,0},1],Blue,Circle[{0,0},1],Thickness[th],GrayLevel[.7],Line[{
(* mother ray starts ... *){-7,d},
(* penetrates ... *)r1={-(Sqrt[1-(d^2)]),d}}],
(* unweaves to children rays ... *)
Table[{n=ref (indexLength[λ]-1.338)+n0;
If[ref==0||nRays==1,Hue[0.8(n0-1.332)/0.011],ColorData["VisibleSpectrum"][λ]],Line[{
(* refraction I. *)r1,
(* backreflection *)r2=backReflection1[d,n],
(*  *)r3=RotationTransform[2 ArcSin[d/n],r2][r1],
(* *)r4=RotationTransform[2 ArcSin[d/n],r3][r2],
(* *)r5=RotationTransform[2 ArcSin[d/n],r4][r3],
(* *)r6=RotationTransform[2 ArcSin[d/n],r5][r4],
(* *)r7=RotationTransform[2 ArcSin[d/n],r6][r5],
(* *)r8=RotationTransform[2 ArcSin[d/n],r7][r6],
(* the end *)r9=r8+10 RotationTransform[ArcSin[d/n]-ArcSin[d]][r8-r7]}]},
{λ,If[nRays==1,550,400],If[nRays==1,550,680],If[nRays==1,1,280/(nRays-1)]}
],
Thickness[0.001],Black,Dashed,If[inf,Line[{r1/3,1.4r1}]],If[inf,Line[{r2/3,1.4r2}]],If[inf,Line[{r3/3,1.4r3}]],If[inf,Line[{r4/3,1.4r4}]],If[inf,Line[{r5/3,1.4r5}]],If[inf,Line[{r6/3,1.4r6}]],If[inf,Line[{r7/3,1.4r7}]],If[inf,Line[{r8/3,1.4r8}]],If[inf,Line[{r9/3,1.4r9}]]
}
],
PlotRange->{{-4,1.8},{-2,1.2}},

ImageSize->600,AspectRatio->Automatic,Axes->False,

Prolog->If[inf&& (Abs[n0-1.338]<0.001),

Text[Style[Which[
nr==0,"Maximal (Subscript[φ, 0])=83.27° (y=1) n=1.338" ,
nr==1,"Maximal (Subscript[φ, 1])=41.36° (y=0.86) n=1.338",
nr==2,"Minimal (Subscript[φ, 2])=52.21° (y=-0.946) n=1.338",
nr==3,"Maximal (Subscript[φ, 3])=39.88° (y=-0.973) n=1.338 (observed in Sun direction)",
nr==4,"Minimal (Subscript[φ, 4])=46.04° (y=0.983) n=1.338 (observed in Sun direction)",
nr==5,"Maximal (Subscript[φ, 5])=48.72° (y=0.989) n=1.338",
nr==6,"Minimal (Subscript[φ, 6])=35.65° (y=0.992) n=1.338" 
],16,Bold],{-1.5,1.1} ],

Text[Style[Which[inf&&nr==1,"Maximal (Subscript[φ, 1])=22.84° (y=0.765) n=1.5 (glass sphere)",inf&&nr==2,"Maximal (Subscript[φ, 1])=86.87° (y=-0.922) n=1.5 (glass sphere)",True,""],16,Bold],{-1.5,1.1} ]

], 
Epilog->{Gray,If[inf,Text[
Style[Which[
nr==0,"(Subscript[φ, 0]) = "<> ToString[Round[180/Pi ArcTan[-(r03[[2]]-r02[[2]])/(r03[[1]]-r02[[1]])],0.01]]<>"°" <>"  y="<>ToString[Round[d,0.001]] ,
nr==1,"(Subscript[φ, 1]) = "<> ToString[Round[180/Pi ArcTan[(r04[[2]]-r03[[2]])/(r04[[1]]-r03[[1]])],0.01]]<>"°" <>"  y="<>ToString[Round[d,0.001]] ,
nr==2,"(Subscript[φ, 2]) = "<>ToString[Round[180/Pi ArcTan[(r05[[2]]-r04[[2]])/(r05[[1]]-r04[[1]])],0.01]]<>"°" <>"  y="<>ToString[Round[d,0.001]],
nr==3,"(Subscript[φ, 3]) = "<>ToString[Round[180/Pi ArcTan[-(r06[[2]]-r05[[2]])/(r06[[1]]-r05[[1]])],0.01]]<>"°" <>"  y="<>ToString[Round[d,0.001]],
nr==4,"(Subscript[φ, 4]) = "<>ToString[Round[180/Pi ArcTan[-(r07[[2]]-r06[[2]])/(r07[[1]]-r06[[1]])],0.01]]<>"°" <>"  y="<>ToString[Round[d,0.001]],
nr==5,"(Subscript[φ, 5]) = "<>ToString[Round[180/Pi ArcTan[(r08[[2]]-r07[[2]])/(r08[[1]]-r07[[1]])],0.01]]<>"°" <>"  y="<>ToString[Round[d,0.001]],
nr==6,"(Subscript[φ, 6]) = "<>ToString[Round[180/Pi ArcTan[(r09[[2]]-r08[[2]])/(r09[[1]]-r08[[1]])],0.01]]<>"°"<>"  y="<>ToString[Round[d,0.001]]
 ],16,Bold],{-2.5,0.5}]],source[h,0.1]
}],
{{h,{-3.8,(*3-2nr*) 0.75}},{-4,- 1},{-2.5,1},Locator},
Row[{(*Control[{{ref,1,"refractiveness"},0,5,1,Appearance->"Labeled",ImageSize->Tiny}],*)
Control[{{nRays,20,"number of rays"},1,50,1,Appearance->"Labeled",ImageSize->Tiny}],
Control[{{n0,1.338,"refraction coefficient"},0.76,2,0.002,Appearance->"Labeled",ImageSize->Tiny, Enabled->True}],
Control[{{n0,1.338,""},{1.338-> Style["Water",11], 1.5-> Style["Glass", 11]},ControlType->Setter}],
Control[{{inf, False, "    info"}, {True, False}}]
}],
Row[{
Control[{{nr,1," rainbow"},{0->"0",1->"1",2->"2",3->"3",4->"4",5->"5",6->"6"},ControlType->Setter}],
Control[{{Qangle, False, " crucial angle"}, {True, False}}],

Control[{{n0,1.338,"      colour "},{(*1.33/1.00022->Style["ІЧ",If[nRays==1,{Bold,RGBColor[0.2,0,0]},Black],13],*)1.3312/1.00022->Style["red",If[nRays==1,{Bold,Red},Black],13],1.3335->Style["orange",If[nRays==1,{Bold,Orange},Black],13],1.3342->Style["yellow",If[nRays==1,{Bold,Yellow},Black],13],1.338->Style["green",If[nRays==1 ,{Bold,Green},Black],13],1.340->Style["blue",If[nRays==1,{Bold,Hue[0.53]},Black],13],1.3415->Style[ "indigo",If[nRays==1,{Bold,Hue[0.7]},Black],13],1.3435/1.00028->Style["violet",If[nRays==1,{Bold,Hue[0.88]},Black],13]},ControlType->Setter,Enabled->nRays==1 && Abs[n0-1.338]<0.01}]
}],
Initialization:>{
source[{x0_,y0_},r0_]:={Hue[0.12],Disk[{x0,y0},r0],Thickness[0.002],Arrowheads[0.02], Arrow[{{x0,y0},{x0+3r0,y0}}],Line[{{x0,y0},{x0-2r0,y0}}],Line[{{x0,y0},{x0,y0+2r0}}],Line[{{x0,y0},{x0,y0-2r0}}],Line[{{x0,y0},{x0-1.6r0,y0-1.6r0}}],Line[{{x0,y0},{x0+1.6r0,y0-1.6r0}}],Line[{{x0,y0},{x0-1.6r0,y0+1.6r0}}],Line[{{x0,y0},{x0+1.6r0,y0+1.6r0}}]};
(* water refractive index as a function of wavelength *)
indexLength=Interpolation[{
{303.4,1.3581/1.0003},
{380,1.3447/1.0003},
{396.847,1.3435/1.00029},
{434.047,1.3404/1.00029},
{486.134,1.3372/1.00028},
{589.3,1.3330/1.00028},
{656.281,1.3312/1.00027},
{700,1.3303/1.00027},
{1256,1.321/1.00026}
}];
(* point of reflection off the raindrop back *)
backReflection1=Compile[{{d,_Real},{n,_Real}},Block[{α=ArcSin[d],β=ArcSin[d/n],x1=-(Sqrt[1-(d^2)]),y1=d,k1=Tan[α-β],x2},x2=((k1(k1 x1+y1)+(Sqrt[1+(k1^2)-(((k1 x1+y1))^2)]))/(1+(k1^2)));  {x2,y1-k1(x2-x1)}]]

},

Bookmarks->{
"rainbow 0":>{ref=1,nRays=20,nr=0,n0=1.338,h={-3.9,1.0}},
"rainbow 1":>{ref=1,nRays=20,nr=1,n0=1.338,h={-3.9,0.86}},
"rainbow 2":>{ref=1,nRays=20,nr=2,n0=1.338,h={-3.9,-0.946}},
"rainbow 3":>{ref=1,nRays=20,nr=3,n0=1.338,h={-3.9,-0.973}},
"rainbow 4":>{ref=1,nRays=20,nr=4,n0=1.338,h={-3.9,0.98337}},
"rainbow 5":>{ref=1,nRays=20,nr=5,n0=1.338,h={-3.9,0.988627}},
"rainbow 6":>{ref=1,nRays=20,nr=6,n0=1.338,h={-3.9,-0.99172}},
"rainbow 1 for glass sphere":>{ref=1,nRays=20,nr=1,n0=1.5,h={-3.9,0.765}},
"rainbow 2 for glass sphere":>{ref=1,nRays=20,nr=2,n0=1.5,h={-3.9,-0.922}}
},
TrackedSymbols:>{ref,nRays,nr,inf,h,n0,ray1,Qangle}]