# BrushBehavior

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

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOS
- Cmn

  ```
  class BrushBehavior
  ```

*** ** * ** ***

A behavior describing how stroke input properties should affect the shape and color of the brush tip.

The behavior is conceptually a tree made from the various node types defined below. Each edge of the tree graph represents passing a nullable finite floating point value (with "null" representing an undefined value) from a node to its parent, and each node in the tree fits into one of the following categories:

1. Leaf nodes generate an output value without graph inputs. For example, they can create a value from properties of stroke input.

2. Filter nodes can conditionally toggle branches of the graph "on" by outputting their input value, or "off" by outputting a null value.

3. Operator nodes take in one or more input values and generate an output. For example, by mapping input to output with an easing function.

4. Terminal nodes apply one or more input values to chosen properties of the brush tip.

For each input in a stroke, `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushTip#behaviors()` are applied as follows:

1. The actual target modifier (as calculated above) for each tip property is accumulated from every `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior` present on the current `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushTip`. Multiple behaviors can affect the same `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.annotation/-target/index.html`. Depending on the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.annotation/-target/index.html`, modifiers from multiple behaviors will stack either additively or multiplicatively, according to the documentation for that `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.annotation/-target/index.html`. Regardless, the order of specified behaviors does not affect the result.

2. The modifiers are applied to the shape and color shift values of the tip's state according to the documentation for each `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.annotation/-target/index.html`. The resulting tip property values are then clamped or normalized to within their valid range of values. E.g. the final value of `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushTip#cornerRounding()` will be clamped within 0, 1. Generally: The affected shape values are those found in `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushTip` members. The color shift values remain in the range -100% to +100%. Note that when stored on a vertex, the color shift is encoded such that each channel is in the range 0, 1, where 0.5 represents a 0% shift.

Note that the accumulated tip shape property modifiers may be adjusted by the implementation before being applied: The rates of change of shape properties may be constrained to keep them from changing too rapidly with respect to distance traveled from one input to the next.

```kotlin
import androidx.ink.brush.BrushBehavior
import androidx.ink.brush.behavior.DampingNode
import androidx.ink.brush.behavior.ProgressDomain
import androidx.ink.brush.behavior.SourceNode
import androidx.ink.brush.behavior.SourceNode.Source
import androidx.ink.brush.behavior.TargetNode
import androidx.ink.brush.behavior.TargetNode.Target

BrushBehavior(
        TargetNode(
            // Modify the size of the brush tip, anywhere from 50% of normal up to 150% of normal.
            target = Target.SIZE_MULTIPLIER,
            targetModifierRangeStart = 0.5f,
            targetModifierRangeEnd = 1.5f,
            input =
                DampingNode(
                    // Apply distance-based damping to the input pressure, so that sudden changes in
                    // pressure
                    // will not result in immediate changes to tip size. Instead, the input value to
                    // the
                    // `TargetNode` will fade towards the current value of the `SourceNode` over a
                    // distance of
                    // approximately 75% of the base brush diameter.
                    dampOver = ProgressDomain.DISTANCE_IN_MULTIPLES_OF_BRUSH_SIZE,
                    strength = 0.75f,
                    input =
                        SourceNode(
                            // This behavior is based on stylus pressure, with minimum (0) pressure
                            // mapping to a
                            // 50% size multiplier, and maximum (1) pressure mapping to a 150% size
                            // multiplier.
                            source = Source.NORMALIZED_PRESSURE,
                            sourceValueRangeStart = 0.0f,
                            sourceValueRangeEnd = 1.0f,
                        ),
                ),
        )
    )
```

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior#BrushBehavior(androidx.ink.brush.behavior.TerminalNode,kotlin.String)(terminalNode: https://developer.android.com/reference/kotlin/androidx/ink/brush/behavior/TerminalNode, developerComment: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Constructs a `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior` with a single `https://developer.android.com/reference/kotlin/androidx/ink/brush/behavior/TerminalNode`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior#BrushBehavior(kotlin.collections.List,kotlin.String)( terminalNodes: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/ink/brush/behavior/TerminalNode>, developerComment: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html )` Constructs a `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior` with a list of `https://developer.android.com/reference/kotlin/androidx/ink/brush/behavior/TerminalNode`s. | Cmn |

| ### Public functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/ink/brush/Version` | `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior#calculateMinimumRequiredVersion()()` Returns the minimum required `https://developer.android.com/reference/kotlin/androidx/ink/brush/Version` for this `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior`. | Cmn |
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior#equals(kotlin.Any)(other: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?)` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior#hashCode()()` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior#toString()()` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior#developerComment()` A multi-line, human-readable string with a description of this brush behavior and its purpose within the brush, with the intended audience being designers/developers who are editing the brush definition. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/ink/brush/behavior/TerminalNode>` | `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior#terminalNodes()` An immutable list of the targets that this `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior` affects. | Cmn |

## Public constructors

### BrushBehavior

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

```
BrushBehavior(terminalNode: TerminalNode, developerComment: String = "")
```

Constructs a `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior` with a single `https://developer.android.com/reference/kotlin/androidx/ink/brush/behavior/TerminalNode`.

### BrushBehavior

Cmn

```
BrushBehavior(
    terminalNodes: List<TerminalNode>,
    developerComment: String = ""
)
```

Constructs a `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior` with a list of `https://developer.android.com/reference/kotlin/androidx/ink/brush/behavior/TerminalNode`s.

## Public functions

### calculateMinimumRequiredVersion

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

```
fun calculateMinimumRequiredVersion(): Version
```

Returns the minimum required `https://developer.android.com/reference/kotlin/androidx/ink/brush/Version` for this `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior`.

By default, decoding a `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushFamily` containing a `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior` with a minimum required version higher than `https://developer.android.com/reference/kotlin/androidx/ink/brush/Version#MAX_SUPPORTED()` will fail.

### equals

Cmn

```
open operator fun equals(other: Any?): Boolean
```

### hashCode

Cmn

```
open fun hashCode(): Int
```

### toString

Cmn

```
open fun toString(): String
```

## Public properties

### developerComment

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

```
val developerComment: String
```

A multi-line, human-readable string with a description of this brush behavior and its purpose within the brush, with the intended audience being designers/developers who are editing the brush definition. This string is not generally intended to be displayed to end users.

### terminalNodes

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

```
val terminalNodes: List<TerminalNode>
```

An immutable list of the targets that this `https://developer.android.com/reference/kotlin/androidx/ink/brush/BrushBehavior` affects.