(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 6.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 46212, 1192] NotebookOptionsPosition[ 43488, 1101] NotebookOutlinePosition[ 44108, 1125] CellTagsIndexPosition[ 44065, 1122] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[TextData[{ "Keyboard/mouse input via ", Cell[BoxData["EventHandler"]] }], "Title", CellChangeTimes->{{3.3907458272729015`*^9, 3.390745835374874*^9}, { 3.390746922311163*^9, 3.3907469286805754`*^9}, {3.390747109577908*^9, 3.390747121535579*^9}, {3.3949919891510243`*^9, 3.3949920025093*^9}, { 3.395346125984375*^9, 3.39534614046875*^9}, {3.3954160997502937`*^9, 3.3954160998804817`*^9}, {3.3954170292761545`*^9, 3.3954170434566865`*^9}, { 3.3954987906173086`*^9, 3.395498815643794*^9}, {3.3954996494493756`*^9, 3.3954996553680043`*^9}, {3.395509069172121*^9, 3.3955090844243565`*^9}}], Cell["\<\ Comp 160 Course Module 7 \ \>", "Subtitle", CellChangeTimes->{{3.390745838950158*^9, 3.3907458395911055`*^9}, 3.3907469187659235`*^9, {3.394991909622219*^9, 3.394991911955411*^9}, 3.3949920154269733`*^9, {3.395346122265625*^9, 3.395346122453125*^9}, 3.3954170235578747`*^9, {3.3954987841378627`*^9, 3.3954987842880816`*^9}, { 3.427129887250551*^9, 3.4271298874608617`*^9}, {3.4596142208125*^9, 3.459614223484375*^9}}], Cell[TextData[{ "In the last module, we used ", StyleBox["Mathematica", FontSlant->"Italic"], "'s built-in control objects. While buttons, radio buttons, and such are \ useful in many applications, the mouse and the keyboard of crucial input \ devices for most PC games. In this module, we learn how to read from the \ keyboard and mouse using the ", StyleBox["Mathematica", FontSlant->"Italic"], " function ", Cell[BoxData["EventHandler"]], "." }], "Text", CellChangeTimes->{{3.394992012613124*^9, 3.3949921192690425`*^9}, { 3.395346151296875*^9, 3.395346266640625*^9}, {3.3954112081877975`*^9, 3.3954112189633994`*^9}, {3.3954161134100714`*^9, 3.3954161204402504`*^9}, 3.3954165079413137`*^9, {3.3954173283091245`*^9, 3.3954174277330804`*^9}, { 3.3954962908229303`*^9, 3.3954963027503185`*^9}, {3.395499665052122*^9, 3.3954997904148855`*^9}, 3.3992949959149437`*^9, {3.459614227328125*^9, 3.459614235921875*^9}, {3.459614301484375*^9, 3.459614337671875*^9}}], Cell[CellGroupData[{ Cell[TextData[{ "The current state of ", StyleBox["Disasteroids", FontSlant->"Italic"] }], "Section", CellChangeTimes->{{3.394384127590186*^9, 3.3943841323971944`*^9}, { 3.3943860065394526`*^9, 3.394386016584097*^9}, {3.3943862806590843`*^9, 3.3943862835232596`*^9}, {3.3944627701709642`*^9, 3.3944627761697097`*^9}, {3.39534637065625*^9, 3.39534638284375*^9}, 3.395358350984375*^9, {3.3954171137785053`*^9, 3.395417121559772*^9}}], Cell[TextData[{ "Since we will spend several modules working on ", StyleBox["Disasteroids", FontSlant->"Italic"], ", we will start with a clean version from the last module. Our \ implementation consisted of a background and a ship whose position was \ parameterized by a position and orientation." }], "Text", CellChangeTimes->{{3.3954174417233367`*^9, 3.395417535108549*^9}}], Cell[BoxData[{ RowBox[{ RowBox[{"background", "=", RowBox[{"Rectangle", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", RowBox[{"-", "1"}]}], "}"}], ",", RowBox[{"{", RowBox[{"1", ",", "1"}], "}"}]}], "]"}]}], ";"}], "\n", RowBox[{ RowBox[{"shipModel", "=", RowBox[{"Polygon", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", FractionBox["1", "2"]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", FractionBox[ RowBox[{"-", "1"}], "2"]}], "}"}]}], "}"}], "]"}]}], ";"}], "\n", RowBox[{ RowBox[{"ship", "[", RowBox[{"p_", ",", "\[Theta]_"}], "]"}], ":=", RowBox[{"Translate", "[", RowBox[{ RowBox[{"Rotate", "[", RowBox[{ RowBox[{"Scale", "[", RowBox[{"shipModel", ",", FractionBox["1", "10"]}], "]"}], ",", "\[Theta]"}], "]"}], ",", "p"}], "]"}]}]}], "Input", CellChangeTimes->{{3.394462114505088*^9, 3.3944621175595407`*^9}, { 3.394462182233827*^9, 3.3944622029840784`*^9}, {3.394559454232637*^9, 3.3945594679125805`*^9}, {3.3954154048541527`*^9, 3.395415411063143*^9}, { 3.395417155168434*^9, 3.3954171685077477`*^9}, {3.395683848974902*^9, 3.3956838513283095`*^9}}], Cell[TextData[{ "Here is our latest version that uses ", Cell[BoxData["Panel"]], " and ", Cell[BoxData["Button"]], "." }], "Text", CellChangeTimes->{{3.3954175427796564`*^9, 3.395417584550136*^9}, { 3.39549874015374*^9, 3.3954987600126915`*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"DynamicModule", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"p", "=", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], ",", RowBox[{"\[Theta]", "=", "0"}], ",", RowBox[{"\[Delta]", "=", ".04"}], ",", RowBox[{"\[Delta]\[Theta]", "=", ".2"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"Panel", "[", RowBox[{ RowBox[{"Column", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Graphics", "[", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ "background", ",", "\[IndentingNewLine]", "White", ",", "\[IndentingNewLine]", RowBox[{"Dynamic", "[", RowBox[{"ship", "[", RowBox[{"p", ",", "\[Theta]"}], "]"}], "]"}]}], "}"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Grid", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Button", "[", RowBox[{"\"\\"", ",", RowBox[{"p", "+=", RowBox[{"\[Delta]", RowBox[{"{", RowBox[{ RowBox[{"Cos", "[", "\[Theta]", "]"}], ",", RowBox[{"Sin", "[", "\[Theta]", "]"}]}], "}"}]}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Button", "[", RowBox[{"\"\\"", ",", RowBox[{"p", "-=", RowBox[{"\[Delta]", RowBox[{"{", RowBox[{ RowBox[{"Cos", "[", "\[Theta]", "]"}], ",", RowBox[{"Sin", "[", "\[Theta]", "]"}]}], "}"}]}]}]}], "]"}]}], "}"}], ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"Button", "[", RowBox[{"\"\\"", ",", RowBox[{"\[Theta]", "+=", "\[Delta]\[Theta]"}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Button", "[", RowBox[{"\"\\"", ",", RowBox[{"\[Theta]", "-=", "\[Delta]\[Theta]"}]}], "]"}]}], "}"}]}], "}"}], "]"}]}], "}"}], ",", "Center"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Style", "[", RowBox[{"\"\\"", ",", "36", ",", "Red", ",", "Italic"}], "]"}], ",", "Top"}], "]"}]}], "]"}]], "Input", CellChangeTimes->{{3.3944607240579944`*^9, 3.3944608783529367`*^9}, { 3.394460909508357*^9, 3.39446105302759*^9}, {3.3944611755261765`*^9, 3.3944612086544733`*^9}, {3.394461376819637*^9, 3.394461394565508*^9}, { 3.394461498316764*^9, 3.394461581467988*^9}, {3.3944616120726056`*^9, 3.394461855096904*^9}, {3.3944621652090073`*^9, 3.394462165869971*^9}, { 3.3944622961298733`*^9, 3.3944622987236547`*^9}, {3.3945600411282554`*^9, 3.39456008757597*^9}, {3.3945601200433035`*^9, 3.394560154613703*^9}, { 3.3954172615524673`*^9, 3.3954172657385283`*^9}, {3.3954195203529863`*^9, 3.395419556375142*^9}, {3.3954974223725843`*^9, 3.395497423263883*^9}, { 3.3954974922945213`*^9, 3.3954975070360126`*^9}, {3.3954982630581956`*^9, 3.3954983590481367`*^9}, {3.3956837944058914`*^9, 3.3956838151158776`*^9}, { 3.46019838390625*^9, 3.460198387953125*^9}}], Cell[BoxData[ DynamicModuleBox[{$CellContext`p$$ = { 0.03999999999999999, 0}, $CellContext`\[Theta]$$ = 0., $CellContext`\[Delta]$$ = 0.04, $CellContext`\[Delta]\[Theta]$$ = 0.2}, InterpretationBox[GridBox[{ { TagBox[ StyleBox[ StyleBox["\<\"Disasteroids\"\>", StripOnInput->False, FrontFaceColor->RGBColor[1, 0, 0], BackFaceColor->RGBColor[1, 0, 0], GraphicsColor->RGBColor[1, 0, 0], FontSize->36, FontSlant->Italic, FontColor->RGBColor[1, 0, 0]], "Panel", StripOnInput->False, Background->None], "Labeled", Editable->True, Selectable->True]}, { TagBox[ TagBox[ PanelBox[ TagBox[GridBox[{ { GraphicsBox[{RectangleBox[{-1, -1}, {1, 1}], {GrayLevel[1], DynamicBox[Typeset`ToBoxes[ $CellContext`ship[$CellContext`p$$, \ $CellContext`\[Theta]$$], StandardForm, Graphics], ImageSizeCache->{{126.71480000000004`, 152.6148}, {-13.500000000000071`, -0.5000000000000726}}]}}]}, { TagBox[GridBox[{ { ButtonBox["\<\"Forward\"\>", Appearance->{Automatic, "DialogBox"}, ButtonFunction:> AddTo[$CellContext`p$$, $CellContext`\[Delta]$$ { Cos[$CellContext`\[Theta]$$], Sin[$CellContext`\[Theta]$$]}], Evaluator->Automatic, Method->"Preemptive"], ButtonBox["\<\"Back\"\>", Appearance->{Automatic, "DialogBox"}, ButtonFunction:> SubtractFrom[$CellContext`p$$, $CellContext`\[Delta]$$ { Cos[$CellContext`\[Theta]$$], Sin[$CellContext`\[Theta]$$]}], Evaluator->Automatic, Method->"Preemptive"]}, { ButtonBox["\<\"Turn Counterclockwise\"\>", Appearance->{Automatic, "DialogBox"}, ButtonFunction:> AddTo[$CellContext`\[Theta]$$, $CellContext`\[Delta]\ \[Theta]$$], Evaluator->Automatic, Method->"Preemptive"], ButtonBox["\<\"Turn Clockwise\"\>", Appearance->{Automatic, "DialogBox"}, ButtonFunction:> SubtractFrom[$CellContext`\[Theta]$$, \ $CellContext`\[Delta]\[Theta]$$], Evaluator->Automatic, Method->"Preemptive"]} }, ColumnsEqual->False, GridBoxItemSize->{ "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, RowsEqual->False], "Grid"]} }, ColumnsEqual->False, GridBoxAlignment->{"Columns" -> {{Center}}}, GridBoxItemSize->{ "Columns" -> {{Automatic}}, "Rows" -> {{Automatic}}}, RowsEqual->False], "Column"]], "Labeled", Editable->True, Selectable->True], "SkipImageSizeLevel"]} }, BaselinePosition->{2, 1}, GridBoxAlignment->{ "Columns" -> {{Center}}, "ColumnsIndexed" -> {}, "Rows" -> {{Center}}, "RowsIndexed" -> {}}, GridBoxItemSize->{ "Columns" -> {{Automatic}}, "ColumnsIndexed" -> {}, "Rows" -> {{1.}}, "RowsIndexed" -> {}}], Labeled[ Panel[ Column[{ Graphics[{ Rectangle[{-1, -1}, {1, 1}], GrayLevel[1], Dynamic[ $CellContext`ship[$CellContext`p$$, $CellContext`\[Theta]$$]]}], Grid[{{ Button["Forward", AddTo[$CellContext`p$$, $CellContext`\[Delta]$$ { Cos[$CellContext`\[Theta]$$], Sin[$CellContext`\[Theta]$$]}]], Button["Back", SubtractFrom[$CellContext`p$$, $CellContext`\[Delta]$$ { Cos[$CellContext`\[Theta]$$], Sin[$CellContext`\[Theta]$$]}]]}, { Button["Turn Counterclockwise", AddTo[$CellContext`\[Theta]$$, $CellContext`\[Delta]\[Theta]$$]], Button["Turn Clockwise", SubtractFrom[$CellContext`\[Theta]$$, \ $CellContext`\[Delta]\[Theta]$$]]}}]}, Center]], { Style[ Style[ "Disasteroids", FontSize -> 36, $CellContext`Color -> RGBColor[1, 0, 0], Italic], "Panel", Background -> None]}, {Top}], Editable->False, Selectable->False], DynamicModuleValues:>{}]], "Output", CellChangeTimes->{ 3.3945650844138823`*^9, 3.3945656950441027`*^9, 3.394565802560848*^9, 3.3948080721503906`*^9, 3.3948082425070505`*^9, 3.3948087399873524`*^9, 3.394809019151554*^9, 3.394813407415324*^9, 3.394919478796875*^9, { 3.395415769722446*^9, 3.395415791984679*^9}, 3.395415822218455*^9, 3.3954158609545407`*^9, 3.39541601960425*^9, 3.3954171783920593`*^9, 3.3954963222988176`*^9, 3.3954996302714167`*^9, 3.3955001318526573`*^9, 3.3955123132115135`*^9, 3.395683854512921*^9}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[TextData[{ "Event handling in ", StyleBox["Mathematica", FontSlant->"Italic"] }], "Section", CellChangeTimes->{{3.3942076761358576`*^9, 3.3942076798312454`*^9}, { 3.394214969488629*^9, 3.3942149761483383`*^9}, {3.3942153315965357`*^9, 3.394215336924303*^9}, {3.394289304576662*^9, 3.3942893174550514`*^9}, { 3.394305925791448*^9, 3.394305940723366*^9}, {3.3943064041536083`*^9, 3.3943064060363717`*^9}, 3.394375794641818*^9, {3.394462790730938*^9, 3.394462791772456*^9}, {3.395499808521282*^9, 3.3954998154914436`*^9}, { 3.395500139954469*^9, 3.3955001419974475`*^9}, {3.3955006858202715`*^9, 3.3955006919191628`*^9}, {3.395500867725466*^9, 3.39550086799586*^9}, { 3.3955009356044245`*^9, 3.3955009413628197`*^9}}], Cell[TextData[{ "Users typically interact with ", StyleBox["Mathematica", FontSlant->"Italic"], " using a keyboard and mouse. For example, you click between two existing \ cells, type in a new expression and then hit ", Cell[BoxData[ RowBox[{"Shift", "+", "Enter"}]]], " for the cell to be evaluated. One interesting point to note is that \ while ", StyleBox["Mathematica", FontSlant->"Italic"], "'s kernel is evaluating the entered expression, the user is free to \ continue editing the rest of the notebook. How does ", StyleBox["Mathematica", FontSlant->"Italic"], " manage to both evaluate an expression and allow editing of the notebook?", StyleBox[" ", FontSlant->"Italic"], "By treating mouse and keyboard input as ", StyleBox["events", FontSlant->"Italic"], " that interrupt the processing of the expression currently being evaluated. \ " }], "Text", CellChangeTimes->{{3.3943058739153023`*^9, 3.394305883399223*^9}, { 3.3944619152245617`*^9, 3.394461930056185*^9}, {3.39550015721964*^9, 3.3955003238826127`*^9}, {3.3955004100782747`*^9, 3.3955006231088457`*^9}, { 3.395500767339115*^9, 3.3955007728972187`*^9}, {3.3955009303567743`*^9, 3.395500930887548*^9}, {3.395501022511123*^9, 3.3955010467364407`*^9}, { 3.395501285774928*^9, 3.3955013073664055`*^9}, {3.459614343359375*^9, 3.45961434375*^9}}], Cell[TextData[{ StyleBox["Mathematica", FontSlant->"Italic"], " (and most other computing environments) keep tracking of a set of specific \ actions that user may do using the keyboard or mouse. When ", StyleBox["Mathematica", FontSlant->"Italic"], " detects that one such action happens (the event), ", StyleBox["Mathematica", FontSlant->"Italic"], " interrupts the kernel and executes some user specified code associated \ with the event. ", "To get an idea of the possibilities for event handling in ", StyleBox["Mathematica", FontSlant->"Italic"], ", you should briefly browse ", ButtonBox["Low-Level Interface Control.", BaseStyle->"Link", ButtonData->"paclet:guide/LowLevelInterfaceControl"] }], "Text", CellChangeTimes->{{3.3943058739153023`*^9, 3.394305883399223*^9}, { 3.3944619152245617`*^9, 3.394461930056185*^9}, {3.39550015721964*^9, 3.3955003238826127`*^9}, {3.3955004100782747`*^9, 3.3955006231088457`*^9}, { 3.395500767339115*^9, 3.3955007728972187`*^9}, {3.395501333113942*^9, 3.3955014545109234`*^9}, {3.3955017268679852`*^9, 3.395501746196163*^9}, { 3.395501784552081*^9, 3.3955019669379764`*^9}, {3.395502051921872*^9, 3.395502054525668*^9}, {3.3955026136808443`*^9, 3.3955026265696344`*^9}}], Cell[TextData[{ "Here is an example from ", StyleBox["Mathematica", FontSlant->"Italic"], "'s ", Cell[BoxData[ RowBox[{"Documentation", " ", "Center"}]]], " that illustrates this point. The code below creates a notebook ", Cell[BoxData["nb"]], " and then set the options for the notebook such that if it detects a mouse \ click, the notebook turns ", Cell[BoxData["Pink"]], ". Note that after the option is set, ", StyleBox["Mathematica'", FontSlant->"Italic"], "s kernel proceeds to grind away at evaluating ", Cell[BoxData[ RowBox[{"While", "[", RowBox[{"True", ",", "1"}], "]"}]]], ". " }], "Text", CellChangeTimes->{{3.3943058739153023`*^9, 3.394305883399223*^9}, { 3.3944619152245617`*^9, 3.394461930056185*^9}, {3.39550015721964*^9, 3.3955003238826127`*^9}, {3.3955004100782747`*^9, 3.3955006231088457`*^9}, { 3.395500767339115*^9, 3.3955007728972187`*^9}, {3.395501333113942*^9, 3.3955014545109234`*^9}, {3.3955017268679852`*^9, 3.395501746196163*^9}, { 3.395501784552081*^9, 3.3955019669379764`*^9}, {3.395502051921872*^9, 3.395502054525668*^9}, {3.3955026136808443`*^9, 3.395502629163416*^9}}], Cell[CellGroupData[{ Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"nb", "=", RowBox[{"CreateDocument", "[", RowBox[{"{", "\"\\"", "}"}], "]"}]}], ";"}], "\[IndentingNewLine]"}], "\n", RowBox[{ RowBox[{ RowBox[{"SetOptions", "[", RowBox[{"nb", ",", RowBox[{"NotebookEventActions", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", "\[RuleDelayed]", RowBox[{"SetOptions", "[", RowBox[{"nb", ",", RowBox[{"Background", "\[Rule]", "Pink"}]}], "]"}]}], "}"}]}]}], "]"}], ";"}], "\[IndentingNewLine]"}], "\[IndentingNewLine]", RowBox[{"While", "[", RowBox[{"True", ",", "1"}], "]"}]}], "Input", CellChangeTimes->{{3.395501659169289*^9, 3.3955017580234056`*^9}, { 3.395501905298113*^9, 3.3955019081422596`*^9}, {3.3955123334510202`*^9, 3.395512335914612*^9}}, CellID->160409786], Cell[BoxData["$Aborted"], "Output", CellChangeTimes->{ 3.395501701130463*^9, {3.395501761818939*^9, 3.3955017822387085`*^9}, 3.395502197614273*^9, 3.395512346480015*^9}] }, Open ]], Cell[TextData[{ "Now, clicking in the notebook ", Cell[BoxData["nb"]], " still turns the notebook ", Cell[BoxData["Pink"]], " even though the expression ", Cell[BoxData[ RowBox[{"While", "[", RowBox[{"True", ",", "1"}], "]"}]]], " is still being evaluated. In this example, the event was ", Cell[BoxData["\<\"MouseClicked\"\>"]], " and the action was ", Cell[BoxData[ RowBox[{"SetOptions", "[", RowBox[{"nb", ",", " ", RowBox[{"Background", " ", "\[Rule]", " ", "Pink"}]}], "]"}]]], ". (Remember to abort the ", Cell[BoxData[ RowBox[{"While", "[", RowBox[{"True", ",", "1"}], "]"}]]], " when done with the example.) One interesting feature of the last example \ was the notebook ", Cell[BoxData["nb"]], " turned ", Cell[BoxData["Pink"]], " when clicked only if it was the notebook currently in focus (i.e., the top \ bar of the window was blue). If another notebook was in focus, mouse clicks \ had no effect on the color of the notebook. " }], "Text", CellChangeTimes->{{3.395501975330211*^9, 3.3955020299898977`*^9}, { 3.3955020633184867`*^9, 3.395502105109412*^9}, {3.3955026428934326`*^9, 3.3955026468491993`*^9}, {3.3955123573057976`*^9, 3.39551238265275*^9}, { 3.4596144305*^9, 3.459614431234375*^9}, 3.460198602671875*^9}], Cell[CellGroupData[{ Cell["Exercise", "Exercise", CellChangeTimes->{{3.395504048382455*^9, 3.395504051156499*^9}}], Cell[TextData[{ StyleBox["Modify the example above so that the color of the notebook \ background alternates between ", FontColor->RGBColor[0.5, 0, 0.5]], Cell[BoxData["Pink"], FontColor->RGBColor[0.5, 0, 0.5]], StyleBox[" and ", FontColor->RGBColor[0.5, 0, 0.5]], Cell[BoxData["White"], FontColor->RGBColor[0.5, 0, 0.5]], StyleBox[" when the notebook is clicked on.", FontColor->RGBColor[0.5, 0, 0.5]] }], "ExerciseText", CellChangeTimes->{{3.395504056534339*^9, 3.3955041045743756`*^9}, { 3.3955124024215703`*^9, 3.3955124027720814`*^9}}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Event handling for keyboard input", "Section", CellChangeTimes->{{3.3955021152341733`*^9, 3.395502134692541*^9}, { 3.3955027848704166`*^9, 3.3955027855614243`*^9}, {3.3955028242478237`*^9, 3.395502825689926*^9}}], Cell[TextData[{ "The previous example raises the point that there are often multiple event \ handlers competing to process keyboard and mouse input. For the sake of \ safety (we don't want to accidentally screw up the notebook we are working \ on), we will restrict our event handling in ", StyleBox["Mathematica", FontSlant->"Italic"], " to the simplest case, attaching event handling to a single expression. \ The ", StyleBox["Mathematica", FontSlant->"Italic"], " function ", Cell[BoxData["EventHandler"]], " attaches a list of events and corresponding actions to a ", StyleBox["Mathematica", FontSlant->"Italic"], " expression." }], "Text", CellChangeTimes->{{3.395502401872054*^9, 3.3955024088221865`*^9}, { 3.395502452816324*^9, 3.395502533123402*^9}, {3.3955025942425056`*^9, 3.395502619519356*^9}, {3.395502672977291*^9, 3.3955027429292717`*^9}, { 3.395512431954626*^9, 3.3955125193520403`*^9}, 3.3992950141517124`*^9, 3.45961447228125*^9}], Cell[TextData[{ "To begin, please review the ", Cell[BoxData[ RowBox[{"Documenation", " ", "Center"}]]], " information on ", Cell[BoxData["EventHandler"]], ". In particular, examine the information in the ", Cell[BoxData[ RowBox[{"More", " ", "information"}]]], " box. Below is a simple example of using the arrow keys to move a black \ rectangle around inside a white square." }], "Text", CellChangeTimes->{{3.3955041335165696`*^9, 3.3955041652428226`*^9}, { 3.395504671290575*^9, 3.3955047177182603`*^9}, {3.395512529987545*^9, 3.3955125441481895`*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"DynamicModule", "[", RowBox[{ RowBox[{"{", RowBox[{"pt", "=", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], "}"}], ",", "\n", RowBox[{"EventHandler", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Graphics", "[", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"Line", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], "}"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Dynamic", "[", RowBox[{"Rectangle", "[", RowBox[{"pt", ",", RowBox[{"pt", "+", "1"}]}], "]"}], "]"}]}], "}"}], "]"}], ",", "\n", RowBox[{"{", RowBox[{ RowBox[{"\"\\"", "\[RuleDelayed]", RowBox[{"(", RowBox[{"pt", "+=", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "0"}], "}"}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[RuleDelayed]", RowBox[{"(", RowBox[{"pt", "+=", RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[RuleDelayed]", RowBox[{"(", RowBox[{"pt", "+=", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[RuleDelayed]", RowBox[{"(", RowBox[{"pt", "+=", RowBox[{"{", RowBox[{"0", ",", RowBox[{"-", "1"}]}], "}"}]}], ")"}]}]}], "}"}]}], "]"}]}], "]"}]], "Input", CellChangeTimes->{{3.3942210443249598`*^9, 3.3942210518158803`*^9}, 3.394221348358201*^9, {3.394221408786298*^9, 3.3942214317698045`*^9}, { 3.394221493940441*^9, 3.3942215246351905`*^9}, {3.3942215998648653`*^9, 3.3942216360376005`*^9}, {3.394221736363864*^9, 3.394221851661953*^9}, { 3.3942218954658136`*^9, 3.3942218958463683`*^9}, 3.3942219965131273`*^9, { 3.3942220370722575`*^9, 3.39422204639585*^9}, {3.394222120353671*^9, 3.3942221233981094`*^9}, {3.3942221817431693`*^9, 3.394222189504484*^9}, { 3.395503007895559*^9, 3.395503092959571*^9}, {3.3955041742960205`*^9, 3.3955041804349704`*^9}}], Cell[BoxData[ DynamicModuleBox[{$CellContext`pt$$ = {2, 0}}, TagBox[ GraphicsBox[{LineBox[{{0, 0}, {3, 0}, {3, 3}, {0, 3}, {0, 0}}], DynamicBox[Typeset`ToBoxes[ Rectangle[$CellContext`pt$$, $CellContext`pt$$ + 1], StandardForm, Graphics], ImageSizeCache->{{133.32, 197.96}, {27.1584, 91.79840000000002}}]}, ImageSize->{135.33333333333334`, Automatic}], EventHandlerTag[{ "LeftArrowKeyDown" :> AddTo[$CellContext`pt$$, {-1, 0}], "RightArrowKeyDown" :> AddTo[$CellContext`pt$$, {1, 0}], "UpArrowKeyDown" :> AddTo[$CellContext`pt$$, {0, 1}], "DownArrowKeyDown" :> AddTo[$CellContext`pt$$, {0, -1}], PassEventsDown -> Automatic, PassEventsUp -> True}]], DynamicModuleValues:>{}]], "Output", CellChangeTimes->{3.3955030934402723`*^9, 3.395504181115963*^9}] }, Open ]], Cell[TextData[{ "Observe that the arrow key affect the position of the square only if the \ cursor is ", StyleBox["inside", FontSlant->"Italic"], " the ", Cell[BoxData["Output"]], " cell. Otherwise, the event handlers for the notebook take precedence and \ interpret the arrow keys are moving the cursor inside the current notebook. \ To further illustrate the crucial role of the cursor location in processing \ events, let's modify the example slightly and add a ", Cell[BoxData["Panel"]], " around the call to ", Cell[BoxData["EventHandler"]], "." }], "Text", CellChangeTimes->{{3.395504193303732*^9, 3.3955042735807652`*^9}, { 3.3955050455461917`*^9, 3.39550504859063*^9}, {3.395505387684986*^9, 3.395505396137308*^9}, {3.399295016124608*^9, 3.399295018107519*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"DynamicModule", "[", RowBox[{ RowBox[{"{", RowBox[{"pt", "=", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], "}"}], ",", "\n", RowBox[{"Panel", "[", RowBox[{"EventHandler", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Graphics", "[", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"Line", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], "}"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Dynamic", "[", RowBox[{"Rectangle", "[", RowBox[{"pt", ",", RowBox[{"pt", "+", "1"}]}], "]"}], "]"}]}], "}"}], "]"}], ",", "\n", RowBox[{"{", RowBox[{ RowBox[{"\"\\"", "\[RuleDelayed]", RowBox[{"(", RowBox[{"pt", "+=", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "0"}], "}"}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[RuleDelayed]", RowBox[{"(", RowBox[{"pt", "+=", RowBox[{"{", RowBox[{"1", ",", "0"}], "}"}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[RuleDelayed]", RowBox[{"(", RowBox[{"pt", "+=", RowBox[{"{", RowBox[{"0", ",", "1"}], "}"}]}], ")"}]}], ",", "\[IndentingNewLine]", RowBox[{"\"\\"", "\[RuleDelayed]", RowBox[{"(", RowBox[{"pt", "+=", RowBox[{"{", RowBox[{"0", ",", RowBox[{"-", "1"}]}], "}"}]}], ")"}]}]}], "}"}]}], "]"}], "]"}]}], "]"}]], "Input", CellChangeTimes->{{3.3942210443249598`*^9, 3.3942210518158803`*^9}, 3.394221348358201*^9, {3.394221408786298*^9, 3.3942214317698045`*^9}, { 3.394221493940441*^9, 3.3942215246351905`*^9}, {3.3942215998648653`*^9, 3.3942216360376005`*^9}, {3.394221736363864*^9, 3.394221851661953*^9}, { 3.3942218954658136`*^9, 3.3942218958463683`*^9}, 3.3942219965131273`*^9, { 3.3942220370722575`*^9, 3.39422204639585*^9}, {3.394222120353671*^9, 3.3942221233981094`*^9}, {3.3942221817431693`*^9, 3.394222189504484*^9}, { 3.395503007895559*^9, 3.395503092959571*^9}, {3.3955041742960205`*^9, 3.3955041804349704`*^9}, {3.3955053335460587`*^9, 3.3955054107886677`*^9}}], Cell[BoxData[ DynamicModuleBox[{$CellContext`pt$$ = {-21, 45}}, PanelBox[ TagBox[ GraphicsBox[{LineBox[{{0, 0}, {3, 0}, {3, 3}, {0, 3}, {0, 0}}], DynamicBox[Typeset`ToBoxes[ Rectangle[$CellContext`pt$$, $CellContext`pt$$ + 1], StandardForm, Graphics], ImageSizeCache->{{5.319999999999965, 15.95999999999998}, {-251.8928, -241.2528}}]}, ImageSize->{177.9999999999999, Automatic}], EventHandlerTag[{ "LeftArrowKeyDown" :> AddTo[$CellContext`pt$$, {-1, 0}], "RightArrowKeyDown" :> AddTo[$CellContext`pt$$, {1, 0}], "UpArrowKeyDown" :> AddTo[$CellContext`pt$$, {0, 1}], "DownArrowKeyDown" :> AddTo[$CellContext`pt$$, {0, -1}], PassEventsDown -> Automatic, PassEventsUp -> True}]]], DynamicModuleValues:>{}]], "Output", CellChangeTimes->{3.3955053770795245`*^9, 3.395505411800143*^9}] }, Open ]], Cell[TextData[{ "Observe that the simply placing the cursor inside the ", Cell[BoxData["Output"]], " cell does not guarantee that the arrow keys controls the movement of the \ square. To move the square, the inner graphic must be selected. Note that \ if we move the call to ", Cell[BoxData["Panel"]], " inside ", Cell[BoxData["EventHandler"]], ", the behavior returns to that of the first example. " }], "Text", CellChangeTimes->{{3.3955054324602623`*^9, 3.3955055682582383`*^9}, { 3.3955056013464766`*^9, 3.3955056467426586`*^9}, {3.3955085473013*^9, 3.395508549073885*^9}, 3.3992950204409437`*^9}], Cell["\<\ We next consider the case when multiple event happen simultaneously.\ \>", "Text", CellChangeTimes->{{3.3955054324602623`*^9, 3.3955055682582383`*^9}, { 3.3955056013464766`*^9, 3.3955056467426586`*^9}, 3.399295021532546*^9}], Cell[CellGroupData[{ Cell["Exercise", "Exercise", CellChangeTimes->{{3.395504287871599*^9, 3.3955042906155996`*^9}}], Cell[TextData[{ StyleBox["Continuing with the previous example's ", FontColor->RGBColor[0.5, 0, 0.5]], Cell[BoxData["Panel"], FontColor->RGBColor[0.5, 0, 0.5]], StyleBox[", hold down an arrow key. What happens? Hold down the left arrow \ key and without releasing this key hold down the up arrow key. What happens? \ Now, repeat these two actions and then release the up arrow key while still \ holding the left arrow key down. What happens? What probably should have \ happened instead?", FontColor->RGBColor[0.5, 0, 0.5]] }], "ExerciseText", CellChangeTimes->{{3.395504296774579*^9, 3.3955044680442677`*^9}, { 3.395504516875458*^9, 3.395504530955985*^9}, {3.45961571121875*^9, 3.459615825765625*^9}}], Cell[TextData[{ "As the exercise above demonstrated, ", StyleBox["Mathematica", FontSlant->"Italic"], "'s behavior when multiple event happen simultaneously is sometimes \ mysterious. Unfortunately, the ", Cell[BoxData[ RowBox[{"Documentation", " ", "Center"}]]], " does not contain much information on this topic. For now, we will simple \ avoid situations where multiple events happen simultaneously." }], "Text", CellChangeTimes->{{3.395504559447522*^9, 3.3955045989451046`*^9}, { 3.3955047237270203`*^9, 3.395504786358329*^9}, {3.395504824383765*^9, 3.395504840367067*^9}, {3.3955048757486486`*^9, 3.395504909507865*^9}, { 3.3955049428765125`*^9, 3.3955049549841633`*^9}, {3.3955050645438876`*^9, 3.39550509278506*^9}}] }, Open ]], Cell[CellGroupData[{ Cell["Exercise", "Exercise", CellChangeTimes->{{3.3955035754529843`*^9, 3.395503577245598*^9}}], Cell[TextData[{ StyleBox["Since using buttons is an awkward method for moving our spaceship, \ modify ", FontColor->RGBColor[0.5, 0, 0.5]], StyleBox["Disasteroids", FontSlant->"Italic", FontColor->RGBColor[0.5, 0, 0.5]], StyleBox[" to use arrow keys in place of buttons. In particular, use the up \ arrow for forward, the down arrow for backward, the left arrow for rotate \ counterclockwise and the right arrow for rotate clockwise. ", FontColor->RGBColor[0.5, 0, 0.5]] }], "ExerciseText", CellChangeTimes->{{3.395503585357424*^9, 3.3955036146000557`*^9}, { 3.3955056614741354`*^9, 3.3955056764159184`*^9}, {3.3955080537217245`*^9, 3.395508123543516*^9}}] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell["Event handling for mouse input", "Section", CellChangeTimes->{{3.3955021152341733`*^9, 3.395502134692541*^9}, { 3.3955027848704166`*^9, 3.3955027855614243`*^9}}], Cell[TextData[{ "By changing the events passed to ", Cell[BoxData["EventHandler"]], ", we can modify how we control the position of the square in our example. \ Observe that because the event ", Cell[BoxData["\<\"MouseDown\"\>"]], " is associated with setting the value for the variable ", Cell[BoxData["pt"]], ", we can no longer user the mouse to resize the graphic." }], "Text", CellChangeTimes->{{3.3944623537038083`*^9, 3.394462366502467*^9}, { 3.394462537131222*^9, 3.3944625400655003`*^9}, {3.395508398384198*^9, 3.395508512560653*^9}, {3.3955085766641073`*^9, 3.3955085773751445`*^9}}], Cell[CellGroupData[{ Cell[BoxData[ RowBox[{"DynamicModule", "[", RowBox[{ RowBox[{"{", RowBox[{"pt", "=", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], "}"}], ",", "\n", RowBox[{"Panel", "[", RowBox[{"EventHandler", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Graphics", "[", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"Line", "[", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"3", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "3"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "0"}], "}"}]}], "}"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Dynamic", "[", RowBox[{"Rectangle", "[", RowBox[{"pt", ",", RowBox[{"pt", "+", "1"}]}], "]"}], "]"}]}], "}"}], "]"}], ",", "\n", RowBox[{"{", RowBox[{"\"\\"", "\[RuleDelayed]", RowBox[{"(", RowBox[{"pt", "=", RowBox[{"Floor", "[", RowBox[{"MousePosition", "[", "\"\\"", "]"}], "]"}]}], ")"}]}], "}"}]}], "]"}], "]"}]}], "]"}]], "Input", CellChangeTimes->{{3.3942210443249598`*^9, 3.3942210518158803`*^9}, 3.394221348358201*^9, {3.394221408786298*^9, 3.3942214317698045`*^9}, { 3.394221493940441*^9, 3.3942215246351905`*^9}, {3.3942215998648653`*^9, 3.3942216360376005`*^9}, {3.394221736363864*^9, 3.394221851661953*^9}, { 3.3942218954658136`*^9, 3.3942218958463683`*^9}, 3.3942219965131273`*^9, { 3.3942220370722575`*^9, 3.39422204639585*^9}, {3.394222120353671*^9, 3.3942221233981094`*^9}, {3.3942221817431693`*^9, 3.394222189504484*^9}, { 3.395503007895559*^9, 3.395503092959571*^9}, {3.3955041742960205`*^9, 3.3955041804349704`*^9}, {3.3955053335460587`*^9, 3.3955054107886677`*^9}, {3.395508214426011*^9, 3.395508352797739*^9}}], Cell[BoxData[ DynamicModuleBox[{$CellContext`pt$$ = {0, 0}}, PanelBox[ TagBox[ GraphicsBox[{LineBox[{{0, 0}, {3, 0}, {3, 3}, {0, 3}, {0, 0}}], DynamicBox[Typeset`ToBoxes[ Rectangle[$CellContext`pt$$, $CellContext`pt$$ + 1], StandardForm, Graphics], ImageSizeCache->{{10.78, 183.26}, {79.30880000000005, 251.78880000000004`}}]}], EventHandlerTag[{"MouseDown" :> ($CellContext`pt$$ = Floor[ MousePosition["Graphics"]]), PassEventsDown -> Automatic, PassEventsUp -> True}]]], DynamicModuleValues:>{}]], "Output", CellChangeTimes->{{3.3955082808628674`*^9, 3.395508295093614*^9}, { 3.395508331436598*^9, 3.395508353929389*^9}}] }, Open ]], Cell[TextData[{ "Observe that we use the function ", Cell[BoxData["MousePosition"]], " to capture the current position of the mouse at the time of the click. \ The option ", Cell[BoxData["\<\"Graphics\"\>"]], " specified that the position should be given in terms of the currently \ selected graphic (i.e., the white square)." }], "Text", CellChangeTimes->{{3.3942077337198076`*^9, 3.394207735011691*^9}, { 3.394209086451917*^9, 3.394209091469232*^9}, {3.3942882541366777`*^9, 3.394288257761854*^9}, {3.394462500908414*^9, 3.3944625315831337`*^9}, { 3.3944625844101486`*^9, 3.3944625928023834`*^9}, {3.394462680940878*^9, 3.394462690034135*^9}, 3.395502812290392*^9, 3.3955084467847605`*^9, { 3.3955086039839363`*^9, 3.395508666294778*^9}, {3.460198423203125*^9, 3.4601984409375*^9}}], Cell[CellGroupData[{ Cell["Exercises", "Exercise", CellChangeTimes->{{3.395508703128476*^9, 3.395508704991192*^9}, 3.459616007046875*^9}], Cell[TextData[StyleBox["1. Modify the example above so that square can be \ positioned by dragging the mouse. Next, remove the restriction that the \ square lie on a grid and allow it to move continuously.", FontColor->RGBColor[0.5, 0, 0.5]]], "ExerciseText", CellChangeTimes->{{3.395508722616888*^9, 3.395508723047516*^9}, { 3.395508766400719*^9, 3.3955087842467365`*^9}, {3.395508850142804*^9, 3.395508891172621*^9}, {3.3955089355072546`*^9, 3.395509020831647*^9}, { 3.3955840937775164`*^9, 3.3955840985844765`*^9}}], Cell[TextData[{ StyleBox["2. Modify ", FontColor->RGBColor[0.5, 0, 0.5]], StyleBox["Disasteroids", FontSlant->"Italic", FontColor->RGBColor[0.5, 0, 0.5]], StyleBox[" to use the mouse instead of arrow keys. In particular, the ship \ should slow rotate towards to current mouse position when the mouse is \ clicked while simultaneously moving forward. You may find the helper \ function ", FontColor->RGBColor[0.5, 0, 0.5]], Cell[BoxData["vectorToAngle"], FontColor->RGBColor[0.5, 0, 0.5]], StyleBox[" given below helpful in determining an orientation ", FontColor->RGBColor[0.5, 0, 0.5]], Cell[BoxData["\[Theta]"], FontColor->RGBColor[0.5, 0, 0.5]], StyleBox[" from the mouse position. ", FontColor->RGBColor[0.5, 0, 0.5]], Cell[BoxData["vectorToAngle"], FontColor->RGBColor[0.5, 0, 0.5]], StyleBox[" that return the angle ", FontColor->RGBColor[0.5, 0, 0.5]], Cell[BoxData["\[Theta]"], FontColor->RGBColor[0.5, 0, 0.5]], StyleBox[" associated with the unit vector ", FontColor->RGBColor[0.5, 0, 0.5]], Cell[BoxData[ RowBox[{"{", RowBox[{ RowBox[{"Cos", "[", "\[Theta]", "]"}], ",", RowBox[{"Sin", "[", "\[Theta]", "]"}]}], "}"}]], FontColor->RGBColor[0.5, 0, 0.5]], StyleBox[" for ", FontColor->RGBColor[0.5, 0, 0.5]], Cell[BoxData[ RowBox[{"0", "\[LessEqual]", "\[Theta]", "\[LessEqual]", RowBox[{"2", "\[Pi]"}]}]], FontColor->RGBColor[0.5, 0, 0.5]], StyleBox[".", FontColor->RGBColor[0.5, 0, 0.5]] }], "ExerciseText", CellChangeTimes->{{3.395508722616888*^9, 3.395508723047516*^9}, { 3.395508766400719*^9, 3.3955087842467365`*^9}, {3.395508850142804*^9, 3.395508891172621*^9}, {3.3955089355072546`*^9, 3.395509020831647*^9}, { 3.3955840937775164`*^9, 3.3955842224438124`*^9}, {3.395585256420909*^9, 3.3955852722237897`*^9}, {3.395585321555217*^9, 3.3955853798796644`*^9}, { 3.395585415391082*^9, 3.3955854444431458`*^9}, {3.3955854745066752`*^9, 3.395585478342229*^9}, {3.395601205784*^9, 3.395601232452614*^9}, { 3.395601265510478*^9, 3.3956013507138443`*^9}}], Cell[BoxData[ RowBox[{ RowBox[{"vectorToAngle", "[", RowBox[{"{", RowBox[{"x_", ",", "y_"}], "}"}], "]"}], ":=", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"y", "\[GreaterEqual]", "0"}], ",", RowBox[{"ArcCos", "[", "x", "]"}], ",", RowBox[{ RowBox[{"2", "\[Pi]"}], "-", RowBox[{"ArcCos", "[", "x", "]"}]}]}], "]"}]}]], "Input", CellChangeTimes->{{3.394462114505088*^9, 3.3944621175595407`*^9}, { 3.394462182233827*^9, 3.3944622029840784`*^9}, {3.394559454232637*^9, 3.3945594679125805`*^9}, {3.3954154048541527`*^9, 3.395415411063143*^9}, { 3.395417155168434*^9, 3.3954171685077477`*^9}, {3.39560065538708*^9, 3.3956006783703575`*^9}, {3.395600843088854*^9, 3.3956008457527103`*^9}, { 3.3956011206206923`*^9, 3.3956011318769903`*^9}, {3.39560125565621*^9, 3.3956012565975733`*^9}}], Cell[TextData[StyleBox["One you have finished your implementation, experiment \ with repeated clicks with mouse to see if the ship ever arrives at the mouse. \ Test various starting locations for the ship relative to the mouse. Feel \ free to implement a better control scheme with the mouse if you can think of \ one.", FontColor->RGBColor[0.5, 0, 0.5]]], "ExerciseText", CellChangeTimes->{{3.395508722616888*^9, 3.395508723047516*^9}, { 3.395508766400719*^9, 3.3955087842467365`*^9}, {3.395508850142804*^9, 3.395508891172621*^9}, {3.3955089355072546`*^9, 3.395509020831647*^9}, { 3.3955840937775164`*^9, 3.3955842224438124`*^9}, {3.395585256420909*^9, 3.3955852722237897`*^9}, {3.395585321555217*^9, 3.3955853798796644`*^9}, { 3.395585415391082*^9, 3.3955854444431458`*^9}, {3.3956013600573726`*^9, 3.39560136321194*^9}, 3.3992950235254717`*^9}] }, Open ]] }, Open ]] }, WindowToolbars->{}, WindowSize->{1016, 668}, WindowMargins->{{0, Automatic}, {Automatic, 0}}, PrintingCopies->1, PrintingPageRange->{1, Automatic}, PrintingOptions->{"PrintCellBrackets"->False, "PrintMultipleHorizontalPages"->False, "PrintRegistrationMarks"->True, "PrintingMargins"->{{54, 54}, {72, 72}}}, ShowSelection->True, Magnification->1.5, FrontEndVersion->"7.0 for Microsoft Windows (32-bit) (November 10, 2008)", StyleDefinitions->"Classroom.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[545, 20, 606, 10, 83, "Title"], Cell[1154, 32, 447, 9, 93, "Subtitle"], Cell[1604, 43, 996, 20, 85, "Text"], Cell[CellGroupData[{ Cell[2625, 67, 451, 9, 81, "Section"], Cell[3079, 78, 384, 8, 60, "Text"], Cell[3466, 88, 1389, 42, 180, "Input"], Cell[4858, 132, 253, 8, 36, "Text"], Cell[CellGroupData[{ Cell[5136, 144, 3388, 75, 313, "Input"], Cell[8527, 221, 5257, 137, 482, "Output"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[13833, 364, 752, 13, 81, "Section"], Cell[14588, 379, 1354, 31, 134, "Text"], Cell[15945, 412, 1252, 26, 109, "Text"], Cell[17200, 440, 1148, 27, 87, "Text"], Cell[CellGroupData[{ Cell[18373, 471, 880, 23, 205, "Input", CellID->160409786], Cell[19256, 496, 176, 3, 68, "Output"] }, Open ]], Cell[19447, 502, 1285, 32, 162, "Text"], Cell[CellGroupData[{ Cell[20757, 538, 94, 1, 56, "Exercise"], Cell[20854, 541, 558, 14, 61, "ExerciseText"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[21461, 561, 224, 3, 81, "Section"], Cell[21688, 566, 979, 22, 110, "Text"], Cell[22670, 590, 574, 14, 86, "Text"], Cell[CellGroupData[{ Cell[23269, 608, 2652, 67, 286, "Input"], Cell[25924, 677, 823, 16, 251, "Output"] }, Open ]], Cell[26762, 696, 787, 18, 112, "Text"], Cell[CellGroupData[{ Cell[27574, 718, 2788, 68, 286, "Input"], Cell[30365, 788, 875, 18, 582, "Output"] }, Open ]], Cell[31255, 809, 618, 13, 87, "Text"], Cell[31876, 824, 238, 4, 52, "Text"], Cell[CellGroupData[{ Cell[32139, 832, 96, 1, 84, "Exercise"], Cell[32238, 835, 723, 14, 165, "ExerciseText"], Cell[32964, 851, 746, 15, 127, "Text"] }, Open ]], Cell[CellGroupData[{ Cell[33747, 871, 96, 1, 84, "Exercise"], Cell[33846, 874, 674, 14, 126, "ExerciseText"] }, Open ]] }, Open ]], Cell[CellGroupData[{ Cell[34569, 894, 170, 2, 121, "Section"], Cell[34742, 898, 606, 12, 129, "Text"], Cell[CellGroupData[{ Cell[35373, 914, 2091, 48, 307, "Input"], Cell[37467, 964, 699, 15, 930, "Output"] }, Open ]], Cell[38181, 982, 812, 15, 93, "Text"], Cell[CellGroupData[{ Cell[39018, 1001, 121, 2, 84, "Exercise"], Cell[39142, 1005, 528, 7, 90, "ExerciseText"], Cell[39673, 1014, 2052, 49, 166, "ExerciseText"], Cell[41728, 1065, 857, 18, 145, "Input"], Cell[42588, 1085, 872, 12, 126, "ExerciseText"] }, Open ]] }, Open ]] } ] *) (* End of internal cache information *)