| Bytes | Lang | Time | Link |
|---|---|---|---|
| 192 | Python 3 | 250912T115816Z | AHelmer |
| 124 | JavaScript ES6 | 250911T115354Z | Arnauld |
| 106 | Ruby | 250911T234027Z | Level Ri |
| 052 | Charcoal | 250911T085232Z | Neil |
Python 3 - 192 bytes
def f(N):
import math as m;c=lambda x,y:"🟨"if x*x+y*y<N*N/64 else"🟥"if abs(round(m.atan2(y,x)/m.pi*16))%2 else"🟧"
for y in range(N):print(''.join([c(x-N/2,y-N/2)for x in range(N)]))
Explanation
Prints a simple 2-D grid, with a function defining the color of the cell: $$ color(x, y) = \text{Yellow, if } x^2 + y^2 < \left(\frac{N}{8}\right)^2$$ Then the angle is obtained with math.atan2, and the circle is divided in 32 sections: $$N = \left[\alpha \cdot \frac {2\pi} {32} \right]$$ N being the number of the corresponding section. When N is even, the returned color is orange, when N is odd, it returns red.
JavaScript (ES6), 124 bytes
f=(w,y=x=w)=>y?[...`🟧🟨🟥
`][x--?(X=x-~-w/2)*X+(Y=y+~w/2)*Y<w*w/64?1:Math.atan(X/Y)*10.19+33&2:(y--,x=w,3)]+f(w,y):""
Method
For each coordinates \$(x,y) \in [0\dots w-1]^2\$, we compute:
$$X=x-\frac{w}{2}+\frac{1}{2}$$ $$Y=y-\frac{w}{2}+\frac{1}{2}$$
and then convert \$(X,Y)\$ to polar coordinates \$(r,\phi)\$:
$$r=\sqrt{X^2+Y^2}$$ $$\phi=\arctan(X/Y)$$
The test for the sun is:
$$r<\frac{w}{8} \iff X^2+Y^2<\frac{w^2}{64}$$
The color of each ray is obtained by testing the parity of:
$$\left\lfloor \phi\times \frac{16}{\pi}+\frac{1}{2}\right\rfloor\approx\lfloor\phi\times 5.09+0.5\rfloor$$
In the JS implementation, we actually multiply by \$32/\pi\approx 10.19\$, add \$33\$(*) and test the 2nd least significant bit.
(*) Because the sign of % in JS is the sign of the dividend and because we use a bitwise AND for our test, we need to add a large enough constant to force a positive result.
Ruby, 106 bytes
->n{(1..n*m=n+1).map{|i|z=i%m-m/2+(i/m-n/2)*1i
i%m<1?$/:z.abs>n/8?'🟥🟧'[(z.arg*5.1-0.5)%2]:?🟨}*""}
A function accepting an integer and returning a newline separated string
Commented code
->n{(1..n*m=n+1).map{|i| #Output n rows of m=n+1 characters by iterating through i from 1 to n*m
z=i%m-m/2+(i/m-n/2)*1i #Convert the x and y coordinates into a complex number z, with origin at the centre.
i%m<1?$/: #For the last character in each row output newline.
z.abs>n/8? #If absolute value of z > n/8
'🟥🟧'[(z.arg*5.1-0.5)%2]: #Output red or orange depending on angle
?🟨 #Else output yellow for centre (the ? marks a character literal)
}*"" #Close iteration bracket. Convert array into string by concatenating
} #Return string
Charcoal, 61 52 bytes
NθEθ⭆Eθ⁻⁺ι×λI1j×⊘⊖θI1+1j⎇‹×⁸↔λθ🟨§🟧🟥№IXλ¹⁶(-
Attempt This Online! Link is to verbose version of code. Explanation:
NθEθ⭆Eθ⁻⁺ι×λI1j×⊘⊖θI1+1j
Input N and calculate the complex numbers for an N×N grid with the origin at its centre.
⎇‹×⁸↔λθ🟨§🟧🟥№IXλ¹⁶(-
Calculate the appropriate emoji for each element.