# 10. Particle galaxy with Points, explained

**Goal:** render tens of thousands of glowing dots efficiently and shape them into a spiral galaxy.

## Walkthrough

```js
const positions = new Float32Array(COUNT * 3);
const colors = new Float32Array(COUNT * 3);
```
Particles are just vertices. One `BufferGeometry` holds all 20,000 of them, and `THREE.Points` draws each vertex as a square sprite. It is one draw call no matter how many points.

```js
const armAngle = ((i % ARMS) / ARMS) * Math.PI * 2;
const twist = radius * 0.9;
```
Each particle belongs to one of four arms (`i % ARMS`). Adding an angle proportional to the radius twists straight arms into spirals.

```js
const spread = () => Math.pow(Math.random(), 3) * (Math.random() < 0.5 ? 1 : -1) * 0.6;
```
Raising a random number between 0 and 1 to the third power pushes most values toward 0, so particles crowd near the arm's center line and thin out at the edges. The random sign spreads them to both sides.

```js
const c = inner.clone().lerp(outer, radius / 6);
```
`lerp` blends two colors: orange at the core, blue at the rim.

```js
new THREE.PointsMaterial({
  size: 0.03,
  sizeAttenuation: true,
  vertexColors: true,
  depthWrite: false,
  blending: THREE.AdditiveBlending,
})
```
- `size` is in world units when `sizeAttenuation` is true (points shrink with distance), or in pixels when false.
- `AdditiveBlending` adds overlapping colors together, so dense regions glow brighter, the classic look for fire, stars and sparks.
- `depthWrite: false` prevents particles from hiding each other based on draw order, which otherwise causes dark square artifacts with transparent or additive particles.

## Points vs other techniques

| Technique | Good for | Limits |
| --- | --- | --- |
| `Points` + `PointsMaterial` | Stars, dust, point clouds (100k+ points) | Square sprites, size capped by the GPU, no per-point rotation |
| `Points` + `ShaderMaterial` | Custom shapes (circles, soft glows) and GPU animation | Write GLSL |
| `InstancedMesh` of small quads or meshes | Particles that need real 3D shape or lighting | More vertices per particle |
| `Sprite` | A few labels or icons facing the camera | One draw call each |

## Make round points

Points are squares by default. Two options:
1. Set `map` to a small circular texture (draw a radial gradient on a canvas, as in example 04) plus `transparent: true` and `alphaTest: 0.01`.
2. Use a `ShaderMaterial` and discard pixels outside a circle in the fragment shader with `gl_PointCoord`.

## Try this

1. Change `ARMS` to 2, 3 or 6, and the twist factor from 0.9 to 2.
2. Make particle size vary: add a `size` attribute and a small shader (see example 11).
3. Animate rotation cheaply by rotating the whole `galaxy` object instead of moving each point.
