# Noise grid stops moving after a while

**URL:** <https://discourse.processing.org/t/noise-grid-stops-moving-after-a-while/11704>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [May 30, 2019, 8:11am UTC](https://discourse.processing.org/t/noise-grid-stops-moving-after-a-while/11704 "2019-05-30T08:11:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![madsogstrup](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@madsogstrup](https://discourse.processing.org/u/madsogstrup)\
**Post date:** [May 30, 2019, 8:11am UTC](https://discourse.processing.org/t/noise-grid-stops-moving-after-a-while/11704/1 "2019-05-30T08:11:09Z")

</div>

Hello!

I have this code that is doing what i want. But i would like for it to keep “animating” in eternity.  
I think i know why i stops, but I don’t know how to explain it properly or do anything about it. 🙂

Is there any way to keep it going?

Thanks in advance!

- Mads

```auto
float gridcelleStr =8; 
float gridBredde;
float gridHoejde;
float faktor = 2;
float fart;
float xPos; 
float yPos; 
float tal; 
float strFaktor = 30;

void setup() {
  size(1200, 1200, P3D);
  gridBredde = floor(120);
  gridHoejde = floor(120);
  fart = 0;
  rectMode(CENTER);
  imageMode(CENTER);
}
void draw() {
  background(255);
  for (int y = 0; y < gridHoejde; y++) {
    for (int x = 0; x <gridBredde; x++) {
      pushMatrix();
      translate(100, 80);
      fart += 0.0000002;
      tal = floor(noise(x/gridHoejde, y / gridBredde, fart) * faktor);
      xPos = x * gridcelleStr;
      yPos = y * gridcelleStr;
      noStroke();
      fill(random(0), random(0), random(150, 255));
      rect(xPos, yPos, tal * strFaktor, tal * strFaktor);
      popMatrix();
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [June 3, 2019, 12:16am UTC](https://discourse.processing.org/t/noise-grid-stops-moving-after-a-while/11704/2 "2019-06-03T00:16:34Z")

</div>

It does keep going, but it doesn’t keep displaying. Your problem is that you have global variables – in particular, speed (fart) – that you keep incrementing, until the number is so large your sketch doesn’t work anymore.

Try bouncing that value around between -1 and 1, for example:

```auto
float gridcelleStr =8; 
float gridBredde;
float gridHoejde;
float faktor = 2;
float fart;
float fart_diff = 0.0000002;
float xPos; 
float yPos; 
float tal; 
float strFaktor = 30;

void setup() {
  size(1200, 1200, P3D);
  gridBredde = floor(120);
  gridHoejde = floor(120);
  fart = 0;
  rectMode(CENTER);
  imageMode(CENTER);
}
void draw() {
  background(255);
  if (fart>1) {
    fart_diff = -0.0000002;
  }
  if (fart<-1) {
    fart_diff = 0.0000002;
  }
  for (int y = 0; y < gridHoejde; y++) {
    for (int x = 0; x <gridBredde; x++) {
      pushMatrix();
      translate(100, 80);
      fart += fart_diff;
      tal = floor(noise(x/gridHoejde, y / gridBredde, fart) * faktor);
      xPos = x * gridcelleStr;
      yPos = y * gridcelleStr;
      noStroke();
      fill(random(0), random(0), random(150, 255));
      rect(xPos, yPos, tal * strFaktor, tal * strFaktor);
      popMatrix();
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![8BitRift](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/8bitrift/32/3495_2.png) [@8BitRift](https://discourse.processing.org/u/8BitRift)\
**Post date:** [June 3, 2019, 3:04am UTC](https://discourse.processing.org/t/noise-grid-stops-moving-after-a-while/11704/3 "2019-06-03T03:04:35Z")

</div>

Eh close but not exactly, the variable fart only gets to 4.0 before it freezes, which wouldn’t even overflow a byte. The problem is computers are bad at adding really small decimals so adding 4.0+0.0000002 = 4.0 in Java land. So fart will just be 4.0 until the end of time and we will never advance through the noise any farther which causes it to appear to freeze.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [June 3, 2019, 5:16am UTC](https://discourse.processing.org/t/noise-grid-stops-moving-after-a-while/11704/4 "2019-06-03T05:16:13Z")

</div>

> [@jeremydouglass](#):
>
> until the number is so large your sketch doesn’t work anymore

> [@8BitRift](#):
>
> computers are bad at adding really small decimals

Yes, both these things are true. I never said it was an overflow–in fact, I gave a sketch with a demo range of +/-1.0 (!)

There are several ways around tiny float increments that freeze–but if you are trying for the smallest increment possible and don’t want reflection looping, one approach is:

```
 speed = Math.nextUp(speed);

```
