Ugly graphical glitches in High Sierra 10.13.2
That is not a software issue. Your graphics card is getting inappropriate power. You probably have a capacitor or transistor that is dying (if you're lucky; if you're REALLY lucky you might be able to pinpoint the exact component by visual inspection) or the graphics chip is nearing the end of its lifespan.

If there is a shop that does board-level repairs near where you live it might be repairable, usually using donor parts from other dead boards.

Most often, instead of just dying one day, the glitches might slowly degrade to something like this.

I think on the 2011 iMacs the dGPU was a mezzanine card? I don't know if you would feel it is worth it to repair, maybe you could find a replacement for cheap.

If this is the integrated graphics, I don't think there is anything that can be done.

As for the MacBook, that's a completely different machine in terms of architecture, and not just for the GPU. Probably unrelated, but you could provide more details on what the issues on that machine are like in another question.