---
agentTools:
  projectIndex: https://whsjs.readme.io/llms.txt
---

# Loops & 3D Animation

You don't need to write `animate()` function like you do in Three.js. The problem is that bigger you app become, the bigger your `animate()` function is.

Here comes `WHS.Loop` class. With just a few lines of code you can your own mini-animate() function:

[block:code]
{
  "codes": [
    {
      "code": "const app = new WHS.App([\n  // ...\n]);\n\nnew WHS.Loop(() => {\n  box.rotation.y += 0.02;\n}).start(app);",
      "language": "javascript"
    }
  ]
}
[/block]

<img src="http://i.imgur.com/v7OaN9h.gif">

And you can make loop temporary like that:

[block:code]
{
  "codes": [
    {
      "code": "const loop = new WHS.Loop((clock) => {\n  // ...\n  if (clock.getElapsedTime() > 5) loop.stop(app);\n});\n\nloop.start(app);",
      "language": "javascript"
    }
  ]
}
[/block]

This loop will be destroyed after 5 seconds.