"""放射 / Radiance — 1,800 lines pointing away from one centre."""
import math
import numpy as np
from PIL import Image, ImageDraw
from _common import W, H, C, rgb, paper, cli


def render(seed, n=1800):
    rng = np.random.default_rng(seed)
    bg, cols = C["yoru"], [C["yamabuki"], C["shu"], C["tsuki"]]
    img = Image.new("RGB", (W, H), rgb(bg)); d = ImageDraw.Draw(img)
    cx, cy = W * 0.62, H * 0.55
    for _ in range(n):
        # squaring the random number pulls start points towards the centre
        a = rng.random() * math.tau; r0 = 60 + rng.random() ** 2 * 500; r1 = r0 + 200 + rng.random() * 1500
        d.line([(cx + math.cos(a) * r0, cy + math.sin(a) * r0), (cx + math.cos(a) * r1, cy + math.sin(a) * r1)],
               fill=rgb(cols[rng.integers(len(cols))]), width=2)
    return paper(img, rng)


SEED = 71

if __name__ == "__main__":
    cli(render, SEED)
