# 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:

1. for 45° or -315°:

 /\
/ /
\ \
\/

2. for 135° or -225°:

 /\
/  \
\/\/

3. for 225° or -135°:

/\
\ \
/ /
\/

4. 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.

• This question is ill-defined. How should we rotate this shape? __ | | |__| (sp _ _ sp, | sp sp |, | _ _ |) This is a 1.5 by 2 box, judging by your example above. Feb 24, 2014 at 19:04

# 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 <<< "||
_____
45"
/
\ /
\
\
\
\

% python r45.py <<< " _
| |_
|___|
-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 <<< " _
| |
|  _
|   |
___
-45"

/ \ / \

\     /
\   /
\ /


# Mathematica <225> 27

## Second Version

Strange as it may seem, both the input and output are ASCII, "constructed with forward slashes /, backward slashes \, spaces and newlines"!

The command works by Rotateing the text within the Mathematica environment, while leaving the string in ASCII. The output is directly editable, as is, with no additional keystrokes or commands required. However, it will not export directly as ASCII. It can, however be exported directly as an image, as I have done here.

inputString =
" _
| |_
|___|";


The following works by rotating the ASCII string on-screen.

s_~f~d_ := Rotate[s, -d Degree]


## Test Cases

f[s, 45]
f[s, -315]


f[s, 135]
f[s, -225]


f[s, -135]
f[s, 225]

f[s, 315]
f[s, -45]


• Your output is not "constructed with forward slashes /, backward slashes \, spaces and newlines" Feb 23, 2014 at 9:50
• @aditsu. You were correct. However, it is now so constructed. They are rotated, but they remain ASCII characters. Feb 23, 2014 at 18:01
• Nope, those are still underscores and pipes (drawn at an angle) Feb 24, 2014 at 3:02
• -1 because you're not following the rules Feb 24, 2014 at 19:37

HTML/CSS/Javascript

FIDDLE : http://jsfiddle.net/c5h2d/1/

<!DOCTYPE HTML>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<script type="text/javascript">
function rotate(){
var x = document.querySelector("#i").value, y = document.querySelector("#t").value; document.querySelector("#a").innerHTML = y ;
document.getElementById("a").style.transform = "rotate("+x+"deg)"

}
</script>

<style type="text/css">
#a{
transform:rotate(45deg);
position:absolute;
top:50%;
left:50%
}
</style>