How should I make a downwind departure from a towered airport?
Typically, you have to think about each phase of flight in three dimensions (sometimes four if you consider time and timing of maneuvers). To be “in the pattern”, you have to be within the patterns lateral boundaries (not the right terminology) and at the proper altitude. 

I consider myself to be in the pattern within a mile of the runway and below 1500 feet AGL. At this distance, I can still affect a power-off landing if my engine quits. Although the airport might designate a specific direction for the pattern, I consider either side of the runway as being in the pattern. This is just in case ATC gives instructions to fly counter to the typical pattern, or another pilot does not know the designated direction.

When exiting the pattern, you follow ATC instructions. They even have the prerogative to have you cross over the airfield abeam midfield when you are on the downwind. In the absence of ATC instructions, your best practice is to do one of three things. They are...


Continue straight out on the same course as either the departure leg or the upwind leg. Sidestepping to the upwind leg should get you out of the way of traffic landing on the opposite runway (same pavement). Once you are two or more miles away or above 1500 feet AGL, you can turn to your planned heading. If your desired heading will take you back over the airfield, try to be above 2000 feet AGL. 
Once you are past he departure end of the runway, turn in the general direction of the traffic pattern. Keep your turn between zero and ninety degrees while continuing to climb out. Once you are two or more miles away or above 1500 feet AGL, you can turn to your planned heading. If your desired heading will take you back over the airfield, try to be above 2000 feet AGL. 
Remain within the lateral track of the airfield during your entire climb to at least 2000 feet AGL. Once you are two or more miles away or above 1500 feet AGL, you can turn to your planned heading. If your desired heading will take you back over the airfield, try to be above 2000 feet AGL.