Message Boards Message Boards

1
|
4356 Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Alignment

Posted 12 years ago
How can this code be modified to position the darker rectangle in the upper right corner of the lighter rectangle? Thanks.
Overlay[{
  Graphics[{Opacity[.4], Rectangle[]}, ImageSize -> .2 {300, 787},
   ImagePadding -> 0, PlotRangePadding -> 0],
  Graphics[{Opacity[.2], Rectangle[]}, ImagePadding -> 0,
   PlotRangePadding -> 0]},
Alignment -> {1, 1}]
POSTED BY: Jay Warendorff
2 Replies
The small square has padding from the explicit image width and height:
Overlay[{
  Graphics[{Opacity[.4], Rectangle[]}, ImageSize -> .2 {300, 787},
   ImagePadding -> 0, PlotRangePadding -> 0, Background -> Red],
  Graphics[{Opacity[.2], Rectangle[]}, ImagePadding -> 0,
   PlotRangePadding -> 0]},
Alignment -> {1, 1}]

Using an Automatic setting, or at least sizes that match the aspect ratio of the graphic, will work:
Overlay[{
  Graphics[{Opacity[.4], Rectangle[]},
   ImageSize -> {0.2*300, Automatic}, ImagePadding -> 0,
   PlotRangePadding -> 0, Background -> Red],
  Graphics[{Opacity[.2], Rectangle[]}, ImagePadding -> 0,
   PlotRangePadding -> 0]}, Alignment -> {1, 1}]
POSTED BY: Brett Champion
Inset will probably be easier to work with:
Graphics[{Opacity[.4], Rectangle[],
  Inset[Graphics[{Opacity[.2], Rectangle[]}], {1, 1}, {1, 1}, 0.2]},
ImageSize -> 300, ImagePadding -> 0, PlotRangePadding -> 0]
POSTED BY: Zach Bjornson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract