# PathEasing

# PathEasing

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/PathEasing.kt+class:androidx.compose.animation.core.PathEasing)  
Added in[1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-animation#1.6.0)
Common/All
  - Cmn  

  ```
  class PathEasing : Easing
  ```

*** ** * ** ***

An easing function for an arbitrary[Path](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path).

The[Path](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path)must begin at`(0, 0)`and end at`(1, 1)`. The x-coordinate along the[Path](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path)is the input value and the output is the y coordinate of the line at that point. This means that the Path must conform to a function`y = f(x)`.

The[Path](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path)must be continuous along the x axis. The[Path](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path)should also be monotonically increasing along the x axis. If the[Path](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path)is not monotonic and there are multiple y values for a given x, the chosen y value is implementation dependent and may vary.

The[Path](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path)must not contain any[Path.close](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path#close())command as it would force the path to restart from the beginning.

This is equivalent to the Android`PathInterpolator`.

[CubicBezierEasing](https://developer.android.com/reference/kotlin/androidx/compose/animation/core/CubicBezierEasing)should be used if a single bezier curve is required as it performs fewer allocations.[PathEasing](https://developer.android.com/reference/kotlin/androidx/compose/animation/core/PathEasing)should be used when creating an arbitrary path.

Note: a[PathEasing](https://developer.android.com/reference/kotlin/androidx/compose/animation/core/PathEasing)instance can be used from any thread, but not concurrently.  

```kotlin
import androidx.compose.animation.core.PathEasing
import androidx.compose.animation.core.animateIntOffsetAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp

// Creates a custom PathEasing curve and applies it to an animation
var toggled by remember { mutableStateOf(true) }
val pathForAnimation = remember {
    Path().apply {
        moveTo(0f, 0f)
        cubicTo(0.05f, 0f, 0.133333f, 0.06f, 0.166666f, 0.4f)
        cubicTo(0.208333f, 0.82f, 0.25f, 1f, 1f, 1f)
    }
}
val offset by
    animateIntOffsetAsState(
        targetValue = if (toggled) IntOffset.Zero else IntOffset(300, 300),
        label = "offset",
        animationSpec = tween(durationMillis = 1000, easing = PathEasing(pathForAnimation)),
    )
Box(modifier = Modifier.fillMaxSize().clickable { toggled = !toggled }) {
    Box(modifier = Modifier.offset { offset }.size(100.dp).background(Color.Blue))
}
```

## Summary

|                                                                                                                  ### Public constructors                                                                                                                  |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| [PathEasing](https://developer.android.com/reference/kotlin/androidx/compose/animation/core/PathEasing#PathEasing(androidx.compose.ui.graphics.Path))`(path: `[Path](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path)`)` | Cmn |

|                                  ### Public functions                                  |
|----------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----|
| `open `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | [transform](https://developer.android.com/reference/kotlin/androidx/compose/animation/core/PathEasing#transform(kotlin.Float))`(fraction: `[Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`)` | Cmn |

## Public constructors

### PathEasing

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

```
PathEasing(path: Path)
```  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| `path: `[Path](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path) | The[Path](https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path)to use to make the curve representing the easing curve. |

## Public functions

### transform

Cmn  

```
open fun transform(fraction: Float): Float
```