# Transform

> Position, rotation and scale on the sprite's transform. Rotation and scale pivot on its centre, so it spins where it stands.

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

Position, rotation and scale live on the sprite's `transform`, and you change them by writing its fields. Rotation and scale pivot around the sprite's centre, which is also the point `x` and `y` place, so the logo spins and pulses in place while it drifts instead of swinging around a corner.

## Code

`index.ts`:

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

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

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

`components/animated_logo.ts`:

```ts
import { createSprite, useLoadTexture, useUpdate } from 'nacatamalon';
import { WIDTH, HEIGHT, LOGO } from '../settings';

export const AnimatedLogo = () => {
    const logo = createSprite({
        texture: useLoadTexture({
            src: '/example-assets/assets/gammix.png'
        }),
        width: LOGO.size,
        height: LOGO.size,
        transform: {
            x: WIDTH / 2,
            y: HEIGHT / 2
        }
    });

    useUpdate((delta, time) => {
        // Angles are radians. The scene clock drives both oscillations without a local timer.
        logo.transform.rotation += LOGO.turnSpeed * delta;

        const pulse = 1 + Math.sin(time * LOGO.pulseSpeed) * LOGO.pulseAmount;

        logo.transform.scaleX = pulse;
        logo.transform.scaleY = pulse;
        logo.transform.x = WIDTH / 2 + Math.sin(time) * LOGO.drift;
    });
};
```

`scenes/demo.ts`:

```ts
import { createScene, useSpawn } from 'nacatamalon';
import { AnimatedLogo } from '../components/animated_logo';

export const Game = () => {
    useSpawn(AnimatedLogo)();

    return createScene();
};
```

`settings.ts`:

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

export const LOGO = {
    size: 96,
    turnSpeed: 1.5,
    pulseSpeed: 3,
    pulseAmount: 0.3,
    drift: 90
};
```
