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

Safe HaskellNone
LanguageHaskell2010

Imj.Graphics.Interpolation

Contents

Synopsis

Discrete interpolation and morphing

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

distance Source #

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.

distanceSuccessive :: Successive v -> Int Source #

Distance between n successive DiscreteDistances.

Instances

DiscreteDistance Int Source #

Naïve interpolation.

DiscreteDistance LayeredColor Source #

First interpolate background color, then foreground color

DiscreteDistance ColorString Source #

First interpolating characters, then color.

DiscreteDistance RectContainer Source #

Smoothly transforms the 4 sides of the rectangle simultaneously, from their middle to their extremities.

DiscreteDistance a => DiscreteDistance [a] 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.

Methods

distance :: [a] -> [a] -> Int Source #

distanceSuccessive :: Successive [a] -> Int Source #

DiscreteDistance a => DiscreteDistance (SequentiallyInterpolatedList a) 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.

DiscreteDistance (Color8 a) Source #

Using bresenham 3D algorithm in RGB space.

DiscreteDistance (Coords Pos) Source #

 Using bresenham 2d line algorithm.

DiscreteColorableMorphing a => DiscreteDistance (Colored a) Source #

Interpolates the color and morphs the Colorable at the same time.

newtype Successive a Source #

Wrapper on a list, to represents successive waypoints.

Constructors

Successive [a] 

Instances

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

interpolate Source #

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\).

interpolateSuccessive :: Successive v -> Int -> v Source #

Instances

DiscreteInterpolation Int Source #

Naïve interpolation.

DiscreteInterpolation LayeredColor Source #

First interpolate background color, then foreground color

DiscreteInterpolation ColorString Source #

First interpolating characters, then color.

DiscreteInterpolation a => DiscreteInterpolation [a] Source #

Interpolate in parallel between 2 lists : each pair of same-index elements is interpolated at the same time.

Methods

interpolate :: [a] -> [a] -> Int -> [a] Source #

interpolateSuccessive :: Successive [a] -> Int -> [a] Source #

DiscreteInterpolation a => DiscreteInterpolation (SequentiallyInterpolatedList a) 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.

DiscreteInterpolation (Color8 a) Source #

Using bresenham 3D algorithm in RGB space.

DiscreteInterpolation (Coords Pos) Source #

 Using bresenham 2d line algorithm.

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

drawMorphing Source #

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

DiscreteColorableMorphing a => DiscreteMorphing (Colored a) Source #

Colored can wrap a DiscreteColorableMorphing, to make a DiscreteMorphing.

Interpolates the color and morphs the Colorable at the same time.

Methods

drawMorphing :: (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.

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:

newtype SequentiallyInterpolatedList a Source #

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

Instances

Eq a => Eq (SequentiallyInterpolatedList a) Source # 
Ord a => Ord (SequentiallyInterpolatedList a) Source # 
Show a => Show (SequentiallyInterpolatedList a) Source # 
DiscreteDistance a => DiscreteDistance (SequentiallyInterpolatedList a) 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.

DiscreteInterpolation a => DiscreteInterpolation (SequentiallyInterpolatedList a) 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.

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

Instances

mkEvolutionEaseQuart Source #

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.

mkEvolution Source #

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.

getDeltaTimeToNextFrame Source #

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

getValueAt Source #

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) 

mkEaseClock Source #

Arguments

:: Float

Duration in seconds

-> Frame

Last frame

-> (Float -> Float)

Inverse ease function (value -> time, both between 0 and 1)

-> EaseClock 

Constructor of EaseClock

Reexports