---
title: "Randomize the start frame of three.js flipbook sprites"
description: "Randomize the start frame of many three.js flipbook sprites: one texture clone each, a random offset in userData, and frame = floor(t * fps + offset) % 64."
canonical: https://appliedmanifold.com/guides/threejs-random-start-frame/
site: "Applied Manifold: The spatial compute cloud for 3D reality"
---

1.  [Home](https://appliedmanifold.com/)
2.  [Guides](https://appliedmanifold.com/guides/)
3.  Random start frame

GUIDE // THREE.JS

# How to randomize the starting frame of many three.js flipbook particles

Give each of your sprites its own clone of the texture and a random offset between 0 and the frame count, then compute its frame as the time times the frame rate plus that offset, rounded down and wrapped. Clones share one image, and every sprite plays the same loop out of step with its neighbors.

[Get Free API Key](https://console.appliedmanifold.com/sign-in?next=/api-keys) [See the examples →](https://appliedmanifold.com/docs/pyrofx/examples/)

-   Godot 4 Available
-   Unity Manual setup
-   Unreal Engine Manual setup
-   Roblox Studio Manual setup
-   **three.js** Available

A draft compile is from $0.05, and new accounts start with $5 of usage.

**SMOKE\_PLUMEFINAL**

![First frame of the smoke\_plume bake](/bakes/smoke_plume/poster.webp)

Smoke plume, 7.0 x 10.8 m, compiled with Spatial Compiler. [Spec →](https://appliedmanifold.com/docs/pyrofx/examples/#ex-smoke_plume)

01 // HOW TO

## Start six smoke plumes on different frames

1.  Load the smoke sheet once with `loadAsync`.
2.  For each plume, clone the texture, set its repeat to 1/8 by 1/8 and make a sprite with it.
3.  Store a random offset in `sprite.userData`, from 0 up to 64.
4.  Each tick, add the offset to the time-based frame before wrapping with `% 64`.

plumes.js

```
import * as THREE from 'three';

const FPS = 16;    // smoke plume: 64 frames over 4 s
const FRAMES = 64;
const base = await new THREE.TextureLoader().loadAsync('/fx/smoke_rgba.png');
base.colorSpace = THREE.SRGBColorSpace;
const plumes = [];

for (let i = 0; i < 6; i++) {
  const map = base.clone();
  map.needsUpdate = true;
  map.repeat.set(1 / 8, 1 / 8);
  const sprite = new THREE.Sprite(new THREE.SpriteMaterial({ map, transparent: true, depthWrite: false }));
  sprite.position.set(i * 8, 5, 0);
  sprite.scale.set(10, 10, 1);
  sprite.userData.offset = Math.random() * FRAMES;
  scene.add(sprite);
  plumes.push(sprite);
}

const clock = new THREE.Clock();
renderer.setAnimationLoop(() => {
  const t = clock.getElapsedTime();
  for (const sprite of plumes) {
    const frame = Math.floor(t * FPS + sprite.userData.offset) % FRAMES;
    sprite.material.map.offset.set((frame % 8) / 8, 1 - (Math.floor(frame / 8) + 1) / 8);
  }
  renderer.render(scene, camera);
});
```

02 // REAL OUTPUT

## Fire on random frames

Set the rate to 32 for the 2 s fire, and a few copies on random frames read as one wide blaze.

**FIREFINAL**

![First frame of the fire bake](/bakes/fire/poster.webp)

Fire, 4.1 x 7.0 m, compiled with Spatial Compiler. [Spec →](https://appliedmanifold.com/docs/pyrofx/examples/#ex-fire)

03 // AT SCALE

## Hundreds of particles

One sprite per plume is fine for dozens. For hundreds, draw them all in one draw call: an `InstancedMesh` of planes with a `ShaderMaterial`, and the random offset stored per instance in an `InstancedBufferAttribute` that the shader adds to the frame. Every instance then reads the same texture with no clones at all.

Keep one-shot explosions on frame 0. A random start would skip their flash, so vary them with different compiles instead, such as the same explosion with a new seed.

Godot 4 gets a ready scene that relights the smoke. three.js uses the documented snippet. A native six-way material is not built yet.

04 // RELATED

## Related pages

-   [Random start frame Godot 4Use Animation Offset and Particles Anim Loop in Godot 4 so each particle starts its flipbook on a different frame.](https://appliedmanifold.com/guides/godot-random-flipbook-start-frame/)
-   [Random start frame Unreal EngineGive Niagara flipbook particles a random start frame with a spawn-time offset and a wrapped Sub Image Index expression.](https://appliedmanifold.com/guides/unreal-random-start-frame/)
-   [Loop a sprite animation three.jsLoop a fire or smoke sprite sheet in three.js from elapsed time, so it plays at the same speed on every screen.](https://appliedmanifold.com/guides/threejs-loop-sprite-animation/)
-   [three.js smoke plume three.jsA smoke plume that leans with the wind and loops every 4 seconds, played in three.js with a documented snippet.](https://appliedmanifold.com/effects/threejs-smoke-plume/)
-   [three.js VFX three.jsFire, smoke, explosion and dust effects in three.js: sprite sheets you play with a documented snippet, next to Godot 4's ready scene.](https://appliedmanifold.com/effects/threejs-vfx/)
-   [Particle systemA particle system spawns and updates many small sprites or meshes from an emitter to make sparks, smoke, rain and fire.](https://appliedmanifold.com/learn/particle-system/)
-   [OutputsWith the default export, each view writes four sheets, `<view>_pos.png`, `_neg.png`, `_colour.png` and `_aux.png`, plus `layout.json`, two still previews, the animated `preview_anim.png` and `bake_report.json`. Sheets are 8 x 8 tiles of 256 px by default.](https://appliedmanifold.com/docs/pyrofx/outputs/)

[All pages in Guides →](https://appliedmanifold.com/guides/)

[← Play an explosion once](https://appliedmanifold.com/guides/threejs-play-once/)[Additive fire →](https://appliedmanifold.com/guides/threejs-additive-fire/)

05 // FAQ

## three.js random start frame questions

[All questions →](https://appliedmanifold.com/faq/)

**README.THREEJS\_RANDOM\_START\_FRAME**

### How do I randomize the starting frame of several three.js fire sprites?

Give each sprite its own texture with texture.clone() and start its frame counter at a random integer from 0 to 63.

### How do I randomize the starting frame of several three.js smoke sprites?

Give each sprite its own texture with texture.clone() and start its frame counter at a random integer from 0 to 63.

### How do I calculate UV coordinates for a sprite sheet with rows and columns in three.js?

Set `texture.repeat` to `1/C` by `1/R`. Compute column `n % C` and row `Math.floor(n / C)`, then offset X by `column / C` and Y from the top.

### How do I organize different particle textures in an atlas?

Use a regular grid of equal cells with matching padding around every cell so your particle system can address each image by index.

## Compile your first effect

You pay per compile and see the price before it runs. New accounts start with $5 of usage.

[Get Free API Key](https://console.appliedmanifold.com/sign-in?next=/api-keys) [Outputs →](https://appliedmanifold.com/docs/pyrofx/outputs/)

[All effects, guides and explainers →](https://appliedmanifold.com/effects/)
