> For the complete documentation index, see [llms.txt](https://robertmay2003.gitbook.io/eaz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://robertmay2003.gitbook.io/eaz/easing.md).

# Easing

The Easing class contains every easing method, as well as a number of static methods used to easily generate new Easing objects and a handful of predefined Easing objects for easy accessibility.

## Constructor

### Easing(inFunction: (t: number) => number)

The constructor for **`Easing`** objects takes an inFunction, the function used to calculate eased time into the curve. The out and inOut functions can be generated using the given in function.

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { Easing } from 'eaz';

const myEasing: Easing = new Easing((t: number) => t ** 2);
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { Easing } from 'eaz';

const myEasing = new Easing(t => t ** 2);
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
An easing function should ideally return a value equal to or approximately 0 at time = 0, and a value equal to or approximately 1 at time = 1.
{% endhint %}

## Methods

### in(t: number): number

The function used to calculate eased time into the curve

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { Easing } from 'eaz';

const cubicEasing: Easing = Easing.cubic;
const result: number = cubicEasing.in(0.5); // Expected value: 0.125
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { Easing } from 'eaz';

const cubicEasing = Easing.cubic;
const result = cubicEasing.in(0.5); // Expected value: 0.125
```

{% endtab %}

{% tab title="Visualization" %}
![Easing.cubic.in evaluated from 0 to 1 drawn as a line using DemoImage](https://2295660694-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFKOhllDCtDrHJJMhJK%2F-MFKm8lWScORAXYC6nj3%2F-MFKrwTj7QSzPa0HXlov%2FcubicIn.png?alt=media\&token=06def848-2d73-49b1-8fdb-d015457720d6)
{% endtab %}
{% endtabs %}

{% hint style="info" %}
The **`in`** method is evaluated over the first half of the curve, when time < 0.5,  and will usually have upwards concavity
{% endhint %}

### out(t: number): number

The function used to calculate eased time out of the curve, generated using the in function

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { Easing } from 'eaz';

const cubicEasing: Easing = Easing.cubic;
const result: number = cubicEasing.out(0.5); // Expected value: 0.875
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { Easing } from 'eaz';

const cubicEasing = Easing.cubic;
const result = cubicEasing.out(0.5); // Expected value: 0.875
```

{% endtab %}

{% tab title="Visualization" %}
![Easing.cubic.out evaluated from 0 to 1 drawn as a line using DemoImage](https://2295660694-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFKOhllDCtDrHJJMhJK%2F-MFKm8lWScORAXYC6nj3%2F-MFKscLOxgvinFSs96U8%2FcubicOut.png?alt=media\&token=8cc6e6da-bda7-4835-9434-ac9500fae98b)
{% endtab %}
{% endtabs %}

{% hint style="info" %}
The **`out`** method is evaluated over the first half of the curve, when time > 0.5,  and will usually have downwards concavity
{% endhint %}

### inOut(t: number): number

The function used to calculate the eased time into the function (where time < 0.5) and subsequently out of the function (where time > 0.5)

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { Easing } from 'eaz';

const cubicEasing: Easing = Easing.cubic;
const result: number = cubicEasing.inOut(0.4); // Expected value: 0.256
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { Easing } from 'eaz';

const cubicEasing = Easing.cubic;
const result = cubicEasing.inOut(0.4); // Expected value: 0.256
```

{% endtab %}

{% tab title="Visualization" %}
![Easing.cubic.inOut evaluated from 0 to 1 drawn as a line using DemoImage](https://2295660694-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFKOhllDCtDrHJJMhJK%2F-MFKm8lWScORAXYC6nj3%2F-MFKsVAg6w3Hdkt5ndgo%2FcubicInOut.png?alt=media\&token=c1de6812-d94e-46ef-874b-c95283a8cd10)
{% endtab %}
{% endtabs %}

### inverse(): Easing

Returns a new **`Easing`** object for which the in and out functions are reversed

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { Easing } from 'eaz';

const cubicEasing: Easing = Easing.cubic;
const result: number = cubicEasing.in(0.5); // Expected value: 0.125
const inverseResult: number = cubicEasing.inverse().out(0.5); // expected value: 0.125
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { Easing } from 'eaz';

const cubicEasing: Easing = Easing.cubic;
const result: number = cubicEasing.in(0.5); // Expected value: 0.125
const inverseResult: number = cubicEasing.inverse().out(0.5); // expected value: 0.125
```

{% endtab %}
{% endtabs %}

## Static Methods

### inOut(inEasing: Easing, outEasing: Easing, t: number): number

Calculates the in-out eased time of the curve using two different **`Easing`** objects for the in and out functions

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { Easing } from 'eaz';

const cubicEasing: Easing = Easing.cubic;
const linearEasing: Easing = Easing.linear;
const result: number = Easing.inOut(cubicEasing, linearEasing, 0.75); // Expected value: 0.6
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { Easing } from 'eaz';

const cubicEasing = Easing.cubic;
const linearEasing = Easing.linear;
const result = Easing.inOut(cubicEasing, linearEasing, 0.75); // Expected value: 0.6
```

{% endtab %}

{% tab title="Visualization" %}
![Easing.inOut evaluated from 0 to 1 using cubic in-easing and linear out-easing](https://2295660694-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFKOhllDCtDrHJJMhJK%2F-MFKm8lWScORAXYC6nj3%2F-MFKwrBIBzuC4sBOdjoP%2FcubicLinearInOut.png?alt=media\&token=e07ce291-a1e8-4424-8dea-92bab93e373d)
{% endtab %}
{% endtabs %}

### interpolate(inEasing: Easing, outEasing: Easing, t: number, smoothing: number = 0.25): number

Calculates the in-out eased time of the curve using two different **`Easing`** objects for the in and out functions with a smooth the transition between the in and out function

{% tabs %}
{% tab title="TypeScript" %}

```typescript
import { Easing } from 'eaz';

const cubicEasing: Easing = Easing.cubic;
const linearEasing: Easing = Easing.linear;
const result: number = Easing.interpolate(cubicEasing, linearEasing, 0.6); // Expected value: 0.6294912
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { Easing } from 'eaz';

const cubicEasing = Easing.cubic;
const linearEasing = Easing.linear;
const result = Easing.interpolate(cubicEasing, linearEasing, 0.6); // Expected value: 0.6294912
```

{% endtab %}

{% tab title="Visualization" %}
![Easing.interpolate evaluated from 0 to 1 using cubic in-easing and linear out-easing](https://2295660694-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFKOhllDCtDrHJJMhJK%2F-MFKm8lWScORAXYC6nj3%2F-MFKyGarvj0x5lh3B2vd%2FcubicLinearInterpolate.png?alt=media\&token=87fc7f69-0b79-4986-b6ac-5b62126ed279)
{% endtab %}
{% endtabs %}

{% hint style="warning" %}
Calling **`Easing.interpolate`** with a smoothing value of 0 will return the equivalent of **`Easing.inOut`**
{% endhint %}
