Mac turns off randomly and has lines on screen For some reason my iMac keeps turning off around 5 to 10 minutes into boot.

Also just recently it turns on but has shaded lines going down the screen. I have not installed any weird programs and i have not used it in around 3 months. 

Any ideas on what the issue is, i don't have any other information about the issue besides whats happening when i use it.
 The image i'm showing you was found on google but this looks exactly like mine does.

The model of my imac is the late 2011 model.
On first guess, based on the description of the symptoms, I would say that you are having an issue with your graphics card.

The best way is to run Apple Diagnostics or Apple Hardware Test. Hold D while booting from a powered off state.  Run the diagnostics and post your results and I will update my answer.

First update based on the comments:  I found this video on YouTube that details this exact problem and it's related to the graphics card.  Now, one word of advice: don't do the fix shown in the video.  

While the diagnosis is correct, that fix is pure nonsense.  I have had much better results getting the board repaired by a shop that specializes in that type of fix (from eBay - I have used the one in Dana Point, CA with great results and for the record, I am not affiliated with them).  

Normally I would say to replace it, but the prices are ridiculous - sometime over $700 for the graphics card.