Zoom 2D
- To: mathgroup at smc.vnet.net
- Subject: [mg77051] Zoom 2D
- From: dh <dh at metrohm.ch>
- Date: Sat, 2 Jun 2007 04:12:04 -0400 (EDT)
Hello All,
after having learned more of the new dynamic abilities, I may post an
improved version of a Zoom function for 2 dimensional Graphics. The code
below will create a small palette with one button. If you select some 2
dim. graphics and click this button, a new notebook will be open with
two panes and a coordinate pair. The upper pane contains the original
graphics overlaid with an transparent rectangle overlaid. This recatngle
may be resized and defines the region to enlarge. The lower panel
contains the enlarged region. Clicking into the lower panel prints the
coordinates below the panels.
You are welcom to comment.
Daniel
(*Creates a Palette with a zoom button*)
Zoom2D[g0_]:=Module[{g,pp1,pp2},
If[!MatchQ[Head[g0],Graphics| GraphicsBox],CreateDialog[{TextCell["Zoom:
No Input available."],DefaultButton[]}];Return[];];
g=If[Head[g0]=!=Graphics,Replace[g0,head_[x1_,x2___]:>Graphics[{x1},{x2}]],g0];
{pp1,pp2}=FullOptions[g,PlotRange]//Transpose;
g1=DynamicModule[{p1=pp1,p2=pp2,lp={0,0}},
Column[{
LocatorPane[Dynamic[{p1,p2}],Show[{g,Graphics[{Opacity[0.1],Rectangle[Dynamic[p1],Dynamic[p2]]}]},ImageSize->Full]]
,EventHandler[Show[g,PlotRange:>Dynamic[Transpose[{p1,p2}]],Frame->True,ImageSize->Full]
,{"MouseClicked":>(lp=MousePosition["Graphics"])}
]
,Dynamic[lp]
},Center]];
CreateDocument[g1,WindowSize->{Small,All},WindowTitle->"Zoom-DH",WindowElements->{},WindowFrame->"Palette",BoxForm`ClosingSaveDialog->False];
]
CreatePalette[
Button["Zoom",Zoom2D[NotebookRead[SelectedNotebook[]]]
],WindowTitle->""];