{- 02/2003 -}
module Main where

import FunWorlds

scene [redPosCh,greenPosCh,bluePosCh] = 
  groupB [flight redPosCh   (cycleIf trueB) redB
         ,flight greenPosCh (cycleIf ((xCompB redPosO) .>. 1)) greenB
         ,flight bluePosCh  (cycleIf ((xCompB greenPosO) .>. 1)) blueB
         ]
  where 
    redPosO   = Observe base redPosCh
    greenPosO = Observe base greenPosCh
    bluePosO  = Observe base bluePosCh

    time :: GLdoubleB
    time           = integral 0.25

    (xBase,yBase)  = (-1.4, -1)
    (xBaseB,yBaseB)= (lift0 xBase, lift0 yBase)
    base           = Vector3 xBase yBase 0
    baseB          = lift0 base

    flight posCh cycle colorB = 
      translateB (Source cycle posCh) $ coloredShapeB colorB $ sphereB 0.3

    x,y :: GLdoubleB
    x = xBaseB + (1/2*time)
    y = yBaseB + (8/5*time) + integral (-1/10*time)
    cycle = vector3B x    y 0 `Until` ((y .<. yBaseB) `then_` 
           (vector3B (-x) y 0 `Until` ((y .<. yBaseB) `then_` 
            cycle)))
    cycleIf b = baseB `Until` (b `then_` cycle)

main :: IO ()
main = startB $ \SC{keyCh=keyb}->
                rotateAndScale keyb $
                newChannels 3 [] scene
