Using noise to create looping GIFs on Processing
- José Lozano
- Apr 10, 2020
- 4 min read
In this tutorial I'll explain how to use noise functions in Processing to create animations with random-like movements that loop well.
It will explain how to obtain the following GIF with this animation technique:

So, first we'll build our base, which will look like this:

Here's the base, I added grey squares so it's easier to understand. Basically, we go through the grid and draw a '\' on each square.
Here's the code for it:
float n = 30;
float side;
void setup() {
size(500, 500);
noFill();
side = width/n;
}
void draw() {
background(0);
for(int y=0;y<n;y++) {
for(int x=0;x<n;x++) {
stroke(255);
line(x*side, y*side, (x+1)*side, (y+1)*side);
}
}
}
The next step is to make a circle in the center, like this:

It's not a perfect circle, I know, but it's good enough for us as a base. We're basically going through our grid and checking if the line we're at is close to the center. If it's close enough it'll draw '\'; otherwise '/' will be drawn.
Here's the code for it:
float n = 30;
float side;
float radius = 150;
void setup() {
size(500, 500);
noFill();
side = width/n;
}
void draw() {
background(0);
for(int y=0;y<n;y++) {
for(int x=0;x<n;x++) {
stroke(255);
if(dist(x*side, y*side, width/2, height/2) < radius) {
line(x*side, y*side, (x+1)*side, (y+1)*side);
} else {
line((x+1)*side, y*side, x*side, (y+1)*side);
}
}
}
}
Good, now we're looking for a blob kind of shape, and we'll use noise for that. However, Processing's noise function only goes as far as 3D, but we need 4D noise to make a looping animation. openSimplex noise fixes this issue for us. To use it paste this code in another tab of your Processing sketch.
openSimplex noise is similar to Perlin noise (used in Processing) but returns values between -1 and 1 instead of 0 and 1;
This is what we're going for:

We're getting there now. But what's going on here? We're using each line's coordinates to generate a new value for the distance treshold using openSimplex noise. Why do we need 4D noise? If we only used 2D noise we'd get a static image; with 3D noise we could make a "yo-yo" GIF, but 4D gives more of a random impression that also loops well.
Here's the code so far:
OpenSimplexNoise noise = new OpenSimplexNoise();
float t;
int numFrames = 120;
boolean recording = false;
float n = 30;
float side;
float noiseRadius = 2;
void setup() {
size(500, 500);
noFill();
side = width/n;
}
void draw() {
background(0);
t = map(frameCount-1, 0, numFrames, 0, 1);
for(int y=0;y<n;y++) {
for(int x=0;x<n;x++) {
stroke(255);
radius = 100*(float)noise.eval(x*side*0.01, y*side*0.01, noiseRadius*cos(TWO_PI*t), noiseRadius*sin(TWO_PI*t))+100;
if(dist(x*side, y*side, width/2, height/2) < radius) {
line(x*side, y*side, (x+1)*side, (y+1)*side);
} else {
line((x+1)*side, y*side, x*side, (y+1)*side);
}
}
}
if(recording) {
saveFrame("###.png");
if(frameCount==numFrames)
exit();
}
}
Here we're introducing a couple new variables: noise is the openSimplex instance we'll use to generate noise; numFrames dictates how many frames will be captured; recording tells the program whether to save the frames; noiseRadius tells openSimplex how big the radius of the circle we're picking our values from is; and t is a variable that helps us time the loop, it goes from 0 at the beginning of the animation (when frameCount = 1) to 1 at the end of it (when frameCount = numFrames). For now, recording should be disabled, we'll get to it later.
The key line here is
radius = 100*(float)noise.eval(x*side*0.01, y*side*0.01, noiseRadius*cos(TWO_PI*t), noiseRadius*sin(TWO_PI*t))+100;
openSimplex noise returns a value between -1 and 1, so we multiply that by 100 to get a bigger effect. We dont need negative values, so we also add 100 at the end. The first two parameters are the x and y coordinates of the line, and the last two just loop around the noise map in a circle to pull out the values so that the last frame matches the beginning. We multiply the x and y coordinates by 0.01 to 'reduce randomness'. The higher this is, the less continuous the values will be.
Almost there, now we just need to allow our blob to wander around the canvas a bit, so it looks like this instead of being anchored to the center:

To get this movement we have to change the following line:
if(dist(x*side, y*side, width/2, height/2) < radius) {
In this line we check if the line's coordinates are within a radius of the center, but now we don't want to have a fixed point, for this we need new coordinates for our blob, so we declare 2 new variables 'xb' and 'yb' (b for blob). To generate values for each coordinate we'll be using openSimplex noise again. You could use Perlin noise for this one as each coordinate only needs 3 dimensions, but I'll use openSimplex noise again for consistency.
Here's the code:
OpenSimplexNoise noise = new OpenSimplexNoise();
float t;
int numFrames = 360;
boolean recording = false;
float n = 30;
float side;
float radius = 150;
float noiseRadius = 2;
float xb, yb;
void setup() {
size(500, 500);
noFill();
side = width/n;
}
void draw() {
background(0);
t = map(frameCount-1, 0, numFrames, 0, 1);
xb = width/2*(float)noise.eval(0, noiseRadius*cos(TWO_PI*t), noiseRadius*sin(TWO_PI*t))+width/2;
yb = height/2*(float)noise.eval(10000, noiseRadius*cos(TWO_PI*t), noiseRadius*sin(TWO_PI*t))+height/2;
for(int y=0;y<n;y++) {
for(int x=0;x<n;x++) {
stroke(255);
radius = 100*(float)noise.eval(x*side*0.01, y*side*0.01, noiseRadius*cos(TWO_PI*t), noiseRadius*sin(TWO_PI*t))+100;
if(dist(x*side, y*side, xb, yb) < radius) {
line(x*side, y*side, (x+1)*side, (y+1)*side);
} else {
line((x+1)*side, y*side, x*side, (y+1)*side);
}
}
}
if(recording) {
saveFrame("###.png");
if(frameCount==numFrames)
exit();
}
}
The key lines here are:
xb = width/2*(float)noise.eval(0, noiseRadius*cos(TWO_PI*t), noiseRadius*sin(TWO_PI*t))+width/2;
yb = height/2*(float)noise.eval(10000, noiseRadius*cos(TWO_PI*t), noiseRadius*sin(TWO_PI*t))+height/2;
and
if(dist(x*side, y*side, xb, yb) < radius) {
To generate the new coordinates we're using very similar instructions, the only difference being the first parameter. This would be called the "seed" of the random map we're generating. Ideally you should use different values here, otherwise you'd get the same value for x and y. The result would be a blob that only moves across a diagonal instead of wandering around.
Great! Now we have the animation, but we have to export it to a GIF somehow. When the variable "recording" is set to true, Processing will save each frame of the sketch as a .png file, so you need a tool to compile all those png's to a GIF. For this I use FFmpeg, although you could also use GIMP or any other tool you feel comfortable with.
If you decide to use FFmpeg, browse to the sketch's folder using the command line and use this command:
ffmpeg -i "%03d.png" output.gif
Et voilà! The GIF should now be in the sketch's folder :)
Share your experiments on #generativehut
My name is José Lozano and I'm a computer science student living in Germany.
You can see all my work on Instagram: @urbanoxygen_
As someone working with Khelraja, I always look forward to sharing the Play India lottery result with our players. The moment of announcing winners is magical—it’s when dreams meet reality. I enjoy being part of this journey, where anticipation turns into celebration. At Khelraja, we focus on transparent systems, so every player feels the thrill with confidence. For me, delivering results isn’t just about numbers; it’s about telling stories of hope and success. Being part of these moments inspires me to keep building exciting opportunities for people who believe in their lucky chance.
Online Forex Trading India Online Forex Trading in India allows traders to participate in the global currency market through digital platforms while following Indian regulatory guidelines. Conducted via SEBI-registered brokers and recognized exchanges like NSE, BSE, and MCX-SX, it permits trading in approved currency pairs such as USD/INR, EUR/INR, GBP/INR, and JPY/INR. With advancements in technology, traders can now access real-time market data, advanced charting tools, and mobile trading apps, making it easier than ever to analyze trends and execute trades. While the Reserve Bank of India (RBI) maintains strict rules to ensure legal and safe transactions, online forex trading continues to grow in popularity, offering Indian traders a secure and convenient way to explore global currency opportunities from the comfort…
Online Forex Trading India Online Forex Trading in India allows traders to participate in the global currency market through digital platforms while following Indian regulatory guidelines. Conducted via SEBI-registered brokers and recognized exchanges like NSE, BSE, and MCX-SX, it permits trading in approved currency pairs such as USD/INR, EUR/INR, GBP/INR, and JPY/INR. With advancements in technology, traders can now access real-time market data, advanced charting tools, and mobile trading apps, making it easier than ever to analyze trends and execute trades. While the Reserve Bank of India (RBI) maintains strict rules to ensure legal and safe transactions, online forex trading continues to grow in popularity, offering Indian traders a secure and convenient way to explore global currency opportunities from the comfort…
Unlock your Free Funded Forex Account with WinProFX and start your trading journey without risking your own capital. WinProFX provides aspiring traders with a unique opportunity to access live trading funds, allowing you to trade in the global forex market and keep a share of the profits you earn. This program is designed to support both beginners and experienced traders by removing the financial barriers to entry and offering the tools, resources, and real market experience needed for success. With advanced trading platforms, dedicated support, and real-time market analysis, WinProFX ensures you have everything you need to grow your skills and achieve your trading goals.
Contact us Address – 1st Floor, The Sotheby Building, Rodney Bay, Gros-Islet, SAINT Lucia P.O Box 838,…
When it comes to achieving consistent success in the forex market, choosing the Best Forex Trading Platform is the first and most important step, and that’s where Winprofx stands out as a trusted partner for traders in 2025. Designed for both beginners and experienced professionals, Winprofx combines advanced trading tools, real-time market insights, and a user-friendly interface to ensure every trade is executed with precision and efficiency. With its lightning-fast execution speeds, low spreads, and a wide range of currency pairs, the platform allows traders to take advantage of even the smallest market movements. What sets Winprofx apart is its focus on trader education, offering detailed guides, webinars, and market analysis so users can sharpen their strategies and make informed decisions.…