Unfortunately, your graphics card is going bad and there is no software solution for it.
If you are still under warranty or have AppleCare, take it to the Apple Store and have them replace your graphics card and/or the logic board.
If your machine is out of warranty, no AppleCare...you can still take it back to Apple or an authorized service center but they may charge you through the nose for replacement.
The cheapest/safest route is having the graphics chip reballed by a qualified BGA reball tech. (if you don't know what this is, look up BGA Reball on YouTube)
The cheapest/less safe route would be to heat your GPU chip with a heat gun or by baking it in the oven. There are tons of videos on YouTube on how to do this and you can get a GPU to work again using the heat method BUT it will just buy you a few months (if you're lucky) because when the GPU starts artifacting, there is something structurally wrong with the chip itself. Worst case scenario is you completely destroy the chip and/or damage your machine. Mileage varies a lot on this technique so beware.