Map one region to another

I am working on a sketch to get Pythagorean dissections from Pythagorean tilings (here). I am having a hard time trying to rotate the region in the black square so that it appears with vertical/horizontal sides (some of that code is commented). I am trying to copy the region in a buffer, rotate, and copy back, but I can’t make it work. It feels like there should be some way to map one quad region to another, kind of like the way texture() works. Is it possible? How should I do this? Thanks!!

Instead of copying the pixels, you could create a PGraphics of the sample size, rotate and scale your geometry to fit a single tiling and draw into it. Then you can paste it as an image.