Dynamically getting the complex number in a color wheel via moving mouse?

You can add a Locator to this answer by halirutan:

With[{pts = Append[#, First[#]] & @ Table[{r {Cos[phi], Sin[phi]}, phi/(2 Pi)}, 
    {phi, 0, 2 Pi, .1}, {r, 0, 1, .1}]}, 
 DynamicModule[{pt = {.5, .5}}, 
  Graphics[{Polygon[{{0, 0}, First[#1], First[#2]}, 
       VertexColors -> (Hue /@ {{0, 0, 1}, Last[#1], Last[#2]})] & @@@
      Partition[pts[[All, -1, {1, 2}]], 2, 1],
   Locator[Dynamic[pt, (pt = If[Norm[#] < 1, #, Normalize[#]]) &], 
     Style["●", FontSize -> 16]]}, PlotLabel -> Dynamic[Style[pt, 16]]]]]

enter image description here


Here is kglr's solution rewritten using LocatorPane, which I think makes the code a little simpler and perhaps clearer. I have also made some changes.

  • the locator is configured to appear a sa disk
  • the plot label shows the position of the disk as a complex number
With[
  {pts =
     Append[
       #,
       First[#]]& @ Table[{r {Cos[phi], Sin[phi]}, phi/(2 Pi)}, 
                          {phi, 0, 2 Pi, .1}, {r, 0, 1, .1}]},
  DynamicModule[{pt = {.5, .5}},
    LocatorPane[
      Dynamic[pt, (pt = If[Norm[#] < 1, #, Normalize[#]]) &], 
      Graphics[
        {Polygon[{{0, 0}, First[#1], First[#2]}, 
           VertexColors -> (Hue /@ {{0, 0, 1}, Last[#1], Last[#2]})]& @@@
         Partition[pts[[All, -1, {1, 2}]], 2, 1]}, 
        PlotLabel -> Dynamic[Style[Complex @@ pt, 16, Black]]], 
      Appearance -> Graphics[{Disk[pt, Scaled[.01]]}]]]]

pane

Update

The following code allows the user to add and remove points from the graphics.

With[
  {pts =
     Append[
      #, 
      First[#]]& @ Table[{r {Cos[phi], Sin[phi]}, phi/(2 Pi)}, 
                         {phi, 0, 2 Pi, .1}, {r, 0, 1, .1}]},
  DynamicModule[{constrain, dots = {{.5, .5}}},
    constrain = If[Norm[#] < 1, #, Normalize[#]] &;
    LocatorPane[
      Dynamic[dots, (dots = constrain /@ #) &], 
      Graphics[
        {Polygon[
           {{0, 0}, First[#1], First[#2]}, 
            VertexColors -> 
              (Hue /@ {{0, 0, 1}, Last[#1], Last[#2]})] & @@@
         Partition[pts[[All, -1, {1, 2}]], 2, 1],
         Dynamic[Disk[#, Scaled[.01]] & /@ dots]},
        PlotLabel -> Dynamic[Style[Column[Complex @@@ dots], 16, Black]]],
      LocatorAutoCreate -> True,
      Appearance -> None]]]

pane

Note

In V11.3, the Documentation Center's instructions for adding and deleting locators are wrong, at least for Mathematica running on MacOS. The correct way to do it is:

  • Add a locator: left click on it while holding down Command+Option
  • Remove a locator: left click on it while holding down Command