Utilisation de chat gpt pour générer l'ensemble d'un code pour du mapping.
Le code:
import ddf.minim.*; import java.util.ArrayList;
Minim minim; AudioInput in;
float[][] landscape;
int cols, rows;
float scale = 20;
float flying = 0;
ArrayList
void setup() { fullScreen(P3D); background(0);
minim = new Minim(this); in = minim.getLineIn(Minim.MONO, 512);
cols = width / int(scale); rows = height / int(scale); landscape = new float[cols][rows];
particles = new ArrayList
flowers = new ArrayList
void draw() { flying -= 0.1; float level = in.mix.level() * 1000; // Augmenter significativement l'effet du son sur l'animation
float lowFreqLevel = in.left.get(0) 500; // Utiliser des basses fréquences pour les particules float highFreqLevel = in.right.get(20) 500; // Utiliser des hautes fréquences pour les fleurs, avec un effet plus saccadé float melodyLevel = in.mix.level() * 400; // Augmenter l'effet pour simuler les mélodies
float yoff = flying; for (int y = 0; y < rows; y++) { float xoff = 0; for (int x = 0; x < cols; x++) { landscape[x][y] = map(noise(xoff, yoff), 0, 1, -level, level * 4); xoff += 0.2; } yoff += 0.2; }
background(0, 100);
translate(width / 2, height / 2 + 50); rotateX(PI / 3 + radians(melodyLevel / 50)); // Faire bouger l'écran de manière plus significative en fonction du niveau de mélodie rotateY(radians(melodyLevel / 75)); // Augmenter la rotation en Y pour suivre les mélodies translate(-width / 2, -height / 2);
noFill(); strokeWeight(1.5);
for (int y = 0; y < rows - 1; y++) { beginShape(TRIANGLE_STRIP); for (int x = 0; x < cols; x++) { float h1 = landscape[x][y]; float h2 = landscape[x][y + 1];
if (h1 < -level / 2) {
stroke(0, 0, 255);
} else if (h1 < level / 4) { // Ralentir la transition entre vert et orange
stroke(46, 204, 113);
} else {
stroke(231, 76, 60);
}
vertex(x * scale, y * scale, h1);
vertex(x * scale, (y + 1) * scale, h2);
}
endShape();
}
for (Particle p : particles) { p.update(lowFreqLevel); // Mettre à jour les particules en fonction des basses fréquences p.show(); }
for (Flower f : flowers) { f.update(highFreqLevel); // Mettre à jour les fleurs en fonction des fréquences élevées, avec un effet plus saccadé f.display(); } }
void stop() { in.close(); minim.stop(); super.stop(); }
class Particle { PVector position; PVector velocity; PVector acceleration; float lifespan;
Particle() { position = new PVector(random(width), random(height), random(-200, 200)); velocity = new PVector(random(-4, 4), random(-4, 4), random(-4, 4)); acceleration = new PVector(0, 0.05, 0); lifespan = 255; }
void update(float audioLevel) { velocity.add(acceleration); position.add(velocity); lifespan -= 1.5; position.x += random(-audioLevel / 10, audioLevel / 10); position.y += random(-audioLevel / 10, audioLevel / 10);
if (lifespan < 0) {
position = new PVector(random(width), random(height), random(-200, 200));
velocity = new PVector(random(-4, 4), random(-4, 4), random(-4, 4));
lifespan = 255;
}
}
void show() { pushMatrix(); translate(position.x, position.y, position.z); noStroke(); fill(255, lifespan); sphere(5); popMatrix(); } }
class Flower { float x, y, z, size; float angle; float angleSpeed; PVector velocity;
Flower(float x, float y, float z, float size) { this.x = x; this.y = y; this.z = z; this.size = size; this.angle = random(TWO_PI); this.angleSpeed = random(0.01, 0.05); this.velocity = new PVector(random(-3, 3), random(-3, 3), random(-3, 3)); }
void update(float audioLevel) { angle += angleSpeed; x += velocity.x + random(-audioLevel / 5, audioLevel / 5); // Rendre le mouvement plus saccadé en utilisant des valeurs plus élevées y += velocity.y + random(-audioLevel / 5, audioLevel / 5); z += velocity.z + random(-audioLevel / 5, audioLevel / 5);
// Empêcher les fleurs de sortir de l'écran
if (x < 0) {
x = 0;
velocity.x *= -1;
}
if (x > width) {
x = width;
velocity.x *= -1;
}
if (y < -200) {
y = -200;
velocity.y *= -1;
}
if (y > height) {
y = height;
velocity.y *= -1;
}
if (z < -200) {
z = -200;
velocity.z *= -1;
}
if (z > 200) {
z = 200;
velocity.z *= -1;
}
}
void display() { pushMatrix(); translate(x, y, z); rotate(angle); noStroke(); fill(255, 210, 6, 150);
for (int i = 0; i < 6; i++) {
pushMatrix();
rotate(PI / 3 * i);
translate(0, size / 2, 0);
sphere(size / 4);
popMatrix();
}
fill(255, 255, 255, 56);
sphere(size / 3);
popMatrix();
} }