helm-0.6.2: A functionally reactive game engine.

Safe HaskellNone

FRP.Helm.Transition

Contents

Description

Contains all data structures for describing transitions, composing and animating them.

Synopsis

Types

type Transition a = StateT a (Writer [(a, Time)])Source

A type describing a combosable transition. The writer keeps record of all the frames in the transition. The state holds the current value of the transition. This allows you to easily compose transitions using do notation.

data TransitionStatus Source

A variety of statuses that can be used to control a transition.

Constructors

Cycle

The transition will repeat forever.

Pause

The transition will be paused and won't changed until resumed.

Once

The transition is cycled once and then stops.

Set Time

The transition will reset to a certain point in time.

class Interpolate a whereSource

Defines a value that can be interpolated. An example instance of this class follows:

 data YourDataType = YourDataConstructor SomeInterpolableType SomeOtherInterpolableType deriving Generic

 instance Interpolate YourDataType
   interpolate 0.5 (YourDataConstructor 3 5) (YourDataConstructor 5 7) == YourDataConstructor 4 6

Methods

interpolate :: Double -> a -> a -> aSource

Instances

Interpolate Bool 
Interpolate Char 
Interpolate Double 
Interpolate Float 
Interpolate Int 
Interpolate Int8 
Interpolate Int16 
Interpolate Int32 
Interpolate Int64 
Interpolate Integer 
Interpolate Word 
Interpolate Word8 
Interpolate Word16 
Interpolate Word32 
Interpolate Word64 
Interpolate Color 
Interpolate (Double, Double) 

Creating

waypoint :: Interpolate a => a -> Time -> Transition a aSource

Adds a value to the transition monad that will be the next point in the transition.

startWith :: Interpolate a => a -> Transition a b -> InternalTransition aSource

Starts a transition with an initial value.

 color = transition (constant $ Time.fps 60) (constant Cycle) $ startWith white $ do
   waypoint green (2 * second)
   waypoint red (5 * second)
   waypoint black (1 * second)
   waypoint yellow (2 * second)

fromList :: Interpolate a => [(a, Time)] -> InternalTransition aSource

Converts a list of tuples describing a waypoint value and time into a transition. The first element in the list is the starting value and time of the transition.

 color = transition (constant $ Time.fps 60) (constant Cycle) $ fromList [(white, 0), (green, 2 * second), (red, 5 * second), (black, 1 * second), (yellow, 2 * second)] 

Transitions

transition :: Interpolate a => SignalGen (Signal Time) -> SignalGen (Signal TransitionStatus) -> InternalTransition a -> SignalGen (Signal a)Source

Turns the internal representation of a transition into a signal. The provided time signal acts as the inner clock of the transition. The status signal can be used to control the transition, deciding whether the transition should cycle, go to a specific time, pause, stop or run once.

length :: InternalTransition a -> DoubleSource

How long it takes for the provided transition to end.