Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
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}. –  Mr.Wizard Jun 10 '12 at 12:50
    
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. –  Mr.Wizard Jun 10 '12 at 12:52
    
What exactly are you doing with Tuples[{Range[wi], Range[he]}] ? The output doesn't appear to match the syntax of Translate. –  Mr.Wizard Jun 10 '12 at 12:53
1  
@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). –  Heike Jun 10 '12 at 13:00
2  
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. ) –  ndroock1 Jun 10 '12 at 13:55

3 Answers 3

up vote 6 down vote accepted

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.

share|improve this answer
    
YES! This is what I was looking for. I can fix my issues now. Thanks. –  ndroock1 Jun 11 '12 at 20:50

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

share|improve this answer

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}
 ]
]
share|improve this answer
    
You left out the Translate and that's exactly what messed it up. I understand the noise now. –  ndroock1 Jun 11 '12 at 20:47
    
@ndroock1 sorry, your code didn't work in version 7; I tried. –  Mr.Wizard Jun 12 '12 at 4:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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