# Lava

> A lava lamp for any box: thick 3D wax glowing in a dark liquid, shot through a long lens.

Source: https://cesarvenzac.com/lava

Package: [@cesarvenzac/lava](https://www.npmjs.com/package/@cesarvenzac/lava) 0.1.0 on npm, MIT licence. Source code: https://github.com/cesarvenzac/lava

```sh
npm install @cesarvenzac/lava
```

*Live example on the page: A lava lamp. Wax rising from a pool on the bulb, drawing a thick neck out of it that parts, then drifting up as the light leaves it and sinking back. Pick its colours below.* Its source:

```tsx
// A lava lamp filling its box: give it a size. The same seed lays
// out the same lamp; it moves only on screen, and holds still under
// reduced motion.
import { Lava } from "@cesarvenzac/lava/react";

<Lava palette="amber" style={{ height: 432 }} />
// amber, magenta, ember, acid, violet; or colours of your own,
// var(--…) included:
<Lava colours={{ wax: "var(--brand)", liquid: "#120a1c" }} />
// Behind content, it's that content's background:
<Lava className="hero">
  <h1>Hello</h1>
</Lava>
```

Lava fills any box with a lava lamp: thick wax glowing in a dark liquid, rising from a pool lying on the bulb and sinking back to it. It's real 3D, lit from below, shot through a long lens with a shallow focus, its light blooming, then graded as film, so it reads as a photograph of a lamp rather than a pattern.

## Use

```tsx
import { Lava } from "@cesarvenzac/lava/react";

<Lava palette="magenta" style={{ height: 480 }} />;
```

Or without React:

```typescript
import { lava } from "@cesarvenzac/lava";

lava(element, { palette: "magenta" });
```

## Playground

*Live example on the page: Playground. Every option that changes how it looks, beside the code that makes what's shown.* Its source:

```tsx
// Every option that changes how it looks, and the code under the
// lamp is what makes it: copy it as it is.
import { Lava } from "@cesarvenzac/lava/react";

<Lava
  palette="magenta" // amber, magenta, ember, acid, violet
  seed="plume"      // the same seed, the same lamp
  speed={1.5}       // a lamp's own pace is 1
  size={1.2}
  pool={0.18}       // the pool on the bulb; 0 for none
  glow={1.3}        // how brightly the bulb lights the wax
  bloom={0.8}
  gloss={1}
  aperture={1.2}    // how shallow the focus is; 0 for all sharp
  focus={0.1}       // nearer above 0, further below
  haze={1}          // wax further back sinks into the liquid
  grain={0.5}
  style={{ height: 480 }}
/>
```

## What it does

- **Thick wax.** A blob rising from the pool draws a thick neck out of it, which heaves the pool up under it, thins to a waist and parts while still thick. Its halves ooze back, one into the blob, one into the pool. Nothing bounces or rings.
- **Real 3D.** Each blob is solid, stretched along its climb with a lobe trailing it, run together with another only where they touch, passing in front of and behind the others.
- **Lit from the bulb.** Each point of wax is lit by what reaches it through the wax beneath: undersides glow, tops fall into shade, thin wax glows toward its hot colour, and a soft light leaves a glossy highlight.
- **A lens.** Wax in front of and behind the focus blurs as a macro lens draws it, wax further back sinks into the liquid, the brightest light blooms, and the picture is graded as film.
- **Five lamps, or yours.** Amber, magenta, ember, acid and violet, each a wax on a dark liquid; or any colours of your own, your page's `var(--…)` included.
- **Seeded.** The same seed lays out the same lamp, and any moment can be drawn on its own.
- **Any box.** Sizes follow the box's shorter side and the number of blobs its shape: a banner, a card and a tall column each get a lamp in proportion. Content inside is drawn over it.
- **Well behaved.** It moves only on screen, holds still under reduced motion, is drawn smaller if frames come slowly, and shows the liquid lit from below until it's drawn, on a server too.
- **Small and plain.** TypeScript with no dependencies, one WebGL 2 render.

## Docs

- [Getting started](https://cesarvenzac.com/lava/docs/getting-started.md): Install Lava and fill a box with a lava lamp: in React, or in any element, alone or behind content.
- [Colours and light](https://cesarvenzac.com/lava/docs/colours-and-light.md): The five palettes, colours of your own, and the light and lens a lamp is drawn with.
- [Motion and the page](https://cesarvenzac.com/lava/docs/motion-and-the-page.md): How the wax moves, any moment drawn on its own, and how a lamp behaves on a page.
- [API reference](https://cesarvenzac.com/lava/docs/api.md): Every function, option and type Lava exports.
