stanley kubrick , deftly directing his own screenplay based on a story by stephen king , follows frustrated writer jack torrance ( jack nicholson ) from relative normalcy to a complete mental breakdown .