Haskell, 109 9898 96 bytes
With nimi's suggestions, it's now just under 100 bytes:Thanks to nimi and Mauris for their help!
0#0='O'
0#_='-'
_#0='|'
i#j|i==j='\\'|i== -j='/'|1<2=' '
f n=unlines[[i#j|j<-n=unlines[map(i#)[-n..n]]|i<n]|i<-[-n..n]]
Explanation:
The operator #
specifies which character appears at coordinates (i,j), with the sun centered at (0,0). Function f
builds the result String by iterating themapping #
over all pairs of coordinates ranging from -n to n.
Usage:
ghci> putStr $ f 2
\ | /
\|/
--O--
/|\
/ | \