# Step Effects

Every [step](https://codeanimate.dev/docs/steps.md) after the first one arrives with an **effect**.

There are 28. This page shows each one playing, and tells you how it works.

To choose one in the editor, see [Effects, Focus and Timing](https://codeanimate.dev/docs/effects.md#choose-an-effect).

## The example

Every animation on this page shows the same change, so that you can compare them.

Step 1 is a function that adds up prices in a loop. Step 2 does the same in one line, and adds a tax.

<details>
<summary>The two steps, as text</summary>

Step 1:

```python
def total(items):
    result = 0
    for item in items:
        result += item.price
    return result
```

Step 2:

```python
def total(items, tax=0.2):
    subtotal = sum(item.price for item in items)
    return subtotal * (1 + tax)
```

</details>

The only thing that changes from one animation to the next is the effect of step 2.

## How an effect works

When the animation goes from one step to the next, it compares the two versions of the code piece by piece: each word, name, number and symbol.

That gives three kinds of code:

* **Kept**: pieces that are in both steps. In the example, `def total(items`, `for item`, `price` and `return` are kept, even though some of them end up on another line.
* **Removed**: pieces that are only in the old step, like `result` and `+=`.
* **New**: pieces that are only in the new step, like `tax=0.2` and `sum(`.

An effect is a rule for what each of the three does.

The effects come in four groups, the same four you see in the gallery in the editor:

| Group | What happens |
|---|---|
| [Keep matching code](#keep-matching-code) | Kept code glides to its new place while the rest fades. |
| [Bring in the new code](#bring-in-the-new-code) | Kept code moves first. Then the new code makes an entrance. |
| [Replace the block](#replace-the-block) | All the old code leaves, and then all the new code arrives. |
| [Slide](#slide) | The old code slides out as the new code slides in. |

### How long it takes

An effect takes the time you set in **Transition**, in the **Motion** tab.

Each step can also have its own **Speed**, from `0.25×` to `2×`. At `2×` the effect takes half the time, and at `0.5×` it takes twice as long.

No effect plays in less than 0.2 seconds.

In the animations on this page, the transition is 1.4 seconds, which is slower than the default. That gives you time to see what happens.

> [!TIP]
> In each animation, step 1 is typed quickly, and rests for a moment. Then the effect plays, and the result rests before the loop starts again.
>
> Click an animation to open its page. There you can also copy its code.

## Keep matching code

These four are for a change where most of the code stays. The kept pieces glide to their new places through the whole transition, so your viewers can follow each one with their eyes.

### Morph

The default.

The kept pieces glide from where they were to where they are now. The removed pieces fade out during the first half, and the new pieces fade in during the second.

Nothing else moves, so this is the calmest way to show a change.

[![The Morph effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/fxDNQALXTT83ynRsGC3ngA.svg)](https://codeanimate.dev/p/fxDNQALXTT83ynRsGC3ngA?copy=1)

### Pulse

A morph, while the whole block swells and settles twice, like a heartbeat. The second beat is smaller than the first.

Use it to say *something just changed here* without taking the eyes off the code.

[![The Pulse effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/vtwv3LQMsbEmemEnefhd_Q.svg)](https://codeanimate.dev/p/vtwv3LQMsbEmemEnefhd_Q?copy=1)

### Shake

A morph, while the whole block rocks from side to side, a little less each time, until it's still.

[![The Shake effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/RlSljenQ2CLpnz1m5R9a7Q.svg)](https://codeanimate.dev/p/RlSljenQ2CLpnz1m5R9a7Q?copy=1)

### Wobble

A morph, while the whole block gets wider and shorter, then taller and narrower, like jelly, and settles.

[![The Wobble effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/kYLlfMl2s1_YWK_sazFVDQ.svg)](https://codeanimate.dev/p/kYLlfMl2s1_YWK_sazFVDQ?copy=1)

## Bring in the new code

These ten are for a change where the new code is the point.

They all start the same way: in the first 40% of the transition, the kept pieces glide to their new places and the removed pieces clear away. The code that stays is then where it belongs, with gaps where the new code goes.

The rest of the transition is the entrance of the new code. That's where they differ.

### Type

The new code is typed into the gaps, in reading order, with a cursor.

It looks like someone writing the change by hand, the same way step 1 is typed.

[![The Type effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/lAShYL8r-ptdd19lrZV0Dg.svg)](https://codeanimate.dev/p/lAShYL8r-ptdd19lrZV0Dg?copy=1)

### Materialize

The new pieces fade in right where they belong, a few at a time.

The order looks random, but it's the same every time the animation plays.

[![The Materialize effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/AcOwlcLRCOcdFV2ozOeOiA.svg)](https://codeanimate.dev/p/AcOwlcLRCOcdFV2ozOeOiA?copy=1)

### Rain

Like Materialize, a few pieces at a time. But each piece also falls into its place, from about a line and a half above.

[![The Rain effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/Ta5CnSYH3wn7kk2_Bp8fJQ.svg)](https://codeanimate.dev/p/Ta5CnSYH3wn7kk2_Bp8fJQ?copy=1)

### Matrix

The new code rains down its columns, a letter at a time.

In each column the lowest letter leads and the others follow it, each one a little dimmer than the one ahead. The columns start at slightly different moments, and they all take the same time to fall, so a tall column falls faster.

The letters are green while they fall. When a column lands, its letters take their own colors.

[![The Matrix effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/wZNhcf12OYzv03CE-kudGg.svg)](https://codeanimate.dev/p/wZNhcf12OYzv03CE-kudGg?copy=1)

### Color matrix

The same rain as Matrix, with every letter falling in the color it will have, instead of green.

[![The Color matrix effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/TnG_BZisaoBu3UfeMcFCRA.svg)](https://codeanimate.dev/p/TnG_BZisaoBu3UfeMcFCRA?copy=1)

### Cascade

The new lines slide in from the left, the top one first and then the others, one after another.

[![The Cascade effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/QtUlJLOEmvTI-WN2ewq0kg.svg)](https://codeanimate.dev/p/QtUlJLOEmvTI-WN2ewq0kg?copy=1)

### Rise

The new lines come up from one line below their place, one after another.

[![The Rise effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/NMPqgLY9DXcvcXWi22V3xw.svg)](https://codeanimate.dev/p/NMPqgLY9DXcvcXWi22V3xw?copy=1)

### Weave

The new lines slide in from alternate sides: one from the left, the next from the right.

[![The Weave effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/Na-jbSblKzpFVNCPOmfjCA.svg)](https://codeanimate.dev/p/Na-jbSblKzpFVNCPOmfjCA?copy=1)

### Sweep

The new code arrives from left to right. The pieces nearest the left edge come in first, whatever line they are on, like a curtain being drawn across the code.

[![The Sweep effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/VynfWmnazBj5nAYev3kB8g.svg)](https://codeanimate.dev/p/VynfWmnazBj5nAYev3kB8g?copy=1)

### Assemble

All the new pieces start scattered around their places, up to a few lines and columns away, and fly in together.

[![The Assemble effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/WKuv6AbFg0o4c10Ju1iOQQ.svg)](https://codeanimate.dev/p/WKuv6AbFg0o4c10Ju1iOQQ?copy=1)

## Replace the block

These ten don't look at what the two steps share. They treat the code as one picture: the old one leaves, and the new one arrives.

The code itself changes at the moment when nothing can be seen, so the swap is never visible.

Use them when the two steps have little in common, or when you want a clear break between them, like a new slide.

### Fade

The old code fades out, and then the new code fades in. Nothing moves.

[![The Fade effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/7e6d-aUrpG0KZ7_rnmsXwQ.svg)](https://codeanimate.dev/p/7e6d-aUrpG0KZ7_rnmsXwQ?copy=1)

### Zoom

The old code grows a little as it fades out. The new code starts a little small and grows into place.

[![The Zoom effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/4nLv8vx7AFBjj6r-M2Q_yA.svg)](https://codeanimate.dev/p/4nLv8vx7AFBjj6r-M2Q_yA?copy=1)

### Zoom out

Zoom, backwards. The old code shrinks a little as it fades out. The new code starts a little large and settles into place.

[![The Zoom out effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/0yMZGZxxabtiiPhE9G2GcA.svg)](https://codeanimate.dev/p/0yMZGZxxabtiiPhE9G2GcA?copy=1)

### Pop

The old code shrinks away quickly. The new code springs up from small, goes a little past its full size, and settles.

[![The Pop effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/_QaNzlANoxaIGkVXRd4_eg.svg)](https://codeanimate.dev/p/_QaNzlANoxaIGkVXRd4_eg?copy=1)

### Bounce

The old code drops down and away. The new code falls in from a line above, and bounces twice before it rests.

[![The Bounce effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/Cp83rps1MmbjL378AFYUYw.svg)](https://codeanimate.dev/p/Cp83rps1MmbjL378AFYUYw?copy=1)

### Slam

The old code clears quickly. The new code drops in from almost twice its size, faster and faster until it lands, and the block shakes once from the hit.

[![The Slam effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/CXcR4VrBs8ykUJ6Gvp-yrA.svg)](https://codeanimate.dev/p/CXcR4VrBs8ykUJ6Gvp-yrA?copy=1)

### Flip

The block folds flat from the top and the bottom, like a card turning over. When it's edge-on, the code changes, and the block opens again on the new code.

[![The Flip effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/nDQPtbt1uZhJjVwHNBbyRg.svg)](https://codeanimate.dev/p/nDQPtbt1uZhJjVwHNBbyRg?copy=1)

### Turn

The same as Flip, from the sides: like a page turning.

[![The Turn effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/V6ThmtRI6Q-jXaU-J9qLdA.svg)](https://codeanimate.dev/p/V6ThmtRI6Q-jXaU-J9qLdA?copy=1)

### Twist

The old code turns a few degrees and shrinks a little as it fades. The new code turns into place from the other side.

[![The Twist effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/en1Zx-bXLYCMkJQpfdgGeA.svg)](https://codeanimate.dev/p/en1Zx-bXLYCMkJQpfdgGeA?copy=1)

### Glitch

Nothing glides here. The block jumps sideways and dims in sudden steps, goes dark for an instant, and comes back as the new code, like a bad signal.

[![The Glitch effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/Y2SBtg-VNkTK9TuHVcB47w.svg)](https://codeanimate.dev/p/Y2SBtg-VNkTK9TuHVcB47w?copy=1)

## Slide

These four also replace the whole block. The old code slides out as it fades, and the new code slides in from the opposite side.

It's a short move: one line up or down, or three columns sideways.

### From bottom

The old code slides up and out. The new code slides in from the bottom.

[![The Slide from bottom effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/Asq_AXSDNT36B4xyNPWIZg.svg)](https://codeanimate.dev/p/Asq_AXSDNT36B4xyNPWIZg?copy=1)

### From top

The old code slides down and out. The new code slides in from the top.

[![The Slide from top effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/rQnXypE-RWISMqEuiJpU2Q.svg)](https://codeanimate.dev/p/rQnXypE-RWISMqEuiJpU2Q?copy=1)

### From left

The old code slides out to the right. The new code slides in from the left.

[![The Slide from left effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/wZvSH_rV6K7NKekOwn4KUw.svg)](https://codeanimate.dev/p/wZvSH_rV6K7NKekOwn4KUw?copy=1)

### From right

The old code slides out to the left. The new code slides in from the right.

[![The Slide from right effect, playing on a small change to cart.py](https://codeanimate.dev/api/embed/Sz2QUU1rXIMGj3iiOtQJ8g.svg)](https://codeanimate.dev/p/Sz2QUU1rXIMGj3iiOtQJ8g?copy=1)

## Which one to use

There are no rules, but this can help you start:

| You want to show | Try |
|---|---|
| A small edit, where the eyes should follow the code that stays | **Morph** |
| New lines being added to code that stays | **Type**, **Cascade** or **Rise** |
| A value or a name that changes, with some emphasis | **Pulse** or **Pop** |
| A completely different piece of code | **Fade**, **Flip** or a **Slide** |
| The big moment of your talk | **Slam**, **Glitch** or **Matrix** |

> [!TIP]
> You can use a different effect for each step. But an animation is easier to follow when most steps use the same one, and you keep the loud effects for the moment that matters.

## Where the effects play

An effect plays the same way everywhere your animation goes:

* In the preview of the editor.
* In the [GIF and MP4 files](https://codeanimate.dev/docs/exporting.md) that you export.
* In the [embeds](https://codeanimate.dev/docs/sharing.md) that you share, both the animated SVG and the GIF.

> [!NOTE]
> **Matrix** and **Color matrix** draw every falling letter on its own, which makes an embed bigger.
>
> So if an animation adds a lot of code with these two effects (more than about 600 letters in total), the steps that go over rain whole words instead of single letters.

## Recap

* An effect decides what the **kept**, the **removed** and the **new** code do when the animation goes from one step to the next.
* **Keep matching code** follows the code that stays. **Bring in the new code** gives the new code an entrance. **Replace the block** and **Slide** change everything at once.
* It takes the time of your **Transition**, changed by the **Speed** of the step.

In an API [snapshot](https://codeanimate.dev/docs/api-reference.md#the-snapshot), an effect is the `effect` of a step. The values are listed there.
