I remember when I was little I would think of all these great ideas for stories but wouldn't know what to do with them. I would think about them all night, but sadly I lost a lot of my creativity through the years.
I've had them before, and not only in writing. I think the best way to describe it is to say that you're in the zone, which originates from sports. I've felt that way when programming, writing, writing music, playing music, AND playing sports. It's an amazing feeling when you can tell that you're in one.