# StrokePaintAnimationClock

Artifact: [androidx.ink:ink-strokes](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/strokes/StrokePaintAnimationClock.kt+class:androidx.ink.strokes.StrokePaintAnimationClock) Added in [1.1.0-alpha11](https://developer.android.com/jetpack/androidx/releases/ink#1.1.0-alpha11)

*** ** * ** ***

Common/All
- Cmn

  ```
  fun interface StrokePaintAnimationClock
  ```

*** ** * ** ***

Controls animated paint textures for rendered strokes. Typically a single `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokePaintAnimationClock` object is used for all strokes in a document.

## Summary

| ### Public companion functions |
|---|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0, toInclusive = false) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokePaintAnimationClock#calculateBasePaintAnimationPhaseForNewStroke(kotlin.Long,kotlin.Long)( clockStateMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, brushFamilyLoopDurationMillis: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 16777216) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html )` Given a whole-stroke animation duration, calculates the \[0, 1) base paint animation phase value for the stroke. | Cmn |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0, toInclusive = false) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokePaintAnimationClock#calculateCurrentAnimationPhaseForBrushPaint(kotlin.Long,kotlin.Long,kotlin.Long,kotlin.Float)( clockStateMillis: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, brushFamilyLoopDurationMillis: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 16777216) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, brushPaintLoopDurationMillis: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 16777216) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, strokeBasePaintAnimationPhase: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0, toInclusive = false) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Given a stroke's base paint animation phase, and its `BrushFamily`'s paint animation loop duration, and the paint animation loop duration for a particular `BrushPaint` in that family, returns the \[0, 1) phase value that `BrushPaint` should have at the given clock state. | Cmn |

| ### Public companion properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokePaintAnimationClock` | `https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokePaintAnimationClock#STOPPED_CLOCK()` An animation clock whose clock state never changes. | Cmn |

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/AnyThread https://developer.android.com/reference/kotlin/androidx/ink/strokes/StrokePaintAnimationClock#getClockStateMillis()()` Returns the number of subjective milliseconds that have elapsed since this clock's zero state. | Cmn |

## Public companion functions

### calculateBasePaintAnimationPhaseForNewStroke

Cmn Added in [1.1.0-alpha11](https://developer.android.com/jetpack/androidx/releases/ink#1.1.0-alpha11)

```
fun calculateBasePaintAnimationPhaseForNewStroke(
    clockStateMillis: Long,
    brushFamilyLoopDurationMillis: @IntRange(from = 0, to = 16777216) Long
): @FloatRange(from = 0.0, to = 1.0, toInclusive = false) Float
```

Given a whole-stroke animation duration, calculates the \[0, 1) base paint animation phase value for the stroke. This is the paint animation progress value that the stroke would use if the paint animation clock state were zero, such that the stroke is at the start of its animation at the current clock state.

If `brushFamilyLoopDurationMillis` is zero, indicating that the stroke's `BrushFamily` contains no animated `BrushPaint`s, then this method returns zero.

### calculateCurrentAnimationPhaseForBrushPaint

Cmn Added in [1.1.0-alpha11](https://developer.android.com/jetpack/androidx/releases/ink#1.1.0-alpha11)

```
fun calculateCurrentAnimationPhaseForBrushPaint(
    clockStateMillis: Long,
    brushFamilyLoopDurationMillis: @IntRange(from = 0, to = 16777216) Long,
    brushPaintLoopDurationMillis: @IntRange(from = 0, to = 16777216) Long,
    strokeBasePaintAnimationPhase: @FloatRange(from = 0.0, to = 1.0, toInclusive = false) Float
): @FloatRange(from = 0.0, to = 1.0, toInclusive = false) Float
```

Given a stroke's base paint animation phase, and its `BrushFamily`'s paint animation loop duration, and the paint animation loop duration for a particular `BrushPaint` in that family, returns the \[0, 1) phase value that `BrushPaint` should have at the given clock state.

If `brushPaintLoopDurationMillis` is zero, indicating that the `BrushPaint` is not animated, then this method returns zero. Otherwise, `brushFamilyLoopDurationMillis` must be a multiple of `brushPaintLoopDurationMillis`.

## Public companion properties

### STOPPED_CLOCK

Cmn

```
val STOPPED_CLOCK: StrokePaintAnimationClock
```

An animation clock whose clock state never changes.

## Public functions

### getClockStateMillis

Cmn Added in [1.1.0-alpha11](https://developer.android.com/jetpack/androidx/releases/ink#1.1.0-alpha11)

```
@AnyThread
fun getClockStateMillis(): Long
```

Returns the number of subjective milliseconds that have elapsed since this clock's zero state. Depending on the implementation, this value may update only once per frame, and it may change at a different speed than real time.

This method must be safe to call from any thread.