# A cube

> A model is a shape, a place and a surface. The light is worked out at the corners and smeared across each face, as the consoles of the era did.

Example `cube`, running at https://nacatamalon.com/en/examples/cube. The whole catalogue: https://nacatamalon.com/llms/examples.md.

A model is a **shape**, a **place** and a **surface**. `useCubeGeometry` builds the shape and shares it; `createMesh` puts one somewhere, the way `createSprite` does with a picture.

The light is worked out **at the corners** and smeared across each face in between, which is what the consoles of this era did: none of them lit per pixel. Watch the faces shade differently as it turns, and note there is no texture on it at all.

## Code

`index.ts`:

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

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

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

`components/spinning_cube.ts`:

```ts
import { createMesh, useCubeGeometry, useUpdate } from 'nacatamalon';
import { SPIN } from '../settings';

export const SpinningCube = () => {
    // Geometry is shared; this mesh owns its own surface and placement.
    const cube = createMesh({
        geometry: useCubeGeometry(),
        tint: '#4cff91'
    });

    useUpdate((delta) => {
        cube.transform.rotationX += delta * SPIN.x;
        cube.transform.rotationY += delta * SPIN.y;
    });
};
```

`scenes/demo.ts`:

```ts
import { createScene, useCamera3d, useDirectionalLight, useSpawn } from 'nacatamalon';
import { SpinningCube } from '../components/spinning_cube';

export const Level = () => {
    useCamera3d({
        projection: 'perspective',
        fov: 60,
        transform: {
            z: 4
        }
    });
    useDirectionalLight({
        intensity: 1
    });
    useSpawn(SpinningCube)();

    return createScene();
};
```

`settings.ts`:

```ts
export const WIDTH = 480;
export const HEIGHT = 320;

export const SPIN = {
    x: 0.6,
    y: 0.9
};
```
