I agree that mood/environement does have an obvious effect, as does the context of your programming. My job is not solely programming, but other menial IT related tasks. When I am getting constant interruptions I canít code and just stop trying until later. When things are quiet I can go for hours.
In this going for hours state though I only enjoy it when I am discovering new things, figuring out ways to do things I had no idea about before. If I had to write a second system slightly different to the first one I wrote, I find it very boring. Which is why I'm browsing around here at the moment :)
I guess that is the problem solver in me coming out.