# FloatAnimationSpec

Artifact: [androidx.compose.animation:animation-core](https://developer.android.com/jetpack/androidx/releases/compose-animation) [View Source](https://cs.android.com/search?q=file:androidx/compose/animation/core/FloatAnimationSpec.kt+class:androidx.compose.animation.core.FloatAnimationSpec) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0) Common/All
- Cmn

  ```
  interface FloatAnimationSpec : AnimationSpec<Float>
  ```
Known direct subclasses [FloatSpringSpec](https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatSpringSpec), [FloatTweenSpec](https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatTweenSpec)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatSpringSpec` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatSpringSpec` animation uses a spring animation to animate a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` value. |
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatTweenSpec` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatTweenSpec` animates a Float value from any start value to any end value using a provided `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatTweenSpec#(kotlin.Int,kotlin.Int,androidx.compose.animation.core.Easing)` function. |

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec` interface is similar to `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/VectorizedAnimationSpec`, except it deals exclusively with floats.

Like `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/VectorizedAnimationSpec`, `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec` is entirely stateless as well. It requires start/end values and start velocity to be passed in for the query of velocity and value of the animation. The `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec` itself stores only the animation configuration (such as the delay, duration and easing curve for `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatTweenSpec`, or spring constants for `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatSpringSpec`.

A `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec` can be converted to an `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/VectorizedAnimationSpec` using `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec#vectorize(androidx.compose.animation.core.TwoWayConverter)`.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/VectorizedAnimationSpec` |   |

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec#getDurationNanos(kotlin.Float,kotlin.Float,kotlin.Float)( initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Calculates the duration of an animation. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec#getEndVelocity(kotlin.Float,kotlin.Float,kotlin.Float)( initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Calculates the end velocity of the animation with the provided start/end values, and start velocity. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec#getValueFromNanos(kotlin.Long,kotlin.Float,kotlin.Float,kotlin.Float)( playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec#getVelocityFromNanos(kotlin.Long,kotlin.Float,kotlin.Float,kotlin.Float)( playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity. | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/animation/core/VectorizedFloatAnimationSpec<V>` | `<V : https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationVector> https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec#vectorize(androidx.compose.animation.core.TwoWayConverter)(converter: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/TwoWayConverter<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, V>)` Create an `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/VectorizedAnimationSpec` that animates `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationVector` from a `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec`. | Cmn |

## Public functions

### getDurationNanos

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
fun getDurationNanos(
    initialValue: Float,
    targetValue: Float,
    initialVelocity: Float
): Long
```

Calculates the duration of an animation. For duration-based animations, this will return the pre-defined duration. For physics-based animations, the duration will be estimated based on the physics configuration (such as spring stiffness, damping ratio, visibility threshold) as well as the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec#getDurationNanos(kotlin.Float,kotlin.Float,kotlin.Float)`, `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec#getDurationNanos(kotlin.Float,kotlin.Float,kotlin.Float)` values, and `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec#getDurationNanos(kotlin.Float,kotlin.Float,kotlin.Float)`.

**Note**: this may be a computation that is expensive - especially with spring based animations

| Parameters |
|---|---|
| `initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start value of the animation |
| `targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | end value of the animation |
| `initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start velocity of the animation |

### getEndVelocity

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
open fun getEndVelocity(
    initialValue: Float,
    targetValue: Float,
    initialVelocity: Float
): Float
```

Calculates the end velocity of the animation with the provided start/end values, and start velocity. For duration-based animations, end velocity will be the velocity of the animation at the duration time. This is also the default assumption. However, for spring animations, the transient trailing velocity will be snapped to zero.

| Parameters |
|---|---|
| `initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start value of the animation |
| `targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | end value of the animation |
| `initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start velocity of the animation |

### getValueFromNanos

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
fun getValueFromNanos(
    playTimeNanos: Long,
    initialValue: Float,
    targetValue: Float,
    initialVelocity: Float
): Float
```

Calculates the value of the animation at given the playtime, with the provided start/end values, and start velocity.

| Parameters |
|---|---|
| `playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | time since the start of the animation |
| `initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start value of the animation |
| `targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | end value of the animation |
| `initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start velocity of the animation |

### getVelocityFromNanos

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
fun getVelocityFromNanos(
    playTimeNanos: Long,
    initialValue: Float,
    targetValue: Float,
    initialVelocity: Float
): Float
```

Calculates the velocity of the animation at given the playtime, with the provided start/end values, and start velocity.

| Parameters |
|---|---|
| `playTimeNanos: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | time since the start of the animation |
| `initialValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start value of the animation |
| `targetValue: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | end value of the animation |
| `initialVelocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | start velocity of the animation |

### vectorize

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.0.0)

```
open fun <V : AnimationVector> vectorize(converter: TwoWayConverter<Float, V>): VectorizedFloatAnimationSpec<V>
```

Create an `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/VectorizedAnimationSpec` that animates `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationVector` from a `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec`. Every dimension of the `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationVector` will be animated using the given `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/FloatAnimationSpec`.