# Manipulation of 2d images, position, alignment and scale

I'm new to Mathematica and I am trying to generate an array of rectangles which stays perfectly aligned and scaled correctly and able to control the opacity of each one. Could anyone point me on to the right direction?

Many thanks to all for showing potential ways of solving the problem. I really appreciate!

Does something like this work for you?

Graphics[{
Red,
Rectangle[{0, 0}, {1, -4}],
Opacity[0.8],
Rectangle[{1.1, 0}, {2.1, -2}],
Opacity[0.6],
Rectangle[{2.2, 0}, {3.2, -2}],
Opacity[0.4],
Rectangle[{3.3, 0}, {4.3, -2}],
Opacity[0.2],
Rectangle[{4.4, 0}, {5.4, -2}],
Black,
Opacity[1],
Table[Style[
Text[{"B0", "B1", "B2", "B3", "B4"}[[i + 1]], {0.5 + 1.1 i,
If[i == 0, -4.2, -2.2]}], 16], {i, 0, 4}]
}]

I've hard-coded all of the rectangles and opacities just to show you the order in which things can be done, but you could easily combine them into a Table and generate them programmatically like I've done for the labels.

• Many thanks for pointing me out a direction possible ways of doing it. Many thanks! Jan 12, 2019 at 11:02

You can start with a single rectangle and Translate and Scale it:

gap = 1/10;
Graphics[{Red, {Opacity[1/(1 + #)],
Translate[Scale[Rectangle[{0, 1}, {1, 5}], {1, 1-Unitize[#]/2}], {(1 + gap) #, Unitize@#}],
Opacity[1], Black,
Text[Style["B" <> ToString[#], 16], {1/2 + (1 + gap) #, 2/3 + 2 Unitize[#]}]} & /@
Range[0, 5]},
ImageSize -> 600]