(*© 2012-Present Computational ClassNotes, lossofgenerality.org, Creative Commons License *)
(*https://creativecommons.org/licenses/by-nc-sa/3.0/us/  :  Attribution-NonCommercial-ShareAlike *)

SetOptions[EvaluationNotebook[],Background->LightGray]

Cloud Libraries

CloudGet["https://www.wolframcloud.com/objects/ccn/module/v5"]
init[]
CloudGet["https://www.wolframcloud.com/objects/ccn/module/geometry/triangle"]
init[]

Logic and Word Functions

logic1[ctr_,mywords_,abcd_]:=Module[{correct,vv,words,wrong,vars,aa,a,b,c,example,choices,molecule={},wrongmolecule={},fastest,name,v,vfastest},


vv=Release@Map[Hold[RandomChoice@{ToUpperCase,ToLowerCase}],RandomSample[Complement[CharacterRange["a","z"],{"l","o", "i","e"}],1]];


correct={};
wrong={{},{},{}};
choices=Join[{correct},wrong];
While[Or@@(#[[1]]===#[[2]]&/@Permutations[choices, {2}]),


correct=Column@{

fastest="";
vfastest=0;
name="Io";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Europa";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Ganymede";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Callisto";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
Row@{fastest, " has the fastest linear speed."}

};


wrong={


Column@{

fastest="";
vfastest=0;
name="Io";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Europa";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Ganymede";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Callisto";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
Row@{fastest, " has the fastest linear speed."}

},

Column@{

fastest="";
vfastest=0;
name="Io";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Europa";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Ganymede";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Callisto";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
Row@{fastest, " has the fastest linear speed."}

},

Column@{

fastest="";
vfastest=0;
name="Io";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Europa";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Ganymede";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Callisto";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
Row@{fastest, " has the fastest linear speed."}

},

Column@{

fastest="";
vfastest=0;
name="Io";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Europa";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Ganymede";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Callisto";
Row@{Subscript["v",name],"=",ScientificForm[v=moondata[name]["distance"]*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
Row@{fastest, " has the fastest linear speed."}

}



};


wrong=RandomSample[wrong,RandomInteger[{4,Length@wrong}]];
choices=Join[{correct},wrong];];


If [mywords=!={}, words=mywords[vars,ctr], words[s_]:=Nothing];


<|

"question labeled"->(

myFRAME1@Column@{
words["text_labeled"],

Row@{ctr,"The four Galilean moons of Jupiter have orbital periods and mean distances\nfrom Jupiter as given in the following table: "},
moontable,
Row@{"Find the linear speed of eah moon. Which is the fastest, in terms of linear\nspeed?"}
}
),

"question"->(
myFRAME1@Column@{
words["text"],

Row@{ctr,"The four Galilean moons of Jupiter have orbital periods and mean distances\nfrom Jupiter as given in the following table: "},
moontable,
Row@{"Find the linear speed of eah moon. Which is the fastest, in terms of linear\nspeed?"}
}
),


"anime"->(

{(*
ImageResize[myRASTER[#],{450,540}]&/@list*)}

),

"tutorial_anime"->(
{}
),

"example"->(

example=Column@{
Row@{Style["Example Stuff",Orange,FontSize->18,FontWeight->Bold]}
}

),

(*This was added in 4.0 to allow for pdf that is different than exampl*)
"example PDF"->(

(*example*)
{}

(*Column@{
Row@{Style["PDF Stuff",Orange,FontSize->18,FontWeight->Bold]}

}*)

),

"example_anime"->(

{}
),

"solution"->(
{
Row@{Style["Solution",FontSize->18,FontWeight->Bold]},
words["solution"],
Spacer@100,
Row@{"ω","=",2*π/"Period"},
Highlighted@Row@{"v","=",2*π/"Period","radius"},
Style[Row@{"Note: Multiply days by 24 to convert to hours. "},Bold,Red],
fastest="";
vfastest=0;
name="Io";
Row@{Subscript["v",name],"=",Row@{moondata[name]["distance"],"×",2,Pi}/Row@{moondata[name]["period"],If[moondata[name]["periodunit"]>1,Row@{"×",moondata[name]["periodunit"]},Nothing]},"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Europa";
Row@{Subscript["v",name],"=",Row@{moondata[name]["distance"],"×",2,Pi}/Row@{moondata[name]["period"],If[moondata[name]["periodunit"]>1,Row@{"×",moondata[name]["periodunit"]},Nothing]},"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Ganymede";
Row@{Subscript["v",name],"=",Row@{moondata[name]["distance"],"×",2,Pi}/Row@{moondata[name]["period"],If[moondata[name]["periodunit"]>1,Row@{"×",moondata[name]["periodunit"]},Nothing]},"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];
name="Callisto";
Row@{Subscript["v",name],"=",Row@{moondata[name]["distance"],"×",2,Pi}/Row@{moondata[name]["period"],If[moondata[name]["periodunit"]>1,Row@{"×",moondata[name]["periodunit"]},Nothing]},"=",ScientificForm[v=moondata[name]["distance"]*2*Pi/(moondata[name]["period"]*moondata[name]["periodunit"])],"km/h"},
If[v>vfastest,vfastest=v;fastest=name];Nothing
}
),

"correct"->(
myFRAME2@correct
),

"wrong"->(
myFRAME2/@wrong
),

"video"->({}),
"molecule"->(molecule), (*used for the question or example*)

"abcd"->({})


|>

];


logic2[ctr_,mywords_,abcd_]:=Module[{correct,vv,words,wrong,vars,b,a,c,example,choices,molecule={},wrongmolecule={},triangle,new,plot,f},


vv=Release@Map[Hold[RandomChoice@{ToUpperCase,ToLowerCase}],RandomSample[Complement[CharacterRange["a","z"],{"l","o", "i","e"}],1]];


correct={};
wrong={{},{},{}};
choices=Join[{correct},wrong];
While[Or@@(#[[1]]===#[[2]]&/@Permutations[choices, {2}]),


a=RandomInteger[{80,150}]*0.1;
myTRIANGLESIZE={200,200};
triangle=<|

(*vertices*)
"A"-><|"name"->"","coors"->{1 ,0}|>,
"B"-><|"name"->"","coors"->{0 ,RandomReal[{0.3,0.5}]}|>,
"C"-><|"name"->"","coors"->{0 ,0}|>,


(*angles*)
"∠A var"-><|"var"->""|>,
"∠B var"-><|"var"->""|>,
"∠C var"-><|"var"->Superscript["90","∘"]|>,


"AB"-><|"name"->""|>,
"AC"-><|"name"->"a"|>,
"BC"-><|"name"->""|>,

(*graphics*)
"color"->(RandomChoice@{(LightGreen),LightBlue,LightGray}),
"opacity"->1,
"edge color"->Pink
|>;


new=myTRIANGLE[triangle,RotationTransform[0]];

plot=new["plot2"];

correct=Column@{
Row@{"a. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(30*Degree),"a"->a,"g"->32},
Row@{"b. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(45*Degree),"a"->a,"g"->32},Row@{"c. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(60*Degree),"a"->a,"g"->32}
};

(*variable number of choices *)
wrong={

Column@{
Row@{"a. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(45*Degree),"a"->a,"g"->32},
Row@{"b. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(30*Degree),"a"->a,"g"->31},Row@{"c. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(60*Degree),"a"->a,"g"->32}
},

Column@{
Row@{"a. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(45*Degree),"a"->a,"g"->32},
Row@{"b. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(60*Degree),"a"->a,"g"->32},Row@{"c. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(30*Degree),"a"->a,"g"->31}
},

Column@{
Row@{"a. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(30*Degree),"a"->a,"g"->31},
Row@{"b. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(60*Degree),"a"->a,"g"->32},Row@{"c. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(45*Degree),"a"->a,"g"->32}
},

Column@{
Row@{"a. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(60*Degree),"a"->a,"g"->32},
Row@{"b. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(45*Degree),"a"->a,"g"->30},Row@{"c. ",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(30*Degree),"a"->a,"g"->32}
}


};

wrong=RandomSample[wrong,RandomInteger[{3,Length@wrong}]];
choices=Join[{correct},wrong];];


If [mywords=!={}, words=mywords[vars,ctr], words[s_]:=Nothing];


<|

"question labeled"->(

myFRAME1@Column@{
words["text_labeled"],

Row@{ctr,"If friction is ignored, the time, t (in seconds) required for a black to slide\ndown an inclined plane is given by the function:\n",TraditionalForm@f["θ"],"=",TraditionalForm[Sqrt[Row@{2,"a"}/Row@{"g",Cos["θ"],Sin["θ"]}]]},
plot,
Row@{"where a is the length of the base (in feet) and g≈",Row@{32,"ft"}/Row@{"(sec^2)"}," is the acceleration\ndue to gravity. How long will a black need to slide the inclined plane with\nbase a=",a,"feet when:"},
Row@{"a. ",Superscript["30","∘"]},
Row@{"b. ",Superscript["45","∘"]},
Row@{"c. ",Superscript["60","∘"]}
}
),

"question"->(
myFRAME1@Column@{
words["text"],

Row@{ctr,"If friction is ignored, the time, t (in seconds) required for a black to slide\ndown an inclined plane is given by the function:\n",TraditionalForm@f["θ"],"=",TraditionalForm[Sqrt[Row@{2,"a"}/Row@{"g",Cos["θ"],Sin["θ"]}]]},
plot,
Row@{"where a is the length of the base (in feet) and g≈",Row@{32,"ft"}/Row@{"(sec^2)"}," is the acceleration\ndue to gravity. How long will a black need to slide the inclined plane with\nbase a=",a,"feet when:"},
Row@{"a. ",Superscript["30","∘"]},
Row@{"b. ",Superscript["45","∘"]},
Row@{"c. ",Superscript["60","∘"]}
}
),


"anime"->(

{(*
ImageResize[myRASTER[#],{450,540}]&/@list*)}

),

"tutorial_anime"->(
{}
),

"example"->(

example=Column@{
Row@{Style["Example Stuff",Orange,FontSize->18,FontWeight->Bold]}
}

),

(*This was added in 4.0 to allow for pdf that is different than exampl*)
"example PDF"->(

(*example*)
{}

(*Column@{
Row@{Style["PDF Stuff",Orange,FontSize->18,FontWeight->Bold]}

}*)

),

"example_anime"->(

{}
),

"solution"->(
{
Row@{Style["Solution",FontSize->18,FontWeight->Bold]},
words["solution"],
Spacer@100,
Row@{TraditionalForm@f["θ"],"=",TraditionalForm[Sqrt[Row@{2,"a"}/Row@{"g",Cos["θ"],Sin["θ"]}]]},
Row@{"=",TraditionalForm[Sqrt[Row@{2,"a"}/Row@{"g",Cos["θ"],Sin["θ"]}]]}/.{"θ"->Superscript["30","∘"],"a"->a},
Row@{"=",TraditionalForm[Sqrt[Row@{2,"a"}/Row@{"g",Cos["θ"],Sin["θ"]}]]}/.{"θ"->(30*Degree),"a"->a,"g"->32},
Row@{"=",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(30*Degree),"a"->a,"g"->32},

Spacer@100,
Row@{TraditionalForm@f["θ"],"=",TraditionalForm[Sqrt[Row@{2,"a"}/Row@{"g",Cos["θ"],Sin["θ"]}]]},
Row@{"=",TraditionalForm[Sqrt[Row@{2,"a"}/Row@{"g",Cos["θ"],Sin["θ"]}]]}/.{"θ"->Superscript["45","∘"],"a"->a},
Row@{"=",TraditionalForm[Sqrt[Row@{2,"a"}/Row@{"g",Cos["θ"],Sin["θ"]}]]}/.{"θ"->(45*Degree),"a"->a,"g"->32},
Row@{"=",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(45*Degree),"a"->a,"g"->32},

Spacer@100,
Row@{TraditionalForm@f["θ"],"=",TraditionalForm[Sqrt[Row@{2,"a"}/Row@{"g",Cos["θ"],Sin["θ"]}]]},
Row@{"=",TraditionalForm[Sqrt[Row@{2,"a"}/Row@{"g",Cos["θ"],Sin["θ"]}]]}/.{"θ"->Superscript["60","∘"],"a"->a},
Row@{"=",TraditionalForm[Sqrt[Row@{2,"a"}/Row@{"g",Cos["θ"],Sin["θ"]}]]}/.{"θ"->(60*Degree),"a"->a,"g"->32},
Row@{"=",Sqrt[2*a/("g"*Cos["θ"]*Sin["θ"])],"sec"}/.{"θ"->(60*Degree),"a"->a,"g"->32}

}
),

"correct"->(
myFRAME2@correct
),

"wrong"->(
myFRAME2/@wrong
),

"video"->({}),
"molecule"->(molecule), (*used for the question or example*)

"abcd"->({})


|>/.{f->"f"}

];

DATA

$UnitSystem="Metric";
data={#,PlanetaryMoonData[#,"AverageOrbitDistance"],PlanetaryMoonData[#,"OrbitPeriod"],PlanetaryMoonData[#,"Image"]}&/@{"Io","Europa","Ganymede","Callisto"};

moondata=<|Flatten[{#-><|
"distance"->(QuantityMagnitude[PlanetaryMoonData[#,"AverageOrbitDistance"],"Kilometers"]),

"period"->(QuantityMagnitude@PlanetaryMoonData[#,"OrbitPeriod"]),
"periodunit"->(If[QuantityUnit@PlanetaryMoonData[#,"OrbitPeriod"]=="Hours",1,24])
|>


}&/@{"Io","Europa","Ganymede","Callisto"}]|>

moontable=Text@Grid[Prepend[data,{"","Distance(km)","Period","Image"}],Background->{None,{Lighter[Yellow,.9],{White,Lighter[Blend[{Blue,Green}],.8]}}},Dividers->{{Darker[Gray,.6],{Lighter[Gray,.5]},Darker[Gray,.6]},{Darker[Gray,.6],Darker[Gray,.6],{False},Darker[Gray,.6]}},Alignment->{{Left,Right,{Left}}},ItemSize->{{7,10,7,8}},Frame->Darker[Gray,.6],ItemStyle->14,Spacings->{Automatic,.8}]

logic2["1. ",{},{}]

Do not touch or run the code below!!!

CloseKernels[];

LaunchKernels[64]

JSON

PNG=False;
debugCORRECT=False;
isSERVER="JSON";
myDIRECTORY={NotebookDirectory[],"trigassignment1_","SVG"};
myGIFDIRECTORY={NotebookDirectory[],"trigassignment1_","GIF"};
myCDFDIRECTORY={NotebookDirectory[],"trigassignment1_","cdf"};
myPDFDIRECTORY={NotebookDirectory[],"trigassignment1_","pdf"};


myTITLE={" "," "," "};


vars=Table[
ParallelTable[


varilist={

{logic1,{},<|"type"->"1","question"->myDIRECTORY,"tutorial"->myDIRECTORY,"anime"->myGIFDIRECTORY|>},
{logic2,{},<|"type"->"1","question"->myDIRECTORY,"tutorial"->myDIRECTORY,"anime"->myGIFDIRECTORY|>}
};


nn=Length@varilist;
varilist=RandomSample[varilist,nn];

(*uncomment these two lines if chained questions*)
(*varilist=Flatten[varilist,1];
nn=Length@varilist;*)
tmp=ConstantArray["",nn];
logics=varilist[[All,1]];
words=varilist[[All,2]];
etc=varilist[[All,3]];

title=<|
1->"1. ",
2->"2. ",
3->"3. ",
4->"4. ",
5->"5. "

|>;



Table[tmp[[ii]]=makeVAR[title[ii],logics[[ii]],words[[ii]],If[ii==1,{},( tmp[[ii-1]])[[1]][[2]]],etc[[ii]]]["json"],{ii,1,nn}],

{32}],
{8}];

vars=Flatten[vars,1];

CloseKernels[];

Export[FileNameJoin@{NotebookDirectory[],"cache","cache.json"},vars];

CloseKernels[];