module Stars where
import Rumpus

-- Golden Section Spiral (via http://www.softimageblog.com/archives/115)
pointsOnSphere :: Int -> [V3 GLfloat]
pointsOnSphere (fromIntegral -> n) =
    let inc = pi * (3 - sqrt 5)
        off = 2 / n
        halfOff = off / 2
    in for [0..n] $ \k ->
        let y   = k * off - 1 + halfOff
            r   = sqrt (1 - y*y)
            phi = k * inc
        in V3 (cos phi * r) y (sin phi * r)


start :: Start
start = do

    -- We only take half the request points to get the upper hemisphere
    let numPoints = 200 :: Int
        --points = reverse $ drop (numPoints `div` 2) $ pointsOnSphere numPoints
        points = reverse $ pointsOnSphere numPoints
        hues = map ((/ fromIntegral numPoints) . fromIntegral) [0..numPoints]
    forM_ (zip3 [0..] points hues) $ \(i, pos, hue) -> spawnChild $ do
            myTransformType ==> AbsolutePose
            myShape         ==> Sphere
            mySize          ==> 0.001
            myColor         ==> colorHSL hue 0.8 0.8
            myPose          ==> position (pos * 500)
            myStart         ==> do
                setDelayedAction (fromIntegral i * 0.05) $
                    setSize 5
