# Python perlin noise loop help

**URL:** <https://discourse.processing.org/t/python-perlin-noise-loop-help/28879>\
**Category:** Processing.py\
**Created:** [March 26, 2021, 4:55pm UTC](https://discourse.processing.org/t/python-perlin-noise-loop-help/28879 "2021-03-26T16:55:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laygos](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@Laygos](https://discourse.processing.org/u/Laygos)\
**Post date:** [March 26, 2021, 4:55pm UTC](https://discourse.processing.org/t/python-perlin-noise-loop-help/28879/1 "2021-03-26T16:55:21Z")

</div>

Hi! I’m unable to get my loop to loop 😓 I was following the video bellow:

[![](https://img.youtube.com/vi/ZI1dmHv3MeM/maxresdefault.jpg "Coding Challenge #136.1: Polar Perlin Noise Loops") ](https://www.youtube.com/watch?v=ZI1dmHv3MeM&t=751s)

the code I followed is shown roughly around the 12 min mark.

```auto
def setup():
    size(900,900)

def draw():
    background(0)
    translate(width/2,height/2)
    stroke(255)
    noFill()
    beginShape()
    a = 0
    while a < TWO_PI:
        a += 0.01
        xoff = cos(a) + 1
        yoff = sin(a) + 1
        x = map(noise(xoff,yoff),0,1,100,200) * cos(a)
        y = map(noise(xoff,yoff),0,1,100,200) * sin(a)
        vertex(x,y)
        
    endShape()

```

If anybody could explain what my mistake is, that’d be greatly appreciated!

Thanks!🙏

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [March 26, 2021, 6:05pm UTC](https://discourse.processing.org/t/python-perlin-noise-loop-help/28879/2 "2021-03-26T18:05:56Z")

</div>

> [@Laygos](#):
>
> If anybody could explain what my mistake is,

Each time your **draw()** repeats the values inside it are always the same.

So nothing is animated, just a static image.

However Processing got a global system variable called _frameCount_ which represents how many times **draw()** has been called back:

> **[frameCount \\ Language (API)](https://py.processing.org/reference/frameCount.html)**
>
> Python Mode for Processing extends the Processing Development Environment with the Python programming language.

I’ve adapted this Java Mode version to Python Mode to use _frameCount_ for the variables inside **draw()**:

> <https://github.com/CodingTrain/website-archive/blob/main/CodingChallenges/CC_136_Polar_Noise_Loop_1/Processing/CC_136_Polar_Noise_Loop_1/CC_136_Polar_Noise_Loop_1.pde>

```auto
# https://Discourse.Processing.org/t/python-perlin-noise-loop-help/28879/2
# Mod by GoToLoop (2021/Mar/26)

def setup():
    size(400, 400)
    stroke(-1)
    strokeWeight(2)
    noFill()

def draw(a = 0, INC = 5 * DEG_TO_RAD, PHASE = .003, ZOFF = .01, XOFF = 100):
    cx = width >> 1
    cy = height >> 1

    cyOff = cy - XOFF

    phase = frameCount * PHASE
    zoff = frameCount * ZOFF

    noiseMax = map(mouseX, 0, width, 1, 5)

    clear()
    translate(cx, cy)

    with beginClosedShape():
        while a < TAU:
            xoff = map(cos(a + phase), -1, 1, 0, noiseMax)
            yoff = map(sin(a + phase), -1, 1, 0, noiseMax)

            r = noise(xoff, yoff, zoff) * XOFF + cyOff

            x = r * cos(a)
            y = r * sin(a)

            a += INC

            vertex(x, y)

```

---

<div class="post-metadata">

**Author:** ![Laygos](https://avatars.discourse-cdn.com/v4/letter/l/e36b37/32.png) [@Laygos](https://discourse.processing.org/u/Laygos)\
**Post date:** [March 26, 2021, 8:42pm UTC](https://discourse.processing.org/t/python-perlin-noise-loop-help/28879/3 "2021-03-26T20:42:21Z")

</div>

WOW! You’re a legend! 🙏 Thanks so much for the resource and for helping me understand what was wrong with my code. 🙏
