# Point light

> usePointLight is a bulb: it has a place and fades with distance. Sweeping past a row of cubes, each one brightens and dims.

Example `point-light-3d`, running at https://nacatamalon.com/en/examples/point-light-3d. The whole catalogue: https://nacatamalon.com/llms/examples.md.

`usePointLight` is a bulb: it has a place in the world and falls off with distance (`range`), radiating in every direction, unlike the parallel rays of `useDirectionalLight`, which have no place.

Here it sweeps past a row of cubes, brightening each one as it passes close and dimming it as it moves away.

## Code

`index.ts`:

```ts
import { createGame } from 'nacatamalon';
import { WIDTH, HEIGHT } from './settings';
import { Scene } from './scenes/demo';

const game = createGame('#app', {
    width: WIDTH,
    height: HEIGHT,
    background: '#0a0a18',
});

// Declare Scenes
game({
    Scene
});
```

`components/cubes.ts`:

```ts
import { createMesh, useCubeGeometry } from 'nacatamalon';

export const Cubes = () => {
    const cube = useCubeGeometry();

    for (let i = -2; i <= 2; i++) {
        createMesh({
            geometry: cube,
            transform: {
                x: i * 1.6
            },
            tint: '#e8e8f0'
        });
    }
};
```

`scenes/demo.ts`:

```ts
import { createScene, useCamera3d, usePointLight, useUpdate, useSpawn } from 'nacatamalon';
import * as Settings from '../settings';

import { Cubes } from '../components/cubes';

export const Scene = () => {
    useCamera3d(Settings.CAMERA);

    // Each light has its own transform, independent of the camera and meshes.
    const light = usePointLight({
        transform: {
            x: 0,
            y: 0,
            z: 2
        },
        color: '#88ccff',
        intensity: 1.4,
        ambient: 0.05,
        range: 4,
    });

    useUpdate((_dt, time) => {
        const angle = time * Settings.ORBIT.speed;

        light.transform.x = Math.cos(angle) * Settings.ORBIT.x;
        light.transform.z = Math.sin(angle) * Settings.ORBIT.z;
    });

    useSpawn(Cubes)();

    return createScene();
};
```

`settings.ts`:

```ts
export const WIDTH = 480;
export const HEIGHT = 320;
import type { TCamera3dOptions } from 'nacatamalon';

export const CAMERA = {
    projection: 'perspective',
    fov: 55,
    near: 0.1,
    far: 100,
    transform: {
        z: 6
    }
} satisfies TCamera3dOptions;
export const ORBIT = {
    speed: 0.6,
    x: 4,
    z: 2
};
```
