3
$\begingroup$
With[{source = ExampleData[{"TestImage", "Lena"}]}, 
  With[{dimensions = ImageDimensions[source]},
    n = 10;
    sub = Subdivide[-1, 1, n];
    grid = 
      Graphics[{}, 
        GridLines -> {sub, sub}, 
        PlotRangePadding -> None, 
        GridLinesStyle -> Directive[White, Thick], 
        ImageSize -> ImageDimensions @ source];
    Manipulate[
      Overlay[{source, grid}],
      {{r, .05,Style["r", Bold, 15]}, .02, .5, .01, ImageSize -> 500}, 
      {{pt, dimensions/2},  Locator,  Appearance -> disk[r]}, 
      Dynamic @ 
        Row[{Style["Posición = ", Bold, 15], Style[{pt[[1]], pt[[2]]}, Bold, 15]}], 
     ControlPlacement -> Top, 
     Initialization :> (
        disk[r_] := 
          Graphics[
            {White, Opacity[.4], EdgeForm[Black], Disk[{0, 0}, ImageScaled[r]]}, 
     ImageSize -> dimensions])]]]

1) I am trying to add a 3rd option:

Overlay[{source, grid, text}],

Where text has to be a lot of references with a static positions over the image.

I tried with:

text = Graphics[{}, Text["Reference1"], {p1x, p1y}];

But it doesn't work! the text appears anywhere!

In this case "Reference1" is the name of a city or place. It has to be static even if I change the scale of the image.

2) I tried to change this too:

{{pt0, {dimensions[[1]], dimensions[[2]]}}, Locator, 
 Appearance -> disk[(r0/dimensions)/proporcion, White]},

I want to see the coordinates over the locator disk. I tried to add Text inside the Disk, outside, and even in the locator itself but it doesn't work.

I saw too that the text can be add inside the Disk but I think that Appearance doesn't support it.

In this case "Reference" is the coordinate of the Locator.

EDIT: (with Answer 1)

My code has 4 disk:

{{pt0, {dimensions[[1]] (0.51), dimensions[[2]] (0.525)}}, Locator,  Appearance -> disk[(r0/dimensions)/proporcion, White, pt0]},

{{pt1, {dimensions[[1]] (0.59), dimensions[[2]] (0.6)}}, Locator,  Appearance -> disk[(r1/dimensions)/proporcion, Red, pt1]},

{{pt2, {dimensions[[1]] (0.465), dimensions[[2]] (0.47)}}, Locator,  Appearance -> disk[(r2/dimensions)/proporcion, Green, pt2]},

{{pt3, {dimensions[[1]] (0.44), dimensions[[2]] (0.6)}}, Locator,  Appearance -> disk[(r3/dimensions)/proporcion, Blue, pt3]},

And I introduced a change (for color):

 Initialization -> ( 
 disk[r_, color_, pt_] := 
  Graphics[{{Opacity[.4, color], EdgeForm[Black], 
     Disk[{0, 0}, Scaled[r]]}, {Thick, 
     Line[{Scaled@{.5 - r/8, .5}, Scaled@{.5 + r/8, .5}}], 
     Line[{Scaled@{.5, .5 - r/8}, Scaled@{.5, .5 + r/8}}]}, {Text[
      Framed[Style[Row[pt, ","], Bold, 12], FrameMargins -> Tiny, 
       Background -> Opacity[.4, White]], Scaled@{.5, .52 + r}]}},
    ImageSize -> dimensions])]]]

Before:

 Initialization -> (disk[r_, color_, pt_] := 
  Graphics[{color, Opacity[.4], EdgeForm[Black], 
    Disk[{0, 0}, ImageScaled[r]]}, ImageSize -> dimensions])]]]

With the 1st initialization each disk creates a gigant red square and no text.

I correct it like this:

Initialization -> ( 
 disk[r_, color_, pt_] := 
  Graphics[{{Opacity[.4, color], EdgeForm[Black], 
     Disk[{0, 0}, Scaled[r]]}, {Thick(*,Line[{Scaled@{.5-r/8,.5},
     Scaled@{.5+r/8,.5}}],Line[{Scaled@{.5,.5-r/8},Scaled@{.5,.5+
     r/8}}]*)}, {Text[
      Framed[Style[Row[pt, ","], Bold, 12], FrameMargins -> Tiny ,
        Background -> Opacity[.4, White]](*,Scaled@{.5,.52+
      r}*)]}}, ImageSize -> dimensions])]]]

All the commented code brokes the program itself.

Anyway to "move" the label over the disk? not inside.

$\endgroup$
6
  • $\begingroup$ Ok i edited it. $\endgroup$ Nov 28, 2016 at 22:00
  • $\begingroup$ I am tempted to revise the title to "Trouble with modifying other people's code"/ $\endgroup$
    – m_goldberg
    Nov 28, 2016 at 23:05
  • $\begingroup$ Related questions: concerning grid overlay and concerning moving disk. $\endgroup$
    – m_goldberg
    Nov 28, 2016 at 23:10
  • $\begingroup$ What is the problem with uses "other people's code"? it hasn't an owner =P I'm trying to add more things over it, i reduced all that i could to make the question itself. $\endgroup$ Nov 28, 2016 at 23:29
  • $\begingroup$ Nothing is wrong with using code posted in answers. It is put into the answer to be used by others. However, it is good practice as well as good manners to give a reference to the source when you present the code in another question. $\endgroup$
    – m_goldberg
    Nov 29, 2016 at 0:50

1 Answer 1

4
$\begingroup$

I see you were not up to working up the hint I gave you in a comment to my answer here. So is here how a coordinates callout can be added to the moving disk. I throw in a cross-hair for free.

With[{source = ExampleData[{"TestImage", "Lena"}]}, 
  With[{dimensions = ImageDimensions[source]},
    Manipulate[
      source,
      {{r, .05, Style["r", Bold, 15]}, .02, .5, .01, ImageSize -> 500}, 
      {{pt, dimensions/2}, Locator, Appearance -> disk[r, pt]},
      ControlPlacement -> Top,
      Initialization :> (
        disk[r_, pt_] :=
          Graphics[
            {{Opacity[.4, White], EdgeForm[Black], Disk[{0, 0}, Scaled[r]]},
            {Thick,
               Line[{Scaled @ {.5 - r/8, .5}, Scaled @ {.5 + r/8, .5}}], 
               Line[{Scaled @ {.5, .5 - r/8}, Scaled @ {.5, .5 + r/8}}]},
            {Text[
               Framed[
                 Style[Row[pt, ","], Bold, 12],
                 FrameMargins -> Tiny,
                 Background -> Opacity[.4, White]],
               Scaled @ {.5, .52 + r}]}},
            ImageSize -> dimensions])]]]

lena

$\endgroup$
3
  • $\begingroup$ I tryed but I failed T.T so I answered again. Well, your code solutions question number 2 =) thanks! $\endgroup$ Nov 29, 2016 at 0:57
  • $\begingroup$ @ShiroIgnis Thanks but no up-vote? I rather have the up-vote. $\endgroup$
    – m_goldberg
    Nov 29, 2016 at 0:59
  • $\begingroup$ It didn't work in my main code T.T i was testing it 1st $\endgroup$ Nov 29, 2016 at 2:24

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.