# Tutorial 175: Looping Noise()

## Joe Clay | May 10, 2019

In this week's After Effects tutorial, we take a look at looping elements. This was inspired by Daniel Shiffman's Coding Challenge #136.1 on his excellent YouTube channel Coding Train. Coding Train is an excellent resource for coding visual art. A lot of the topics he covers can be repurposed in After Effects. Since he tackles algorithms frequently, it's also a good way to learn more deeply about the tools we use every day. For example, he has a few videos on Perlin noise, which underpins a lot of the plugins you probably use every day, like Fractal Noise.

### Expression Code

Note that all of these require slider controls. You can see which ones you need to make assigned to variables in the following expressions.

This goes in a path property so you can draw a polygon.

``````seed = effect("Seed")("Slider");
s = effect("Noise Scale")("Slider");
v = effect("Variance")("Slider")/100;
x = Math.cos(a) * s + seed;
y = Math.sin(a) * s + seed;
angles = new Array();
pts = new Array();
for(i = 0; i < 4; i++)
{
n = noise([x + (i*v),y + (i*v)]);
a = linear(n, -1.25,1.25,-1,1) * 360;
if (a < 0) {
a = 360 + a;
}
angles.push(a);
}

angles.sort(function(a, b){ return a - b });

for(i = 0; i < angles.length; i++)
{
ptX = Math.cos(a) * 300;
ptY = Math.sin(a) * 300;
pts.push([ptX, ptY]);
}
createPath(pts);``````

All of the text layers have something like this to repeat characters. If you put a few characters in and add a carriage return, it'll duplicate lines and the carriage returns.

``text.sourceText.repeat(23);``

This is the expression used on text where we don't care if the first and last characters loop together. Apply this to an expression selector in a text animator.

``````v = effect("Variance")("Slider")/100;
a = degreesToRadians(effect("Evolution")("Angle") + (textIndex * v));
s = effect("Noise Scale")("Slider");
x = Math.cos(a) * s;
y = Math.sin(a) * s;
noise([x, y]) * 100;``````

This is the expression used on characters that need to loop first and last characters—around a circular path for example. Apply this to an expression selector in a text animator.

``````seed = effect("Seed")("Slider");
a = degreesToRadians(textIndex/textTotal * 360 + effect("Evolution")("Angle"));
s = effect("Noise Scale")("Slider");
x = Math.cos(a) * s + seed;
y = Math.sin(a) * s + seed;
noise([x, y]) * 100;``````

## Grab the Project Files

The best way to get our project files is to become a patron on Patreon. For \$5 a month, you get access to all of the tutorial project files we've made available as well as other monthly projects, rigs, R&D, elements, early product previews, and BTS content not available anywhere else! You can also purchase just this project file on our Gumroad Store if you would rather do that.

or