2
$\begingroup$

i have this code:

With[{ img = ImageResize[ExampleData[{"TestImage", "Lena"}], {escala}]}, size = 1000; escala = 500; proporcion = size/escala; celda = 200; n = size/celda; sub = Subdivide[-1, 1, n]; With[{ dimensions = ImageDimensions[img]}, Manipulate[ 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.

$\endgroup$
1
  • $\begingroup$ Wrap it in an appropriate Manipulate? $\endgroup$ Commented Dec 9, 2016 at 19:33

2 Answers 2

2
$\begingroup$

Change the GridLines setting to

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

and add the control

{showGridlines, {True, False}} 

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ It works good =) thanks! $\endgroup$ Commented Dec 10, 2016 at 14:07
1
$\begingroup$

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:

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

enter image description here

$\endgroup$
1
  • $\begingroup$ any other way? i can't introduce it inside the with and manipulate. $\endgroup$ Commented Dec 9, 2016 at 21:16

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.