How can i make rectangles, squares or triangles

I need something very close to the topic below, see that it generates separate rectangles but I don’t know how to do this in my scripty