[Question]
  [
# Challenge
Given the phase of the moon, draw it using ASCII art.
Your program must handle new moon, waxing crescent, first quarter, waxing gibbous, full moon, waning gibbous, last quarter, and waning crescent. Your input will be an integer.
```
0 -> new moon
1 -> waxing crescent
2 -> first quarter
3 -> waxing gibbous
4 -> full moon
5 -> waning gibbous
6 -> last quarter
7 -> waning crescent
```
The ASCII art is all placed on a 16x8 grid (because character dimension ratios). You can replace `.` with any character and `#` with any other non-whitespace character.
The output for new moon should be:
```
................
................
................
................
................
................
................
................
```
For waxing crescent:
```
..........######
............####
.............###
.............###
.............###
.............###
............####
..........######
```
For first quarter:
```
........########
........########
........########
........########
........########
........########
........########
........########
```
For waxing gibbous:
```
......##########
....############
...#############
...#############
...#############
...#############
....############
......##########
```
And for full moon:
```
################
################
################
################
################
################
################
################
```
The waning crescent is just the waxing crescent with each line reversed, as with the waning gibbous and the waxing gibbous, and the first and last quarter.
# Rules
* [Standard Loopholes Apply](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default)
* You may choose to output waxing/waning in the opposite direction if you want, though it should make no difference (the graphics shown in this question are for the northern hemisphere)
* Your output must be exactly as specified. Your newlines can be any reasonable line separator, and you may have a trailing newline if you would like.
  
[Answer]
## JavaScript (ES6), ~~121~~ ... ~~103~~ 92 bytes
```
f=(n,i=128)=>i--?f(n,i)+(i%16?'':`
`)+'.#.'[i%16+4*n-~-'31000013'[n&1?i>>4:1]*~-(n&2)>>4]:''
```
### Demo
```
f=(n,i=128)=>i--?f(n,i)+(i%16?'':`
`)+'.#.'[i%16+4*n-~-'31000013'[n&1?i>>4:1]*~-(n&2)>>4]:''
o.innerHTML=f(0)
```
```
<input type="range" oninput="o.innerHTML=f(this.value)" value=0 min=0 max=7><pre id=o>
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~43~~ 32 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
-7 bytes moving from bit-mask to comparison-mask  
-2 bytes with some tacit programming improvements  
-1 byte moving to the southern hemisphere  
-1 byte - **use the all-new `ɓ` chain separator** ...its first ever use!
```
“>,##‘m0Dm€0ż@€4Ḷ¤Œṙɓ%4>C¹⁸:4¤?Y
```
Uses the characters `0` for `.` and `1` for `#`.
All cases in a test suite at **[Try it online!](https://tio.run/nexus/jelly#@/@oYY6djrLyo4YZuQYuuY@a1hgc3eMApEwe7th2aMnRSQ93zjw5WdXEzvnQzkeNO6xMDi2xj/x/dM/hdqCaSBD@/z/aQMdQx0jHWMdEx1THTMc8FgA)**
### How?
Builds a mask capturing the first four phases, and rather than reversing the lines complements the resulting values of the modulo-4 phase result when the phase div-4 is non-zero.
I originally built a bit mask, but the mask values were `0`,`8`,`12`, and `14` - `0000`, `1000`, `1100`, and `1110` - these have `phase` leading ones - so a comparison-mask could be used instead.
```
“>,##‘m0Dm€0ż@€4Ḷ¤Œṙɓ%4>C¹⁸:4¤?Y - Main link 1: number phase
“>,##‘                           - code-page index literal [62,44,35,35]
      m0                         - reflect -> [62,44,35,35,35,35,44,62]
        D                        - decimalise -> [[6,2],[4,4],[3,5],[3,5],[3,5],[3,5],[4,4],[6,2]]
         m€0                     - reflect €ach -> [[6,2,2,6],[4,4,4,4],[3,5,5,3],[3,5,5,3],[3,5,5,3],[3,5,5,3],[4,4,4,4],[6,2,2,6]]
                 ¤               - nilad and link(s) as a nilad:
               4                 -   literal 4
                Ḷ                -   lowered range -> [0,1,2,3]
            ż@€                  - zip (reverse @rguments) for €ach -> [[[0,6],[1,2],[2,2],[3,6]],[[0,4],[1,4],[2,4],[3,4]],[[0,3],[1,5],[2,5],[3,3]],[[0,3],[1,5],[2,5],[3,3]],[[0,3],[1,5],[2,5],[3,3]],[[0,3],[1,5],[2,5],[3,3]],[[0,4],[1,4],[2,4],[3,4]],[[0,6],[1,2],[2,2],[3,6]]]
                  Œṙ             - run-length decode -> [[0,0,0,0,0,0,1,1,2,2,3,3,3,3,3,3],[0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3],[0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3],[0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3],[0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3],[0,0,0,1,1,1,1,1,2,2,2,2,2,3,3,3],[0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3],[0,0,0,0,0,0,1,1,2,2,3,3,3,3,3,3]]
                                    -   i.e.: 0000001122333333  -
                                              0000111122223333  - Marking out the separate
                                              0001111122222333  - regions as filled up by
                                              0001111122222333  - the phases of the moon in
                                              0001111122222333  - the southern hemisphere.
                                              0001111122222333  -
                                              0000111122223333  -
                                              0000001122333333  -
                    ɓ            - dyadic chain separation & swap arguments, call that m
                     %4          - phase mod 4
                       >         - greater than? (vectorises across m) 1 if so 0 if not
                              ?  - if:
                             ¤   -   nilad followed by link(s) as a nilad:
                          ⁸      -     link's left argument, phase
                           :4    -     integer divide by 4
                        C        - then: complement
                         ¹       - else: identity (do nothing)
                               Y - join with newlines
                                 - implicit print
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~98~~ 90 bytes
```
f i=do{a<-[3,1,0,0,0,0,1,3];[".#."!!div(i*4+x+[0,a-1,0,1-a]!!mod i 4)16|x<-[0..15]]++"\n"}
```
It loops through the rows and columns using the list monad (a `do` block for rows and a list comprehension for columns) and determines which character for each cell using a expression of the input (`i`), offset value for the row (`a`), and column index (`x`).
Saved 8 bytes by simplifying the subexpression for the true offset.
[Answer]
# [Python 2](https://docs.python.org/2/), ~~144~~ ~~142~~ 127 bytes
```
i=input()
a,b='#.'[::i/4*2-1]
i%=4
for x in range(8):y=(int(abs(x-3.5))or 1)+2;y=[y,16-y][i>2];y=[i*4,y][i%2];print(16-y)*a+b*y
```
[Try it online!](https://tio.run/nexus/python2#LcxBCoMwFATQfU4REMn/UdNq01KE9CLiIqFV/iZKasGcPk2ls5x5TCJDfv1sgMzWztBJW/8UhRJLEKoQjEqj2bQEvnPyPFg/v@COPeM50QD5Dax7w95c1BUxuxar7lhp4vTo@mjaWxP/fiCp6zgOVHbjUa0hP3Ar4YewcjKmdP4C "Python 2 – TIO Nexus")
Can definitely be golfed further, tips are appreciated :)
Golfed off 1 byte thanks to undergroundmonorail!
Golfed off many bytes thanks to ovi and Mego because I'm a fool who forgets to not use 4 spaces for codegolf :)
[Answer]
# PHP, 105 Bytes
```
for(;$i++<8;)echo($p=str_pad)($p("",[16,16-$b=_64333346[$i],8,$b][3&$a=$argn],_M[$a/4]),16,M_[$a/4])."
";
```
[Try it online!](https://tio.run/nexus/php#LYw9D4IwFEV3fkbzYtpYPwgESQpxMAwO6OJWSVOwQpfSPHAy@tcRjXe6N@fmZHvf@cAg9qjQ@B5H61r6LtTpfDkeCiaCe49GNx1F7VpDt3zH9AAaW8ee08yoALtcZqlgpul6Cj4fRlRe39jcKSFchgkPkxXUuUriaE6cSLAVTznUlYwWoPOfruKqlKA3ccXmPy/Vf6xJQMT0lZOrI@LhBjNSsEy8pg8 "PHP – TIO Nexus")
[Answer]
## Mathematica, 125 bytes
```
s=Switch;Grid@If[1<#<6,#&,1-#&][s[m=#~Mod~4,0,0,2,1,_,1-{3.4,5}~DiskMatrix~{8,16}]s[m,1,h=Table[Boole[i>8],8,{i,16}],_,1-h]]&
```
Returns a grid using `1` and `0` instead of `.` and `#` respectively.
It works using two masks, one circular one and one half-shaded one, and logically combining them to get the appropriate shapes.
The two masks are made with `1-{3.4,5}~DiskMatrix~{8,16}` for the circular one, and `Table[Boole[i>8],8,{i,16}]` for the half one. The logic is as follows:
```
output = f(a AND b)
where f, a and b are:
n | f    a  b
--+-----------
0 | NOT  F  ◨ 
1 | NOT  ○  ◧ 
2 | 1    T  ◨
3 | 1    ○  ◨
4 | 1    F  ◨ 
5 | 1    ○  ◧ 
6 | NOT  T  ◨ 
7 | NOT  ○  ◨
```
The logic is simulated with `1`s and `0`s by using multiplication for `AND` and `x -> 1-x` for `NOT`.
A bonus (non-ASCII) solution, for 28 bytes: `IconData["MoonPhase",#/4-1]&`
]