# relative scale of elements in ImageCompose

My code:

sqrSize = 16/2;
dots = Flatten[Table[{2 i + Mod[j, 2], j Sqrt[3]},
{i, -sqrSize, sqrSize}, {j, -sqrSize, sqrSize}], 1];
inner = Select[dots, Norm[#] <= 5 &];
zePlot = ListPlot[{dots, inner}, PlotRange -> {{-sqrSize, sqrSize}, {-sqrSize, sqrSize}},
AspectRatio -> 1, Axes -> None, PlotStyle -> {{PointSize[0.02]}},
Epilog -> {Circle[{0, 0}, 5], PlotStyle -> {Blue, Opacity[0.2]}}];
ImageCompose[zePlot, {Graphics[{Blue, Disk[{0, 0}, 5]}], 0.2}]


gives this Plot as result:

Two issues:

1. The disk seems to use another scale than the rest of the image; I'd like to have it the same size as the circle
2. (not in the code yet) Instead of the disk I'd like to have its complement, i.e. the area outside the circle should be blue, inside the circle white.

How can I achieve these?

-

## 4 Answers

 ImageCompose[zePlot, {Graphics[{Blue, Disk[{0, 0}, 5]},
PlotRange -> {{-sqrSize, sqrSize}, {-sqrSize, sqrSize}}], 0.2}]


  ImageCompose[zePlot, {Graphics[{White, Disk[{0, 0}, 5]},
PlotRange -> {{-sqrSize, sqrSize}, {-sqrSize, sqrSize}},
Background -> Blue], 0.2}]


-
Nice, thanks a bunch. +1 for now. (For an accept I'll wait to give others the chance to post an answer too.) –  stevenvh Jan 26 '13 at 10:51

You can use Show to combine at a Graphics level, as opposed to ImageCompose that in a sense sees the graphics as images and just aligns them on top of each other not knowing about the different scales etc. This is why adding PlotRange to the Graphics fixes it in the ImageCompose case.

Show[zePlot, Graphics[{Opacity[0.2], Blue, Disk[{0, 0}, 5]}]]

-

I favor ssch's approach of keeping this within the domain of vector graphics which of course are scalable and editable in a way that a raster is not. Your point #2 graphic:

Show[
zePlot,
Prolog -> {White, Disk[{0, 0}, 5]},
Background -> RGBColor[0.8, 0.8, 1]
]


For illustration Prolog can also be used for the point #1 graphic:

Show[zePlot,
Prolog -> {RGBColor[0.8, 0.8, 1], Disk[{0, 0}, 5]}
]

-
Aha, a cheat! :-) I was thinking of cutting out the disk from a plane, like in CSG, but this is easier, of course. Thanks, +1. (I admit that I also cheat by just placing the purple dots over the blue ones, instead of replacing them.) –  stevenvh Jan 26 '13 at 19:45
@stevenvh I don't really see this as a cheat. If it causes problems for you I can try something else. I thought that the solid colors used here might be preferable to the transparency you used (I thought of that as a cheat). –  Mr.Wizard Jan 26 '13 at 19:48
@stevenvh okay I see you wrote +1 but I didn't see the counter go up. I was responding as if you'd seen my answer but not voted for it. I guess this is good then? Can I make it better? –  Mr.Wizard Jan 26 '13 at 19:49
No, it's fine, and together with ssch's solution I like it better than kguler's. The reason for the transparency is that I'm more used to Epilogs than Prologs. I realize that I still often make the wrong choice == a lot to learn! –  stevenvh Jan 26 '13 at 19:52
I can see the upvote indicator, and +2, but I'm not sure it was +1 before I voted. –  stevenvh Jan 26 '13 at 19:54

I thought I would show how this might be done with the Presentations Application (which I sell through my web site).

There I believe the approach is more natural because you simply draw one thing after another. Everything is treated as a graphic primitive and there is no necessity to jump between Graphics levels, or to use Prolog or Epilog.

CirclePoint is just a Presentations shortcut for drawing an outlined disk of a given size in printers points.

Module[
{sqrSize = 16/2, dotLocations},
dotLocations =
Flatten[Table[{2 i + Mod[j, 2], j Sqrt[3]}, {i, -sqrSize,
sqrSize}, {j, -sqrSize, sqrSize}], 1];
(* Generate the dot graphics *)
dots = CirclePoint[#, 3.5, Black, If[Norm[#] <= 5,
ColorData["Legacy"]["DarkSeaGreen"],
ColorData["Legacy"]["SandyBrown"]]] & /@ dotLocations;
Draw2D[
{(* Draw the outer background *)
LightBlue,
RegionDraw[
Norm[{x, y}] >= 5, {x, -sqrSize, sqrSize}, {y, -sqrSize, sqrSize}],
(* Draw the dots *)
dots,
(* Draw the boundary circle *)
Black,
Circle[{0, 0}, 5]},
PlotRange -> sqrSize,
Frame -> True, FrameTicks -> False,
ImageSize -> 300]
]


-