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

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

```
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!

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:

Py.Processing.org/reference/frameCount.html

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

```
# 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)
```

6 Likes

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

2 Likes