Cell[CellGroupData[{Cell[BoxData[ RowBox[{"Manipulate", "[", " ", RowBox[{ RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{"cf", "=", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"a", "<", "b"}], ",", "Rest", ",", "Identity"}], "]"}], "@", RowBox[{"ContinuedFraction", "[", RowBox[{"a", "/", "b"}], "]"}]}]}], "}"}], ",", " ", RowBox[{"Part", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"Graphics", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"PointSize", "[", ".007", "]"}], ",", RowBox[{"{", RowBox[{ RowBox[{"GrayLevel", "[", ".75", "]"}], ",", RowBox[{"Rectangle", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"-", "a"}], ",", "0"}], "}"}], ",", RowBox[{"{", RowBox[{"0", ",", "b"}], "}"}]}], "]"}]}], "}"}], ",", "#", ",", RowBox[{"Table", "[", RowBox[{ RowBox[{"Point", "[", RowBox[{"{", RowBox[{ RowBox[{"-", "i"}], ",", "j"}], "}"}], "]"}], ",", RowBox[{"{", RowBox[{"i", ",", "0", ",", "a"}], "}"}], ",", RowBox[{"{", RowBox[{"j", ",", "0", ",", "b"}], "}"}]}], "]"}]}], "}"}], ",", RowBox[{"PlotRange", "->", RowBox[{"If", "[", RowBox[{ RowBox[{"a", "<", "b"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"-", RowBox[{"(", RowBox[{"b", "+", "a", "+", "1"}], ")"}]}], "/", "2"}], ",", RowBox[{ RowBox[{"(", RowBox[{"b", "-", "a", "+", "1"}], ")"}], "/", "2"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"-", ".5"}], ",", RowBox[{"b", "+", ".5"}]}], "}"}]}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"-", "a"}], "-", ".5"}], ",", ".5"}], "}"}], ",", RowBox[{"{", RowBox[{ RowBox[{ RowBox[{"-", RowBox[{"(", RowBox[{"a", "-", "b", "+", "1"}], ")"}]}], "/", "2"}], ",", RowBox[{ RowBox[{"(", RowBox[{"a", "+", "b", "+", "1"}], ")"}], "/", "2"}]}], "}"}]}], "}"}]}], "]"}]}], ",", RowBox[{"PlotLabel", "->", RowBox[{"Style", "[", RowBox[{ RowBox[{"Row", "[", RowBox[{"{", RowBox[{ "\"\\"", ",", "a", ",", "\"\< and \>\"", ",", "b", ",", "\"\< is \>\"", ",", RowBox[{"GCD", "[", RowBox[{"a", ",", "b"}], "]"}], ",", " ", "\"\<.\>\""}], "}"}], "]"}], ",", "16"}], "]"}]}], ",", RowBox[{"ImageSize", "->", RowBox[{"{", RowBox[{"450", ",", "450"}], "}"}]}]}], "]"}], "&"}], "/@", RowBox[{"FoldList", "[", RowBox[{"Append", ",", RowBox[{"{", "}"}], ",", RowBox[{"MapIndexed", "[", RowBox[{ RowBox[{ RowBox[{"With", "[", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"min", "=", RowBox[{"#1", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "1"}], "}"}]}]}], ",", RowBox[{"max", "=", RowBox[{ RowBox[{"(", RowBox[{"#1", "-", RowBox[{"Min", "[", "#1", "]"}]}], ")"}], " ", RowBox[{"{", RowBox[{ RowBox[{"-", "1"}], ",", "1"}], "}"}]}]}]}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{ RowBox[{"Hue", "[", RowBox[{ RowBox[{ RowBox[{"Position", "[", RowBox[{ RowBox[{"Rest", "[", RowBox[{"FoldList", "[", RowBox[{"Plus", ",", "0", ",", "cf"}], "]"}], "]"}], ",", RowBox[{"n_", "/;", RowBox[{ RowBox[{ RowBox[{ "#2", "[[", "1", "]]"}], "-", "1"}], "<", "n"}]}], ",", "1", ",", "1"}], "]"}], "[[", "1", "]]"}], "/", RowBox[{"Length", "[", "cf", "]"}]}], "]"}], ",", RowBox[{"Rectangle", "[", RowBox[{"min", ",", "max"}], "]"}]}], "}"}], ",", RowBox[{"Line", "[", RowBox[{"{", RowBox[{"min", ",", RowBox[{"{", RowBox[{ RowBox[{ "min", "[[", "1", "]]"}], ",", RowBox[{ "max", "[[", "2", "]]"}]}], "}"}], ",", "max", ",", RowBox[{"{", RowBox[{ RowBox[{ "max", "[[", "1", "]]"}], ",", RowBox[{ "min", "[[", "2", "]]"}]}], "}"}], ",", "min"}], "}"}], "]"}]}], "}"}]}], "]"}], "&"}], ",", RowBox[{"Drop", "[", RowBox[{ RowBox[{"FixedPointList", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{"#1", ">", "#2"}], ",", RowBox[{"{", RowBox[{ RowBox[{"#1", "-", "#2"}], ",", "#2"}], "}"}], ",", RowBox[{"{", RowBox[{"#1", ",", RowBox[{"#2", "-", "#1"}]}], "}"}]}], "]"}], "&"}], "@@", "#"}], "&"}], ",", RowBox[{"{", RowBox[{"a", ",", "b"}], "}"}]}], "]"}], ",", RowBox[{"-", "2"}]}], "]"}]}], "]"}]}], "]"}]}], ",", RowBox[{ RowBox[{"\[LeftCeiling]", RowBox[{"n", " ", RowBox[{"Total", "[", "cf", "]"}]}], "\[RightCeiling]"}], "+", "1"}]}], "]"}]}], "]"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"a", ",", "10", ",", "\"\\""}], "}"}], ",", "1", ",", "15", ",", "1"}], "}"}], ",", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"b", ",", "3", ",", "\"\\""}], "}"}], ",", "1", ",", "15", ",", "1"}], "}"}], ",", " ", "Delimiter", ",", " ", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"n", ",", "1", ",", "\"\\""}], "}"}], ",", "0", ",", "1"}], "}"}], ",", RowBox[{"AutorunSequencing", "->", RowBox[{"{", RowBox[{ RowBox[{"{", RowBox[{"1", ",", "6"}], "}"}], ",", RowBox[{"{", RowBox[{"2", ",", "6"}], "}"}]}], "}"}]}]}], "]"}]], "Input", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{{3.3579926156514*^9, 3.35799267698692*^9}, { 3.35799284202304*^9, 3.35799284514807*^9}, {3.35799290623173*^9, 3.35799291012417*^9}, {3.35799294368924*^9, 3.35799296920861*^9}, { 3.35799301326515*^9, 3.35799302888506*^9}, {3.35800005974995*^9, 3.35800011929044*^9}, {3.35800175485571*^9, 3.35800177439131*^9}, { 3.35800183556624*^9, 3.35800183595661*^9}, {3.35800193460618*^9, 3.3580019378863*^9}, {3.35800206704492*^9, 3.35800213222691*^9}, { 3.35800225773454*^9, 3.35800226203967*^9}, {3.35800819841339*^9, 3.35800821685364*^9}, {3.35800827703516*^9, 3.35800829199451*^9}, { 3.35800832730833*^9, 3.35800849516182*^9}, {3.3580088591026*^9, 3.35800886334992*^9}, {3.35800902379503*^9, 3.35800903131732*^9}, { 3.35800914829923*^9, 3.35800915371242*^9}, {3.35800925524617*^9, 3.35800925648423*^9}, {3.35800932514393*^9, 3.35800932910533*^9}, { 3.35801020822038*^9, 3.35801022229182*^9}, {3.35801034585303*^9, 3.35801038734578*^9}, {3.35801147663891*^9, 3.35801152755758*^9}, { 3.3580115607864*^9, 3.35801158368124*^9}, {3.35801161561784*^9, 3.35801168610196*^9}, {3.35801181027425*^9, 3.35801184574684*^9}, { 3.35801189601805*^9, 3.35801193944445*^9}, {3.35801246421583*^9, 3.35801252429744*^9}, {3.35801291862256*^9, 3.35801296878757*^9}, { 3.35801302876697*^9, 3.35801303930664*^9}, {3.3580132887396*^9, 3.35801332386859*^9}, {3.35801352661468*^9, 3.35801353027322*^9}, { 3.35801389527052*^9, 3.35801389762975*^9}, {3.35801395916418*^9, 3.35801396599952*^9}, {3.35801443395179*^9, 3.35801443509482*^9}, { 3.35801477120335*^9, 3.35801477589518*^9}, {3.3580154334598*^9, 3.35801544552744*^9}, {3.35801587283278*^9, 3.35801589775874*^9}, { 3.35801598263578*^9, 3.35801599675552*^9}, {3.35801680080805*^9, 3.35801680772301*^9}, {3.35807919493024*^9, 3.35807926135306*^9}, { 3.35807932627207*^9, 3.35807937673618*^9}, {3.35807946583092*^9, 3.35807955688297*^9}, {3.35807967388517*^9, 3.35807970914347*^9}, { 3.35807984966359*^9, 3.3580798955368*^9}, {3.35808006847413*^9, 3.35808010870904*^9}, 3.3580801567461*^9, {3.35808035000188*^9, 3.35808035440546*^9}, {3.35808066518802*^9, 3.35808067076895*^9}, { 3.35808094917845*^9, 3.35808095228549*^9}, {3.35808100039378*^9, 3.35808114708331*^9}, {3.35808137172511*^9, 3.35808142203842*^9}, { 3.35808186986866*^9, 3.35808188366162*^9}, {3.35808192617443*^9, 3.35808195248029*^9}, {3.35808213876856*^9, 3.35808217547375*^9}, { 3.35808223307032*^9, 3.35808226960236*^9}, {3.35808241428322*^9, 3.35808241783822*^9}, {3.35808249150257*^9, 3.35808249634886*^9}, { 3.35808267852147*^9, 3.35808273672805*^9}, {3.35808294087252*^9, 3.3580829723397*^9}, {3.35808816260204*^9, 3.35808828409533*^9}, { 3.35808848198643*^9, 3.35808854740407*^9}, {3.35808858861634*^9, 3.35808859438505*^9}, {3.35808878691103*^9, 3.35808878988403*^9}, { 3.35808901242172*^9, 3.35808901683279*^9}, {3.35809088820472*^9, 3.35809088982105*^9}, {3.35809092163614*^9, 3.35809100027773*^9}, { 3.35809106313709*^9, 3.3580911716546*^9}, {3.35809201756376*^9, 3.35809211012404*^9}, {3.35809246818154*^9, 3.35809252330639*^9}, { 3.35809284448531*^9, 3.35809293358538*^9}, {3.35811166713545*^9, 3.35811169977629*^9}, {3.35811202421586*^9, 3.3581120299659*^9}, { 3.35811272622036*^9, 3.35811275161114*^9}, {3.36041521359844*^9, 3.36041521499049*^9}, {3.36240954645544*^9, 3.36240955255031*^9}, { 3.36284652469272*^9, 3.36284654831772*^9}, 3.760818610949789*^9}, CellID->1129047256], Cell[BoxData[ TagBox[ StyleBox[ DynamicModuleBox[{$CellContext`a$$ = 10, $CellContext`b$$ = 3, $CellContext`n$$ = 1, Typeset`show$$ = True, Typeset`bookmarkList$$ = {}, Typeset`bookmarkMode$$ = "Menu", Typeset`animator$$, Typeset`animvar$$ = 1, Typeset`name$$ = "\"untitled\"", Typeset`specs$$ = {{{ Hold[$CellContext`a$$], 10, "first number (width)"}, 1, 15, 1}, {{ Hold[$CellContext`b$$], 3, "second number (height)"}, 1, 15, 1}, {{ Hold[$CellContext`n$$], 1, "step in algorithm"}, 0, 1}}, Typeset`size$$ = {450., {223., 227.}}, Typeset`update$$ = 0, Typeset`initDone$$, Typeset`skipInitDone$$ = True, $CellContext`a$63061$$ = 0, $CellContext`b$63062$$ = 0, $CellContext`n$63063$$ = 0}, DynamicBox[Manipulate`ManipulateBoxes[ 1, StandardForm, "Variables" :> {$CellContext`a$$ = 10, $CellContext`b$$ = 3, $CellContext`n$$ = 1}, "ControllerVariables" :> { Hold[$CellContext`a$$, $CellContext`a$63061$$, 0], Hold[$CellContext`b$$, $CellContext`b$63062$$, 0], Hold[$CellContext`n$$, $CellContext`n$63063$$, 0]}, "OtherVariables" :> { Typeset`show$$, Typeset`bookmarkList$$, Typeset`bookmarkMode$$, Typeset`animator$$, Typeset`animvar$$, Typeset`name$$, Typeset`specs$$, Typeset`size$$, Typeset`update$$, Typeset`initDone$$, Typeset`skipInitDone$$}, "Body" :> With[{$CellContext`cf$ = If[$CellContext`a$$ < $CellContext`b$$, Rest, Identity][ ContinuedFraction[$CellContext`a$$/$CellContext`b$$]]}, Part[ Map[Graphics[{ PointSize[0.007], { GrayLevel[0.75], Rectangle[{-$CellContext`a$$, 0}, { 0, $CellContext`b$$}]}, #, Table[ Point[{-$CellContext`i, $CellContext`j}], \ {$CellContext`i, 0, $CellContext`a$$}, {$CellContext`j, 0, $CellContext`b$$}]}, PlotRange -> If[$CellContext`a$$ < $CellContext`b$$, \ {{(-($CellContext`b$$ + $CellContext`a$$ + 1))/ 2, ($CellContext`b$$ - $CellContext`a$$ + 1)/ 2}, {-0.5, $CellContext`b$$ + 0.5}}, {{-$CellContext`a$$ - 0.5, 0.5}, {(-($CellContext`a$$ - $CellContext`b$$ + 1))/ 2, ($CellContext`a$$ + $CellContext`b$$ + 1)/2}}], PlotLabel -> Style[ Row[{"The greatest common divisor of ", $CellContext`a$$, " and ", $CellContext`b$$, " is ", GCD[$CellContext`a$$, $CellContext`b$$], "."}], 16], ImageSize -> {450, 450}]& , FoldList[Append, {}, MapIndexed[ With[{$CellContext`min$ = # {-1, 1}, $CellContext`max$ = (# - Min[#]) {-1, 1}}, {{ Hue[Part[ Position[ Rest[ FoldList[Plus, 0, $CellContext`cf$]], Condition[ Pattern[$CellContext`n, Blank[]], Part[#2, 1] - 1 < $CellContext`n], 1, 1], 1]/Length[$CellContext`cf$]], Rectangle[$CellContext`min$, $CellContext`max$]}, Line[{$CellContext`min$, { Part[$CellContext`min$, 1], Part[$CellContext`max$, 2]}, $CellContext`max$, { Part[$CellContext`max$, 1], Part[$CellContext`min$, 2]}, $CellContext`min$}]}]& , Drop[ FixedPointList[ Apply[If[# > #2, {# - #2, #2}, {#, #2 - #}]& , #]& , \ {$CellContext`a$$, $CellContext`b$$}], -2]]]], Ceiling[$CellContext`n$$ Total[$CellContext`cf$]] + 1]], "Specifications" :> {{{$CellContext`a$$, 10, "first number (width)"}, 1, 15, 1}, {{$CellContext`b$$, 3, "second number (height)"}, 1, 15, 1}, Delimiter, {{$CellContext`n$$, 1, "step in algorithm"}, 0, 1}}, "Options" :> {AutorunSequencing -> {{1, 6}, {2, 6}}}, "DefaultOptions" :> {ControllerLinking -> True}], ImageSizeCache->{495., {303., 309.}}, SingleEvaluation->True], Deinitialization:>None, DynamicModuleValues:>{}, SynchronousInitialization->True, UnsavedVariables:>{Typeset`initDone$$}, UntrackedVariables:>{Typeset`size$$}], "Manipulate", Deployed->True, StripOnInput->False], Manipulate`InterpretManipulate[1]]], "Output", CellGroupingRules->{"GroupTogetherGrouping", 10000.}, CellChangeTimes->{3.760818610950077*^9}, CellID->377009605] }, {2}]]