(*© 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.1"];
init[];
Clear[init];

logic1[ctr_,mywords_,abcd_]:=Module[{correct,vv,words,wrong,vars,aa,a,b,c,example,choices,molecule={},wrongmolecule={},c1,c2,c3,c4,c5,c6,letter,name},


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


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

name=names[[1]];

c1=RandomChoice[CCNENGLISH`nounsveggies[name]];
(*c1 correct*)


{c2,c3,c4,c5,c6}={RandomChoice@CCNENGLISH`nounsveggies[names[[2]]],RandomChoice@CCNENGLISH`nounsveggies[names[[3]]],RandomChoice@CCNENGLISH`nounsveggies[names[[4]]],
Sequence@@RandomSample[CCNENGLISH`nounsmisc,2]};
correct=(Row@{c1["name"],c1["image"]});
wrong=({

Row@{c2["name"],c3["image"]},
Row@{c3["name"],c4["image"]},
Row@{c5["name"],c6["image"]}

});

wrong=RandomSample[wrong,Length@wrong];

choices=Join[{correct},wrong];];


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


<|

"question labeled"->(
myFRAME1@Column@{
Row@{ctr,"Which of the following is correct?"}
}
),

"question"->(
myFRAME1@Column@{
Row@{ctr,"Which of the following is correct?"}
}
),


"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"],
correct
}
),

"correct"->(
myFRAME2@correct
),

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

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


|>

];




logic2[ctr_,mywords_,abcd_]:=Module[{correct,vv,words,wrong,vars,aa,a,b,c,example,choices,molecule={},wrongmolecule={},c1,c2,c3,c4,c5,c6,letter,name},


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


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

name=names[[2]];

c1=RandomChoice[CCNENGLISH`nounsveggies[name]];
(*c1 correct*)


{c2,c3,c4,c5,c6}={RandomChoice@CCNENGLISH`nounsveggies[names[[1]]],RandomChoice@CCNENGLISH`nounsveggies[names[[3]]],RandomChoice@CCNENGLISH`nounsveggies[names[[4]]],
Sequence@@RandomSample[CCNENGLISH`nounsmisc,2]};
correct=(Row@{c1["name"],c1["image"]});
wrong=({

Row@{c2["name"],c3["image"]},
Row@{c3["name"],c4["image"]},
Row@{c5["name"],c6["image"]}

});

wrong=RandomSample[wrong,Length@wrong];

choices=Join[{correct},wrong];];


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


<|

"question labeled"->(
myFRAME1@Column@{
Row@{ctr,"Which of the following is correct?"}
}
),

"question"->(
myFRAME1@Column@{
Row@{ctr,"Which of the following is correct?"}
}
),


"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"],
correct
}
),

"correct"->(
myFRAME2@correct
),

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

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


|>

];


logic3[ctr_,mywords_,abcd_]:=Module[{correct,vv,words,wrong,vars,aa,a,b,c,example,choices,molecule={},wrongmolecule={},c1,c2,c3,c4,c5,c6,letter,name},


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


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

name=names[[3]];

c1=RandomChoice[CCNENGLISH`nounsveggies[name]];
(*c1 correct*)


{c2,c3,c4,c5,c6}={RandomChoice@CCNENGLISH`nounsveggies[names[[2]]],RandomChoice@CCNENGLISH`nounsveggies[names[[1]]],RandomChoice@CCNENGLISH`nounsveggies[names[[4]]],
Sequence@@RandomSample[CCNENGLISH`nounsmisc,2]};
correct=(Row@{c1["name"],c1["image"]});
wrong=({

Row@{c2["name"],c3["image"]},
Row@{c3["name"],c4["image"]},
Row@{c5["name"],c6["image"]}

});

wrong=RandomSample[wrong,Length@wrong];

choices=Join[{correct},wrong];];


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


<|

"question labeled"->(
myFRAME1@Column@{
Row@{ctr,"Which of the following is correct?"}
}
),

"question"->(
myFRAME1@Column@{
Row@{ctr,"Which of the following is correct?"}
}
),


"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"],
correct
}
),

"correct"->(
myFRAME2@correct
),

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

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


|>

];


logic4[ctr_,mywords_,abcd_]:=Module[{correct,vv,words,wrong,vars,aa,a,b,c,example,choices,molecule={},wrongmolecule={},c1,c2,c3,c4,c5,c6,letter,name},


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


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

name=names[[4]];

c1=RandomChoice[CCNENGLISH`nounsveggies[name]];
(*c1 correct*)


{c2,c3,c4,c5,c6}={RandomChoice@CCNENGLISH`nounsveggies[names[[1]]],RandomChoice@CCNENGLISH`nounsveggies[names[[3]]],RandomChoice@CCNENGLISH`nounsveggies[names[[5]]],
Sequence@@RandomSample[CCNENGLISH`nounsmisc,2]};
correct=(Row@{c1["name"],c1["image"]});
wrong=({

Row@{c2["name"],c3["image"]},
Row@{c3["name"],c4["image"]},
Row@{c5["name"],c6["image"]}

});

wrong=RandomSample[wrong,Length@wrong];

choices=Join[{correct},wrong];];


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


<|

"question labeled"->(
myFRAME1@Column@{
Row@{ctr,"Which of the following is correct?"}
}
),

"question"->(
myFRAME1@Column@{
Row@{ctr,"Which of the following is correct?"}
}
),


"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"],
correct
}
),

"correct"->(
myFRAME2@correct
),

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

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


|>

];

logic5[ctr_,mywords_,abcd_]:=Module[{correct,vv,words,wrong,vars,aa,a,b,c,example,choices,molecule={},wrongmolecule={},c1,c2,c3,c4,c5,c6,letter,name},


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


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

name=names[[5]];

c1=RandomChoice[CCNENGLISH`nounsveggies[name]];
(*c1 correct*)


{c2,c3,c4,c5,c6}={RandomChoice@CCNENGLISH`nounsveggies[names[[1]]],RandomChoice@CCNENGLISH`nounsveggies[names[[4]]],RandomChoice@CCNENGLISH`nounsveggies[names[[3]]],
Sequence@@RandomSample[CCNENGLISH`nounsmisc,2]};
correct=(Row@{c1["name"],c1["image"]});
wrong=({

Row@{c2["name"],c3["image"]},
Row@{c3["name"],c4["image"]},
Row@{c5["name"],c6["image"]}

});

wrong=RandomSample[wrong,Length@wrong];

choices=Join[{correct},wrong];];


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


<|

"question labeled"->(
myFRAME1@Column@{
Row@{ctr,"Which of the following is correct?"}
}
),

"question"->(
myFRAME1@Column@{
Row@{ctr,"Which of the following is correct?"}
}
),


"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"],
correct
}
),

"correct"->(
myFRAME2@correct
),

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

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


|>

];

DATA

CCNENGLISH`nounsveggies=<|


"Brinjal"->{
<|"name"->Style["Brinjal",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Brinjal",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Brinjal",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Brinjal",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Brinjal",40],"image"->ImageResize[,200]|>} ,

"potato"->{
<|"name"->Style["Potato",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Potato",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Potato",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Potato",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Potato",40],"image"->ImageResize[,200]|>} ,


"onion"->{
<|"name"->Style["Onion",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Onion",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Onion",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Onion",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Onion",40],"image"->ImageResize[,200]|>} ,

"Corn"->{
<|"name"->Style["Corn",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Corn",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Corn",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Corn",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Corn",40],"image"->ImageResize[,200]|>} ,


"Cabbage"->{
<|"name"->Style["Cabbage",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Cabbage",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Cabbage",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Cabbage",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Cabbage",40],"image"->ImageResize[,200]|>} 




|>;


CCNENGLISH`nounsmisc={


<|"name"->Style["Cup",40],"image"->ImageResize[,200]|>,

<|"name"->Style["Table",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Tree",40],"image"->ImageResize[,200]|>
,<|"name"->Style["House",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Axe",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Flower",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Butterfly",40],"image"->ImageResize[,200]|>
,<|"name"->Style["Cactus",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Chair",40],"image"->ImageResize[,200]|>,
<|"name"->Style["Moon",40],"image"->ImageResize[,200]|>



};

names=Keys@CCNENGLISH`nounsveggies

CloseKernels[];

LaunchKernels[4]

SetSharedVariable[CCNENGLISH`nounsveggies];
SetSharedVariable[CCNENGLISH`nounsmisc];

JSON

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


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


vars=Table[
ParallelTable[


varilist={

{logic1,{},<|"type"->"1","question"->myDIRECTORY,"tutorial"->myDIRECTORY,"anime"->myGIFDIRECTORY|>},
{logic2,{},<|"type"->"1","question"->myDIRECTORY,"tutorial"->myDIRECTORY,"anime"->myGIFDIRECTORY|>},
{logic3,{},<|"type"->"1","question"->myDIRECTORY,"tutorial"->myDIRECTORY,"anime"->myGIFDIRECTORY|>},
{logic4,{},<|"type"->"1","question"->myDIRECTORY,"tutorial"->myDIRECTORY,"anime"->myGIFDIRECTORY|>},
{logic5,{},<|"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. ",
6->"6. "

|>;



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}],
{1}];

vars=Flatten[vars,1];.

CloseKernels[];

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

CloseKernels[];