| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Imj.Graphics.Interpolation
Contents
- class DiscreteDistance v where
- newtype Successive a = Successive [a]
- class DiscreteDistance v => DiscreteInterpolation v where
- class (DiscreteDistance v, Drawable v) => DiscreteMorphing v where
- class (DiscreteDistance a, Colorable a) => DiscreteColorableMorphing a where
- newtype SequentiallyInterpolatedList a = SequentiallyInterpolatedList [a]
- data Evolution v = Evolution {}
- mkEvolutionEaseQuart :: DiscreteDistance v => Successive v -> Float -> Evolution v
- mkEvolution :: DiscreteDistance v => (Float -> Float) -> Successive v -> Float -> Evolution v
- getDeltaTimeToNextFrame :: Evolution v -> Frame -> Maybe Float
- getValueAt :: DiscreteInterpolation v => Evolution v -> Frame -> v
- drawMorphingAt :: (DiscreteMorphing v, Draw e, MonadReader e m, MonadIO m) => Evolution v -> Frame -> m ()
- newtype EaseClock = EaseClock (Evolution NotWaypoint)
- mkEaseClock :: Float -> Frame -> (Float -> Float) -> EaseClock
- module Imj.Iteration
Discrete interpolation and morphing
DiscreteInterpolationdescribes interpolation by value , where the result of the interpolation between two \(v\) is a \(v\)DiscreteMorphingandDiscreteColorableMorphingdescribe 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, \)
Minimal complete definition
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.
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. |
| DiscreteDistance a => DiscreteDistance (SequentiallyInterpolatedList a) Source # | Interpolation between 2 |
| 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 |
newtype Successive a Source #
Wrapper on a list, to represents successive waypoints.
Constructors
| Successive [a] |
Instances
| Show a => Show (Successive a) Source # | |
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
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\).
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. |
| DiscreteInterpolation a => DiscreteInterpolation (SequentiallyInterpolatedList a) Source # | Interpolation between 2 |
| 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
Drawablex - The visual result of IO rendering commands induced by a
drawxcall.
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
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
| DiscreteColorableMorphing a => DiscreteMorphing (Colored a) Source # |
Interpolates the color and morphs the |
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
Colorablex - The visual result of IO rendering commands induced by a
drawUsingColorxcall.
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
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
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.
Constructors
| SequentiallyInterpolatedList [a] |
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 |
| DiscreteInterpolation a => DiscreteInterpolation (SequentiallyInterpolatedList a) Source # | Interpolation between 2 |
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.
Defines an evolution (interpolation or morphing) between Successive DiscreteDistances.
Constructors
| Evolution | |
Fields
| |
Arguments
| :: DiscreteDistance v | |
| => Successive v |
|
| -> 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 |
|
| -> 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 |
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. |
Draw a morphing
drawMorphingAt :: (DiscreteMorphing v, Draw e, MonadReader e m, MonadIO m) => Evolution v -> Frame -> m () Source #
Synchronizing multiple Evolutions
Used to synchronize multiple Evolutions.
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
module Imj.Iteration