imj-base-0.1.0.2: Game engine with geometry, easing, animated text, delta rendering.

Imj.Graphics.Interpolation

Synopsis

# Discrete interpolation and morphing

• DiscreteInterpolation describes interpolation by value , where the result of the interpolation between two $$v$$ is a $$v$$
• DiscreteMorphing and DiscreteColorableMorphing describe a morphing between drawn representations of $$v$$.

These classes rely on the DiscreteDistance class:

class DiscreteDistance v where Source #

Instances should satisfy:

$$\forall (\, from, to)\, \in v,$$

• distance from to >= 0
• distance from to can be different from distance to from, to provide different forward and backward interpolations (or morphings).

Minimal complete definition

distance

Methods

Arguments

 :: v first value -> v last value -> Int the number of steps (including first and last) to go from first to last

Distance between two DiscreteDistances.

Distance between n successive DiscreteDistances.

Instances

 Source # Naïve interpolation. Methodsdistance :: Int -> Int -> Int Source # Source # First interpolate background color, then foreground color Methods Source # First interpolating characters, then color. Methods Source # Smoothly transforms the 4 sides of the rectangle simultaneously, from their middle to their extremities. Methods Source # Interpolation between 2 lists, occuring in parallel between same-index elements. Prerequisite : lists have the same lengths.For an interpolation that occurs sequentially between same-index elements, use SequentiallyInterpolatedList. Methodsdistance :: [a] -> [a] -> Int Source # Source # Interpolation between 2 SequentiallyInterpolatedList, occuring sequentially i.e interpolating between one pair of same-index elements at a time, starting with 0 index and increasing. Prerequisite : lists have the same lengths. Methods Source # Using bresenham 3D algorithm in RGB space. Methodsdistance :: Color8 a -> Color8 a -> Int Source # Source # Using bresenham 2d line algorithm. Methods Source # Interpolates the color and morphs the Colorable at the same time. Methodsdistance :: Colored a -> Colored a -> Int Source #

newtype Successive a Source #

Wrapper on a list, to represents successive waypoints.

Constructors

 Successive [a]

Instances

 Show a => Show (Successive a) Source # MethodsshowsPrec :: Int -> Successive a -> ShowS #show :: Successive a -> String #showList :: [Successive a] -> ShowS #

## Interpolation

class DiscreteDistance v => DiscreteInterpolation v where Source #

Instances should statisfy the following constraints:

• An interpolation between A and B starts at A and ends at B:

$$\forall (\, from, to)\, \in v,$$

    d = distance from to
interpolate from to 0 == from
interpolate from to d == to

• The interpolation path is composed of strictly distinct points:
    length $nubOrd$ map (interpolate from to) [0..pred d] == d

• Given any points A,B belonging the path generated by an interpolation, the interpolation beween A and B will be the points of the path between A and B:

$$\forall med \in [\,0,d]\,, \forall low \in [\,0,med]\,, \forall high \in [\,med,d]\,,$$

    distance from med + distance med to == 1 + distance from to
medVal = interpolate from to med
interpolate from to low  == interpolate from medVal low
interpolate from to high == interpolate medVal to \$ high-med


Minimal complete definition

interpolate

Methods

Arguments

 :: v first value -> v last value -> Int the current step -> v the interpolated value

Implement this function if you want to interpolate by value, i.e the result of the interpolation between two $$v$$ is a $$v$$.

Instances

 Source # Naïve interpolation. Methodsinterpolate :: Int -> Int -> Int -> Int Source # Source # First interpolate background color, then foreground color Methods Source # First interpolating characters, then color. Methods Source # Interpolate in parallel between 2 lists : each pair of same-index elements is interpolated at the same time. Methodsinterpolate :: [a] -> [a] -> Int -> [a] Source #interpolateSuccessive :: Successive [a] -> Int -> [a] Source # Source # Interpolation between 2 SequentiallyInterpolatedList, occuring sequentially i.e interpolating between one pair of same-index elements at a time, starting with 0 index and increasing. Prerequisite : lists have the same lengths. Methods Source # Using bresenham 3D algorithm in RGB space. Methodsinterpolate :: Color8 a -> Color8 a -> Int -> Color8 a Source # Source # Using bresenham 2d line algorithm. Methods

## Morphing

class (DiscreteDistance v, Drawable v) => DiscreteMorphing v where Source #

Morph between drawn representations of Drawbles.

Drawn representation of Drawable x
The visual result of IO rendering commands induced by a draw x call.

Instances should statisfy the following constraints:

• A morphing between drawn representations of A and B starts at the drawn representation of A and ends at the drawn represntation of B:

$$\forall (\, from, to)\, \in v,$$

    d = distance from to
drawMorphing from to 0 "is the same as" draw from
drawMorphing from to d "is the same as" draw to

• The morphing path is composed of strictly distinct drawings.
• The drawings, when seen in rapid succession, should visually produce a smooth transformation from the first to the last drawing.

Minimal complete definition

drawMorphing

Methods

Arguments

 :: (Draw e, MonadReader e m, MonadIO m) => v first value -> v last value -> Int the current step -> m ()

Draws the morphing between the drawn representations of 2 $$v$$.

drawMorphingSuccessive :: (Draw e, MonadReader e m, MonadIO m) => Successive v -> Int -> m () Source #

Draws the morphing between the drawn representations of several $$v$$.

Instances

 Source # Colored can wrap a DiscreteColorableMorphing, to make a DiscreteMorphing.Interpolates the color and morphs the Colorable at the same time. MethodsdrawMorphing :: (Draw e, MonadReader e m, MonadIO m) => Colored a -> Colored a -> Int -> m () Source #drawMorphingSuccessive :: (Draw e, MonadReader e m, MonadIO m) => Successive (Colored a) -> Int -> m () Source #

class (DiscreteDistance a, Colorable a) => DiscreteColorableMorphing a where Source #

Like DiscreteMorphing, except the Drawable constraint is replaced by a Colorable constraint:

Morph between drawn representations of Colorable.

Drawn representation of Colorable x
The visual result of IO rendering commands induced by a drawUsingColor x call.

Instances should statisfy the following constraints:

• A morphing between drawn representations of A and B start at the drawn representation of A and ends at the drawn represntation of B:

$$\forall (\, from, to)\, \in v, \forall color$$

    d = distance from to
drawMorphingUsingColor from to 0 color "is the same as" drawUsingColor from color
drawMorphingUsingColor from to d color "is the same as" drawUsingColor to   color

• The morphing path is composed of strictly distinct drawings.
• The drawings, when seen in rapid succession, should visually produce a smooth transformation from the first to the last drawing.

Minimal complete definition

drawMorphingUsingColor

Methods

drawMorphingUsingColor :: (Draw e, MonadReader e m, MonadIO m) => a -> a -> Int -> LayeredColor -> m () Source #

A Colorable is colourless so it wouldn't know in which color to draw itself, hence here we pass a LayeredColor.

Instances

 Source # MethodsdrawMorphingUsingColor :: (Draw e, MonadReader e m, MonadIO m) => RectContainer -> RectContainer -> Int -> LayeredColor -> m () Source #

# Lists interpolations

The DiscreteInterpolation instance on [] defines a parallel interpolation (interpolation occurs at the same time for all same-index elements).

To interpolate sequentially (i.e one index at a time), use SequentiallyInterpolatedList instead:

A List-like type to interpolate sequentially (one index at a time) between same-index elements.

Constructors

 SequentiallyInterpolatedList [a]

Instances

 Source # Methods Source # Methods Source # Methods Source # Interpolation between 2 SequentiallyInterpolatedList, occuring sequentially i.e interpolating between one pair of same-index elements at a time, starting with 0 index and increasing. Prerequisite : lists have the same lengths. Methods Source # Interpolation between 2 SequentiallyInterpolatedList, occuring sequentially i.e interpolating between one pair of same-index elements at a time, starting with 0 index and increasing. Prerequisite : lists have the same lengths. Methods

# Evolution

Evolution is a helper type to interpolate between DiscreteInterpolations or morph between DiscreteMorphing.

It stores the distance to cache potential expensive distance computations.

The preferred way to create it is to use mkEvolutionEaseQuart which uses the inverse ease function invQuartEaseInOut.

To produce the desired easing effect, the Evolution should be updated at specific time intervals. In that respect, getDeltaTimeToNextFrame computes the next time at which the interpolation should be updated (for interpolations) or rendered (for morphings), based on the current frame and the inverse ease function.

data Evolution v Source #

Defines an evolution (interpolation or morphing) between Successive DiscreteDistances.

Constructors

 Evolution Fields_evolutionSuccessive :: !(Successive v)Successive DiscreteDistances._evolutionLastFrame :: !FrameThe frame at which the Evolution value is equal to the last Successive value._evolutionDuration :: FloatDuration of the interpolation in seconds._evolutionInverseEase :: Float -> FloatInverse ease function.

Instances

 Show v => Show (Evolution v) Source # MethodsshowsPrec :: Int -> Evolution v -> ShowS #show :: Evolution v -> String #showList :: [Evolution v] -> ShowS #

Arguments

 :: DiscreteDistance v => Successive v DiscreteDistances through which the evolution will pass. -> Float Duration in seconds -> Evolution v

An evolution between n DiscreteDistances. With a 4th order ease in & out.

Arguments

 :: DiscreteDistance v => (Float -> Float) Inverse continuous ease function -> Successive v DiscreteDistances through which the evolution will pass. -> Float Duration in seconds -> Evolution v

An evolution between n DiscreteDistances. With a user-specified (inverse) ease function.

Arguments

 :: Evolution v -> Frame -> Maybe Float If evolution is still ongoing, returns the time interval between the input Frame and the next.

Computes the time increment between the input Frame and the next.

## Getting an interpolated value

Arguments

 :: DiscreteInterpolation v => Evolution v -> Frame -> v The evolution value.

Gets the value of an Evolution at a given Frame.

## Draw a morphing

drawMorphingAt :: (DiscreteMorphing v, Draw e, MonadReader e m, MonadIO m) => Evolution v -> Frame -> m () Source #

Draws an Evolution at a given Frame.

## Synchronizing multiple Evolutions

EaseClock can be used to synchronize multiple Evolutions.

newtype EaseClock Source #

Used to synchronize multiple Evolutions.

Constructors

 EaseClock (Evolution NotWaypoint)

Instances

 Source # MethodsshowList :: [EaseClock] -> ShowS #

Arguments

 :: Float Duration in seconds -> Frame Last frame -> (Float -> Float) Inverse ease function (value -> time, both between 0 and 1) -> EaseClock

Constructor of EaseClock