Date:2023-12-05

# How to create a Chladni Figure with Processing.

This article presents the formula and how to create a digital representation of the chladni plate (chladni figure) using Processing. The most classical way of visualizing and expressing sound. You can enjoy the various geometric patterns created by sound.

Chladni figures were devised by the German physicist Ernst Florens Friedrich Chladni in the 18th century.

The creation of these figures involves spreading fine particles on a fixed flat plate and vibrating it at specific frequencies, resulting in the emergence of beautiful geometric patterns.

Research on Chladni figures is utilized in various fields such as acoustic design of musical instruments, understanding resonance, visualization of vibrational phenomena, acoustical engineering, and physics education.

### case : barbe_generative_diary

## Formula: Chladni plate (2D)

The Chladni plate experiment involves fixing a plate at the edge or center and inducing vibrations using a violin bow or a speaker. By consistently sprinkling fine sand on the plate during the experiment, patterns are generated as particles gather in the areas of the plate’s surface that are not vibrating (nodes).

The equation for the nodes of standing waves on a square Chladni plate (side length L) constrained at the center is as follows:

**cos(n π x / L) cos(m π y / L) – cos(m π x / L) cos(n π y / L) = 0**

n, m (positive integers) = number of nodes on the plate

L = side length, x = position on the X-axis, y = position on the Y-axis

Note that when n = m, the lower half of the table is equal to the upper half, meaning (n1, m2) = (n2, m1).

## Processing code: Chladni plate (2D)

Below is a Chladni plate 2D code using Processing:

```
int xCount = 120;
int yCount = 120;
float n = 5;
float m = 3;
float randNM = 20;
Particle[] myParticles = new Particle[xCount*yCount];
void setup() {
size(1200,1200,P2D);
background(0);
smooth();
initParticle();
shuffle();
}
void draw() {
translate(width / 2, height / 2);
scale(1.0 * width/2, 1.0 * height/2);
background(0);
noFill();
stroke(255,180);
strokeWeight(0.003);
for (int i = 0; i < myParticles.length; i++) {
myParticles[i].update();
myParticles[i].display();
}
}
void shuffle() {
n = floor(random(randNM));
m = floor(random(randNM));
while (m == n) {
m = floor(random(randNM));
}
}
void initParticle() {
int i = 0;
for (int y = 0; y < yCount; y++) {
for (int x = 0; x < xCount; x++) {
myParticles[i] = new Particle();
i++;
}
}
}
class Particle extends PVector {
float x,y;
float speed;
Particle() {
x = random(-1, 1);
y = random(-1, 1);
speed = 0.035;
}
void update() {
float vibrationmax = 0.003;
float vibrationX = random(-vibrationmax, vibrationmax);
float vibrationY = random(-vibrationmax, vibrationmax);
float amount = chladni(x, y);
float randomNum = random(-0.2,0.5);
if (amount >= 0) {
if (chladni(x + vibrationmax, y) >= amount) {
x = constrain(x - randomNum * amount * speed + vibrationX, -1, 1);
} else {
x = constrain(x + randomNum * amount * speed + vibrationX, -1, 1);
}
if (chladni(x, y + vibrationmax) >= amount) {
y = constrain(y - randomNum * amount * speed + vibrationY, -1, 1);
} else {
y = constrain(y + randomNum * amount * speed + vibrationY, -1, 1);
}
} else {
if (chladni(x + vibrationmax, y) <= amount) {
x = constrain(x + randomNum * amount * speed + vibrationX, -1, 1);
} else {
x = constrain(x - randomNum * amount * speed + vibrationX, -1, 1);
}
if (chladni(x, y + vibrationmax) <= amount) {
y = constrain(y + randomNum * amount * speed + vibrationY, -1, 1);
} else {
y = constrain(y - randomNum * amount * speed + vibrationY, -1, 1);
}
}
}
float chladni(float x, float y) {
float L = 2;
return cos(n * PI * x / L) * cos(m * PI * y / L) - cos(m * PI * x / L) * cos(n * PI * y / L);
}
void display() {
point(x, y);
}
}
```

Reference: Chladni plate interference surfaces

## Recommended Book / Generative art for beginner

### Generative Art: A Practical Guide Using Processing – Matt Pearson

Generative Art presents both the techniques and the beauty of algorithmic art. In it, you’ll find dozens of high-quality examples of generative art, along with the specific steps the author followed to create each unique piece using the Processing programming language. The book includes concise tutorials for each of the technical components required to create the book’s images, and it offers countless suggestions for how you can combine and reuse the various techniques to create your own works.

Purchase of the print book comes with an offer of a free PDF, ePub, and Kindle eBook from Manning. Also available is all code from the book.

—–

► **Generative Art: A Practical Guide Using Processing** – Matt Pearson

Publication date: 2011. July 10

Length: 240 Pages

Publisher: Manning

Language: English

—–

## Related article

### How to get started with a Pen-Plotter for code graphics.

The use of pen plotters and other drawing machines has become an important part of the contemporary generative and digital art scene. This article is written for those who are considering the introduction of a pen plotter.

## Recommended on Amazon

I introduce the tools and gear I use for my art, as well as the books on my studio bookshelf on Amazon’s barbe_generative_diary page.