# Quickstart

This scene shows the core idea in one run: one state value drives a point on a
curve, a tangent line, a guide line, and a number that follows the point.

Create a file called `quickstart.py`:

```python
from manim import *
import numpy as np

from manim_stateflow import ReactiveScene, d, lift


class Quickstart(ReactiveScene):
    def construct(self):
        axes = Axes(
            x_range=[-4, 4, 1],
            y_range=[-2, 2, 1],
            x_length=8,
            y_length=4,
            tips=False,
        )
        curve = axes.plot(lambda t: np.sin(t), x_range=[-PI, PI], color=BLUE, stroke_width=5)

        x = self.state(-PI)
        y = lift(lambda x_value: np.sin(x_value), x)
        slope = lift(lambda x_value: np.cos(x_value), x)
        point = lift(lambda x_value, y_value: axes.c2p(x_value, y_value), x, y)

        dot = d.Dot(point, color=YELLOW, radius=0.1).set_z_index(10)
        tangent = d.call(
            lambda center, m: Line(LEFT, RIGHT, color=ORANGE, stroke_width=5)
            .set_length(2.0)
            .rotate(np.arctan(m))
            .move_to(center),
            point,
            slope,
        )
        guide = d.call(
            lambda x_value, center: DashedLine(
                axes.c2p(x_value, 0),
                center,
                color=GREY_B,
                stroke_width=2,
            ),
            x,
            point,
        )

        value = DecimalNumber(num_decimal_places=2).scale(0.65).set_z_index(10)
        value.d.set_value(y).d.next_to(dot, UP, buff=0.2)

        self.add(axes, curve, guide, tangent, dot, value)
        self.play(x.animate_to(PI), run_time=5)
        self.play(x.animate_to(-PI / 2), run_time=3)
        self.wait()
```

Run it:

```bash
manim -pql quickstart.py Quickstart
```

## What Happened?

- `x = self.state(-PI)` creates the source value.
- `lift(...)` creates computed values: `y`, `slope`, and `point`.
- `d.Dot(point, ...)` creates a Manim dot that follows the computed point.
- `d.call(...)` builds custom reactive geometry from state.
- `value.d.set_value(y).d.next_to(dot, UP)` keeps a normal Manim object connected to reactive values and another mobject.
- `x.animate_to(...)` uses Manim animation timing while Stateflow refreshes the dependent objects.

## Next Steps

- Learn the core pattern in [Guide](guide.md).
- Browse runnable scenes in the [example catalog](../README.md#all-examples).
- See the API surface in [Reference](reference.md).
