i have this code:

img = ImageResize[ExampleData[{"TestImage", "Lena"}], {escala}]},
   size = 1000;
    escala = 500;
     proporcion = size/escala;

  celda = 200;
n = size/celda;
sub = Subdivide[-1, 1, n];

    dimensions = ImageDimensions[img]},

    grid = 
Graphics[{}, GridLines -> {sub, sub}, PlotRangePadding -> None, 
 GridLinesStyle -> 
  Directive[White, Thick, Dashing[Tiny], Opacity[0.5]], 
 ImageSize -> ImageDimensions@img];
    Overlay[{img, grid}],

   {{pt, dimensions/2}, Locator, Appearance -> disk[r, White, pt]},
   {{pt2, dimensions/2}, Locator, Appearance -> disk[r, Red, pt2]},

{{r, .05, Style["r", Bold, 15]}, .02, .5, .01, ImageSize -> 500},
ControlPlacement -> Top, 
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])]]]

I want to make the GRID optional but i don't know how to enable/disable it in real-time in the Overlay function.

I was thinking about a tick 0->ON 1->OFF, but the real problem is adding this inside Overlay itself.

  • $\begingroup$ Wrap it in an appropriate Manipulate? $\endgroup$ – MarcoB Dec 9 '16 at 19:33

Change the GridLines setting to

GridLines -> If[showGridlines, {sub, sub}, None]

and add the control

{showGridlines, {True, False}}

Mathematica graphics

  • $\begingroup$ It works good =) thanks! $\endgroup$ – Shiro Ignis Dec 10 '16 at 14:07

Since you seem to have most of the details worked out with respect to your image and gridlines, I'll only give a minimal working example for the checkbox.

I would move to a dynamic module and use the switch to either output the image or the image with the overlay:

 img1 = Graphics[{Red, Disk[{0, 0}, 0.5]}];
 img2 = Graphics[{Blue, Rectangle[]}];
  Labeled[Checkbox[Dynamic@swtch], "Optional Overlay"],
    Overlay[{img2, img1}],

enter image description here

  • $\begingroup$ any other way? i can't introduce it inside the with and manipulate. $\endgroup$ – Shiro Ignis Dec 9 '16 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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