Are aircraft pilots required to fly runway heading for a certain distance?
The initial turn should be made at 400 feet AGL.
Unless otherwise specified in the departure procedure, the initial turn should be made when reaching an altitude of 400 feet above the runway elevation as specified in the AIM:

Unless specified otherwise, required obstacle clearance for all departures, including diverse, is based on the pilot crossing the departure end of the runway at least 35 feet above the departure end of runway elevation, climbing to 400 feet above the departure end of runway elevation before making the initial turn, and maintaining a minimum climb gradient of 200 feet per nautical mile (FPNM), unless required to level off by a crossing restriction, until the minimum IFR altitude. A greater climb gradient maybe specified in the DP to clear obstacles or to achieve an ATC crossing restriction. If an initial turn higher than 400 feet above the departure end of runway elevation is specified in the DP, the turn should be commenced at the higher altitude. If a turn is specified at a fix, the turn must be made at that fix. Fixes may have minimum and/or maximum crossing altitudes that must be adhered to prior to passing the fix. In rare instances, obstacles that exist on the extended runway centerline may make an “early turn” more desirable than proceeding straight ahead. In these cases, the published departure instructions will include the language “turn left (right) as soon as practicable.” These departures will also include a ceiling and visibility minimum of at least 300 and 1. Pilots encountering one of these DPs should preplan the climb out to gain altitude and begin the turn as quickly as possible within the bounds of safe operating practices and operating limitations. This type of departure procedure is being phased out.

(AIM 5-2-6 Departure Procedures, emphasis mine)
The Canarsie climb at JFK does not include any special instructions for when to make the turn:

CANARSIE CLIMB: Climbing left turn direct CRI VOR/DME. Make turn east of
CRI R-039 (remain within JFK 4.5 DME), then via CRI R-176. Cross CRI 2 DME
or JFK R-253 at or above 2500, thence . . . .

(Kennedy Five Departure)
I would therefore start the turn at 400 feet. In principle, this would allow turning before reaching the far end of the runway, but only for a very good climb performance or a very long runway.