# Primitives

> Eight shapes built in code rather than loaded: Blender's Add Mesh set minus the monkey.

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

Eight shapes built in code rather than loaded, which is Blender's **Add Mesh** set minus the monkey. Each one hands back the same kind of thing a loaded model will, so nothing downstream knows the difference.

They are kept under a name made from their size, so asking twice for the same size gives back the same shape. Look at the two balls: the globe-style one bunches its triangles at the poles and the other does not, which is why there are two.

## Code

`index.ts`:

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

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

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

`components/gallery.ts`:

```ts
import { createMesh, getColor, useCircleGeometry, useConeGeometry, useCubeGeometry, useCylinderGeometry, useIcoSphereGeometry, usePlaneGeometry, useTorusGeometry, useUpdate, useSphereGeometry } from 'nacatamalon';
import * as Settings from '../settings';

export const Gallery = () => {
    const shapes = [
        {
            geometry: usePlaneGeometry({
                width: 0.8,
                depth: 0.8
            }),
            color: '#f5c518'
        },
        {
            geometry: useCircleGeometry({
                segments: 12
            }),
            color: '#ff6b6b'
        },
        {
            geometry: useCubeGeometry({
                width: 0.7,
                height: 0.7,
                depth: 0.7
            }),
            color: '#4cff91'
        },
        {
            geometry: useSphereGeometry(),
            color: '#60a5fa'
        },
        {
            geometry: useIcoSphereGeometry({
                subdivisions: 1
            }),
            color: '#c084fc'
        },
        {
            geometry: useCylinderGeometry({
                radius: 0.35,
                height: 0.7
            }),
            color: '#ff9f43'
        },
        {
            geometry: useConeGeometry({
                radius: 0.4,
                height: 0.8,
                segments: 12
            }),
            color: '#22eeff'
        },
        {
            geometry: useTorusGeometry({
                radius: 0.3,
                tube: 0.12
            }),
            color: '#ff6b35'
        },
    ];

    shapes.forEach(({ geometry, color }, i) => {
        const model = createMesh({
            geometry,
            tint: getColor(color),
            transform: {
                x: ((i % 4) - 1.5) * Settings.SPACING,
                y: (0.5 - Math.floor(i / 4)) * Settings.SPACING
            },
        });

        useUpdate((delta) => {
            model.transform.rotationX += delta * Settings.TURN.x;
            model.transform.rotationY += delta * Settings.TURN.y;
        });
    });
};
```

`scenes/demo.ts`:

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

import { Gallery } from '../components/gallery';

export const Level = () => {
    useCamera3d(Settings.CAMERA);
    useDirectionalLight({
        intensity: 1.1
    });

    useSpawn(Gallery)();

    return createScene();
};
```

`settings.ts`:

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

export const CAMERA = {
    projection: 'perspective',
    fov: 50,
    transform: {
        z: 6
    }
} satisfies TCamera3dOptions;
export const SPACING = 1.4;
export const TURN = {
    x: 0.5,
    y: 0.7
};
```
