Hi,
Welcome to the forum.
It’s a bit hard to help you to right direction without your code. Please have a look at Guidelines—Asking Questions and include your code.
in general term you need a data structure to store information of your rectangles and a loop where you go though all those rectangles and move them. Data structure like array helps to construct a loop without repetitive code.