I think what you should keep in mind is that rotate function rotates around the point you set in translate function. So, with translate(width/2,height/2) is rotates around the (width/2,height/2) point.
What I suggest is to translate to the point that should be rect's center, so that it would rotate around that point, and this way would do the thing you want. So, replace corresponding lines with this:
translate(width/2+recto.x+50,height/2+rectoy+50) #50 is to set to rect's middle point, not top left corner
...
rect(-50,-50,100,100) #-50 is because rect draws from top left, and we need it's center to align with the axis point
Not sure to perfectly understand what you want (it seems to me you can operate a rotation from the center of a rectangle with atan2()). Does the following correspond to what you’re trying to achieve ?