Align a horizontally-aligned, right-angled ASCII shape along a diagonal Your program will receive an ascii shape consisting of only underscores _, pipes |, spaces  and newlines \n, which, together, represent a horizontally-aligned, right-angled shape. Together with this shape, on a new line, you will also receive either a positive or a negative integer, whose absolute value will be either one of 45, 135, 225 or 315 — signifying the degree that the original image should rotate. For instance:

 _
| |_
|___|
-45


Your program's job is to rotate this shape the provided amount of degrees. Following are the example outputs, for all possible degrees, given the above provided example shape:


for 45° or -315°:

 /\
/ /
\ \
 \/

for 135° or -225°:

 /\
/  \
\/\/

for 225° or -135°:

/\
\ \
/ /
\/

for 315° or -45°:

/\/\
\  /
 \/



Remember though: the original shape above is just an example. Your program should be able to handle any shape constructed with said characters (within reason, of course — let's say: with a maximum of 100 x 100 characters).

The output of your program should be the rotated image, constructed with forward slashes /, backward slashes \, spaces and newlines.

Shortest code, after one week, wins.

Note: although this challenge offers many similarities with these [1] [2] two challenges, I think this one offers just enough variation (because the original image is not supposed to be rotated at 90° angles) for it to generate interesting new results.
Python 2 - 285

import sys
l=list(sys.stdin)
L=len;R=range
r=L(l)-2
c=L(max(l,key=L))-2
k=r+c+1
d=int(l[-1])/90%4
a=d/2;x=a^d%2
z=1-x*2;t=1-a*2
m=[k*[' ']for i in R(k)]
for i in R(r+1):
 for j in R(L(l[i])-1):m[a*c+x*r+z*i+t*j][r-a*r+x*c-t*i+z*j]='  \/'[ord(l[i][j])/40^d%2]
for s in m:print''.join(s)


I strongly suspect it can be golfed more, tips are welcome.

Examples:

% python r45.py &lt;&lt;&lt; "||
_____
45"
 /    
\ /   
 \    
  \   
   \  
    \ 

% python r45.py &lt;&lt;&lt; " _
| |_
|___|
-45"


    / \
 / \ / 
    /  
 \ /   
  \    


If the 2nd one looks misaligned, that's because of some issues with the question:
First, the underscore is at the bottom of the character "cell", while the pipe, slash and backslash are all in the middle. It would be fairer to use a dash (-) instead of underscore.
Second, with the rotation of the heart in the question, you couldn't represent it in any reasonable way if the first line was ___ (3 underscores) instead of
 _, as the 1st and 3rd underscore would be "capping" the pipes in the 2nd line.

Here's a better heart:

% python r45.py &lt;&lt;&lt; " _
| |
|  _
|   |
 ___
-45"



 / \ / \ 

 \     / 
  \   /  
   \ /