{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Diagrams.Animation
(
QAnimation
, Animation
, animEnvelope, animEnvelope'
, animRect, animRect'
) where
import Data.Active
import Data.Semigroup
import Diagrams.Core
import Diagrams.Animation.Active ()
import Diagrams.BoundingBox
import Diagrams.Combinators
import Diagrams.TrailLike
import Diagrams.TwoD.Shapes
import Diagrams.TwoD.Types
import Linear.Metric
type QAnimation b v n m = Active (QDiagram b v n m)
type Animation b v n = QAnimation b v n Any
animEnvelope :: (OrderedField n, Metric v, Monoid' m)
=> QAnimation b v n m -> QAnimation b v n m
animEnvelope :: forall n (v :: * -> *) m b.
(OrderedField n, Metric v, Monoid' m) =>
QAnimation b v n m -> QAnimation b v n m
animEnvelope = Rational -> QAnimation b v n m -> QAnimation b v n m
forall n (v :: * -> *) m b.
(OrderedField n, Metric v, Monoid' m) =>
Rational -> QAnimation b v n m -> QAnimation b v n m
animEnvelope' Rational
30
animEnvelope' :: (OrderedField n, Metric v, Monoid' m)
=> Rational -> QAnimation b v n m -> QAnimation b v n m
animEnvelope' :: forall n (v :: * -> *) m b.
(OrderedField n, Metric v, Monoid' m) =>
Rational -> QAnimation b v n m -> QAnimation b v n m
animEnvelope' Rational
r QAnimation b v n m
a = [QDiagram b v n m] -> QDiagram b v n m -> QDiagram b v n m
forall (v :: * -> *) n a m b.
(InSpace v n a, Monoid' m, Enveloped a) =>
a -> QDiagram b v n m -> QDiagram b v n m
withEnvelope (Rational -> QAnimation b v n m -> [QDiagram b v n m]
forall a. Rational -> Active a -> [a]
simulate Rational
r QAnimation b v n m
a) (QDiagram b v n m -> QDiagram b v n m)
-> QAnimation b v n m -> QAnimation b v n m
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> QAnimation b v n m
a
animRect :: (InSpace V2 n t, Monoid' m, TrailLike t, Enveloped t, Transformable t, Monoid t)
=> QAnimation b V2 n m -> t
animRect :: forall n t m b.
(InSpace V2 n t, Monoid' m, TrailLike t, Enveloped t,
Transformable t, Monoid t) =>
QAnimation b V2 n m -> t
animRect = Rational -> QAnimation b V2 n m -> t
forall n t m b.
(InSpace V2 n t, Monoid' m, TrailLike t, Enveloped t,
Transformable t, Monoid t) =>
Rational -> QAnimation b V2 n m -> t
animRect' Rational
30
animRect' :: (InSpace V2 n t, Monoid' m, TrailLike t, Enveloped t, Transformable t, Monoid t)
=> Rational -> QAnimation b V2 n m -> t
animRect' :: forall n t m b.
(InSpace V2 n t, Monoid' m, TrailLike t, Enveloped t,
Transformable t, Monoid t) =>
Rational -> QAnimation b V2 n m -> t
animRect' Rational
r QAnimation b V2 n m
anim
| [QDiagram b V2 n m] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [QDiagram b V2 n m]
results = n -> n -> t
forall n t. (InSpace V2 n t, TrailLike t) => n -> n -> t
rect n
1 n
1
| Bool
otherwise = BoundingBox V2 n -> t -> t
forall (v :: * -> *) n a.
(InSpace v n a, HasBasis v, Enveloped a, Transformable a,
Monoid a) =>
BoundingBox v n -> a -> a
boxFit ((QDiagram b V2 n m -> BoundingBox V2 n)
-> [QDiagram b V2 n m] -> BoundingBox V2 n
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap QDiagram b V2 n m -> BoundingBox V2 n
forall (v :: * -> *) n a.
(InSpace v n a, HasBasis v, Enveloped a) =>
a -> BoundingBox v n
boundingBox [QDiagram b V2 n m]
results) (n -> n -> t
forall n t. (InSpace V2 n t, TrailLike t) => n -> n -> t
rect n
1 n
1)
where
results :: [QDiagram b V2 n m]
results = Rational -> QAnimation b V2 n m -> [QDiagram b V2 n m]
forall a. Rational -> Active a -> [a]
simulate Rational
r QAnimation b V2 n m
anim