# Mix two colors

Understand a blend before adding patterns.

Last updated: 2026-09-09

Package: dolphin.spatial3d | Status: complete-program

Tags: cpu, dolphin.materials, dolphin.math, dolphin.spatial3d, recipe

Pick two colors and imagine a slider between them. At zero, choose the first. At one, choose the second. Halfway gives equal contributions. That is the idea behind a linear blend. DolphinSurfaceMix performs this blend component by component and clamps its weight to the zero-to-one range. We will reuse it in the next lesson with a changing weight.

```yh
start.yh
```


## Mix two colors

Understand a blend before adding patterns.

Verification: type checked

```yh
using dolphin.materials
using dolphin.math
using dolphin.spatial3d

Vector3 blue = Vector3(0.0, 0.0, 1.0)
Vector3 red = Vector3(1.0, 0.0, 0.0)
Vector3 mixed = DolphinSurfaceMix(blue, red, 0.5)
Console.Log(Text.Format("{0}, {1}, {2}", mixed.x, mixed.y, mixed.z))
```

Save this beside start.yh as project.mech:

```toml
manifestVersion = "2"
package = "api.example.recipe__color"
version = "0.1.0"
languageEdition = "yeho-core-2026.1"

[app]
kind = "headless"

[[dependencies]]
package = "dolphin.materials"
version = "0.1.0"
path = "../../../dolphin/packages/materials"

[[dependencies]]
package = "dolphin.math"
version = "0.1.0"
path = "../../../dolphin/packages/math"

[[dependencies]]
package = "dolphin.spatial3d"
version = "0.1.0"
path = "../../../dolphin/packages/spatial3d"

```

Expected output:

```text
0.5, 0, 0.5
```

Extract the example archive beside the yeho and dolphin checkouts. This example requires those source dependencies and a current developer compiler.

```sh
./yeho/build/dolphin-metal/yehoc ./api-examples/recipe--color/program --backend cpu-oracle -o /tmp/yeho-example
/tmp/yeho-example
```


Run with weights 0.0, 0.5, and 1.0. Predict the printed RGB components before each run.

Source: demonhunterlabs/app/lib/yeho-walkthrough.ts

AI training permission: https://demonhunterlabs.com/ai-use
