7
$\begingroup$

Consider the following snippet:

  DynamicModule[{},
   Manipulate[
    Graphics[
     Translate[
      GeometricTransformation[
       {Blue, Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},
       {{scx, 0}, {0, scy}}],
      Tuples[{Range[wi], Range[he]}] - 1]],
    {{scx, 1, "x scale"}, 0, 1},
    {{scy, 1, "y scale"}, 0, 1},
    {{wi, 1, "width"}, 1, 5, 1},
    {{he, 1, "heigth"}, 1, 5, 1}]]

Mathematica graphics

I want a stable, fixed, panel in which the polygons are displayed, thus independent from the slider values. Applying the PlotRange-> option to the Graphics function in the example above doesn't work as expected.

Question: How should I set and fix the panel size?

$\endgroup$
12
  • $\begingroup$ I am getting the error Affine transform {{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {1, 0}, {1, 1}, {1, 2}, {1, 3}, {1, 4}} should be one of the forms {{{xx, yx}, {xy, yy}}, {tx, ty}}; {{xx, yx}, {yy, yy}}; or {tx, ty}. $\endgroup$
    – Mr.Wizard
    Commented Jun 10, 2012 at 12:50
  • $\begingroup$ If I put width and height all the way to the left, and use PlotRange -> {{-1, 2}, {-1, 2}} the x and y sliders appear stable. $\endgroup$
    – Mr.Wizard
    Commented Jun 10, 2012 at 12:52
  • $\begingroup$ What exactly are you doing with Tuples[{Range[wi], Range[he]}] ? The output doesn't appear to match the syntax of Translate. $\endgroup$
    – Mr.Wizard
    Commented Jun 10, 2012 at 12:53
  • 1
    $\begingroup$ @Mr.Wizard I don't get an error. In version 8 you can specify a list of vectors over which to translate the object. It's similar to Translate[gr, #]& /@ (Tuples[...] - 1). $\endgroup$
    – Heike
    Commented Jun 10, 2012 at 13:00
  • 2
    $\begingroup$ Imagine a square with width / height = 1. Display that initially, so it fills the panel. If I reduce the size of the square, the panel maintains it size but the square becomes smaller. If I add a square the squares are shown at half size. - The panel size/width, initially, is the standard. ( I may not be able to reply anymore today, this can wait. Thanks for the help sofar. ) $\endgroup$ Commented Jun 10, 2012 at 13:55

3 Answers 3

8
$\begingroup$

I think what you are looking for is simply ImageSize -> {Xpx, Ypx} option. It will fix your outer graphics frame to be displayed as X pixels by Y pixels, re-sizing graphics objects to fit into it. The approximate shape of that frame can be seen from the orange selection line when you click on the graphics as shown below. The figure below shows the action of "adding squares" as you described in the comment to your main question.

DynamicModule[{}, 
 Manipulate[
  Graphics[Translate[
    GeometricTransformation[{Blue, 
      Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}, {{scx, 0}, {0, 
       scy}}], Tuples[{Range[wi], Range[he]}] - 1], 
   ImageSize -> 400 {1, 1}], {{scx, 1, "x scale"}, 0, 
   1}, {{scy, 1, "y scale"}, 0, 1}, {{wi, 1, "width"}, 1, 5, 
   1}, {{he, 1, "heigth"}, 1, 5, 1}]]

enter image description here

BTW, DynamicModule wrapped around serves no purpose in this particular case. I just kept it to preserve your code as much as possible.

$\endgroup$
1
  • $\begingroup$ YES! This is what I was looking for. I can fix my issues now. Thanks. $\endgroup$ Commented Jun 11, 2012 at 20:50
6
$\begingroup$

First of all, adding PlotRange -> {{0, 5}, {0, 5}} works for me, so I'm just assuming you're looking for possible alternatives.

The answers based on ImageSize and ContentSize work fine if you know what the output size in units of printer's points is supposed to be. But if you instead want to specify a fixed size in the units that you're actually using for your rectangles in the manipulate, I would suggest a different approach.

Simply add an invisible rectangle of the desired fixed dimensions to the list of graphics objects. Here I inserted {Transparent, Rectangle[{0, 0}, {5, 5}]} before the dynamically variable polygons:

DynamicModule[{}, Manipulate[
  Graphics[{{Transparent, Rectangle[{0, 0}, {5, 5}]},
    Translate[
     GeometricTransformation[
      {Blue, Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]},
      {{scx, 0}, {0, scy}}
      ],
     Tuples[
       {Range[wi], Range[he]}] - 1]}
   ],
  {{scx, 1, "x scale"}, 0, 1}, {{scy, 1, "y scale"}, 0, 
   1}, {{wi, 1, "width"}, 1, 5, 1}, {{he, 1, "heigth"}, 1, 5, 1}]]

panel

$\endgroup$
5
$\begingroup$

Please try this simplified example and tell me if it works as expected. The key feature is the option ContentSize:

DynamicModule[{},
 Manipulate[
  Graphics[
   GeometricTransformation[{Blue, 
     Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}, {{scx, 0}, {0, scy}}]],
  {{scx, 1, "x scale"}, 0, 1}, {{scy, 1, "y scale"}, 0, 1},
  ContentSize -> {400, 400}
 ]
]

Or combined with PlotRange:

DynamicModule[{},
 Manipulate[
  Graphics[
   GeometricTransformation[{Blue, 
     Polygon[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}]}, {{scx, 0}, {0, 
      scy}}], PlotRange -> {{0, 1}, {0, 1}}],
  {{scx, 1, "x scale"}, 0, 1}, {{scy, 1, "y scale"}, 0, 1},
  ContentSize -> {400, 400}
 ]
]
$\endgroup$
2
  • $\begingroup$ You left out the Translate and that's exactly what messed it up. I understand the noise now. $\endgroup$ Commented Jun 11, 2012 at 20:47
  • $\begingroup$ @ndroock1 sorry, your code didn't work in version 7; I tried. $\endgroup$
    – Mr.Wizard
    Commented Jun 12, 2012 at 4:37

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.