0
$\begingroup$

I am trying to create an image function:

image = Rasterize[ImageResize[ExampleData[{"TestImage", "Mandrill"}], 300], ImageResolution -> 72];

Manipulate[LocatorPane[Dynamic[{p1, p2}], 
Grid[{{
 ap[{pix[image, p1], pix[image, p2]}], 
 image
}}]], 
{{p1, {1, 1}}, Locator, Appearance -> Style[Graphics[{White, Disk[{1, 1}, 1.2], 
     RGBColor[PixelValue[image, p1]], Disk[{1, 1}, 1]}, ImageSize -> 20]]}, 
{{p2, {1, 1}}, Locator, Appearance -> Style[Graphics[{White, Disk[{1, 1}, 1.2], 
     RGBColor[PixelValue[image, p2]], Disk[{1, 1}, 1]}, ImageSize -> 20]]}]

enter image description here

but when I try to add a colour wheel:

Manipulate[LocatorPane[Dynamic[{p1, p2}], 
Grid[{{
 ap[{pix[image, p1], pix[image, p2]}], 
 (*colour wheel added here*)
 cw[{pix[image, p1], pix[image, p2]}], 
 image
}}]], 
{{p1, {1, 1}}, Locator, Appearance -> Style[Graphics[{White, Disk[{1, 1}, 1.2], 
     RGBColor[PixelValue[image, p1]], Disk[{1, 1}, 1]}, ImageSize -> 20]]}, 
{{p2, {1, 1}}, Locator, Appearance -> Style[Graphics[{White, Disk[{1, 1}, 1.2], 
     RGBColor[PixelValue[image, p2]], Disk[{1, 1}, 1]}, ImageSize -> 20]]}]

enter image description here

The locators jump to the coordinates in the colour wheel rather than the image. Where am I going wrong with my syntax?

I am using the above with with these functions:

pix[image_, px_] := (Evaluate[InputForm[ColorConvert[PixelValue[image, px], "HSB"]]][[1,#1]] & ) /@ 
Range[3]; 
cw[list_] := Graphics[{Apply[Polygon[{{0, 0}, First[#1], First[#2]}, 
    VertexColors -> Hue /@ {{0, 0, 1}, Last[#1], Last[#2]}] & , 
  Partition[(Append[#1, First[#1]] & )[Table[{r*{Cos[phi], Sin[phi]}, phi/(2*Pi)}, 
      {phi, 0, 2*Pi, 0.1}, {r, 0, 1, 0.1}][[All,-1,{1, 2}]]], 2, 1], {1}], 
 EdgeForm[Directive[White]], 
 ((Thread[{Hue[#1, #2, #3], Disk[#2*{Cos[360*#1*Degree], Sin[360*#1*Degree]}, 0.1]}] & ) @@ 
    #1 & ) /@ list}]; 
ap[list_] := (ArrayPlot[Partition[Apply[Hue[#1, #2, #3] & , #1, {1}], UpTo[3]], ImageSize -> 200] & )[
list]; 
$\endgroup$

1 Answer 1

3
$\begingroup$

The LocatorPane seems to get confused about what part of the 2nd argument is supposed to be the domain of the locators. It's better to disentangle this a bit:

DynamicModule[{p1 = {1, 1}, p2 = {1, 1}},
 Grid[{{
    Dynamic[ap[{pix[image, p1], pix[image, p2]}]],(*colour wheel added here*)           
    Dynamic[cw[{pix[image, p1], pix[image, p2]}]],
    LocatorPane[Dynamic[{p1, p2}],
     image,
     Appearance -> {Dynamic @ Style[Graphics[{White, Disk[{1, 1}, 1.2], 
           RGBColor[PixelValue[image, p1]], Disk[{1, 1}, 1]}, 
          ImageSize -> 20]],
       Dynamic @ Style[Graphics[{White, Disk[{1, 1}, 1.2], 
           RGBColor[PixelValue[image, p2]], Disk[{1, 1}, 1]}, 
          ImageSize -> 20]]
       }
     ]
    }}
  ]
 ]
$\endgroup$
1
  • $\begingroup$ perfect! thank you! $\endgroup$
    – martin
    Mar 16, 2021 at 19:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.