float t; // currentTime
int t1 = 2000; //2000ms = after 2s
int t2 = 6000; //6000ms = after 6s
int t3 = 10000; //10000ms = after 10s
int t4 = 15000; //1500ms = after 15s
int finish = 20000; //2000ms = 20s
Amplitude amp;
float a; // amplitude value = a
float x; // x-pos of the shape
float c; //rotation of the shape
float n4;
float n6;
float n5 = 0.01;
int n;
Square[] rect;
float x2 = 0;
//MUSIC
import ddf.minim.*;
import ddf.minim.signals.*;
Minim minim;
AudioPlayer mySound;
// for fixing delay problem
Boolean isStart=false;
float delay;
void setup() {
fullScreen();
noCursor();
smooth();
background (0);
frameRate(50);
minim = new Minim(this);
mySound = minim.loadFile("hill.mp3");
mySound.play();
n = 10; // number of rect
rect = new Square[n]; //storing rect in array
for (int i=0; i<n; i++) {
rect[i] = new Square(i); //number of rect
}
}
void draw() {
background(0);
// for fixing delay problem
if (!isStart) {
mySound.play();
delay=millis();
isStart=true;
}
t = (millis()-delay)%finish;
//a = amp.analyze();
//Event/Effect 1 : 0s - 2s
if (t < t1) {
effect01();
}
//Event/Effect 2 : 2s ~ 6s
if (t > t1 && t <t2) {
effect02();
}
//Event/Effect 3 : 6s~10s
if (t >t2 && t <t3) {
effect03();
}
//Event/Effect 4 : 10s~15s
if (t >t3 && t <t4) {
effect04();
}
//Event/Effect 5 : 15s~20s
if (t >t4 && t <finish) {
effect05();
}
displayTime();
}
void effect02() {
background(0);
for (int i=0; i<n; i++) {
rect[i].display(); // display rect
}
}
class Square {
Square(int index) {
}
void display() {
float x1 = 0; // mapping for noise
fill(random(255), random(255), random(255)); // fill of rect
for (int i = 0; i < width; i++) {
rect(i*90, noise(x1, x2)*1000, 30, 30); // position and size of rect
x1 -= map(mouseX, 0, width, 0.0001, 1 ); //mapping the x1 for noise
frameRate(10);
}
for (int j = 0; j < width; j++) {
x2 -= map(j, 0, width, 0.00001, 1); // mapping x2 for noise
}
}
}
how can I make it react to music
void effect03() {
//println(amp.analyze());
fill(amp.analyze() + 1000,10);
rect(0,0,width,height);
float d = amp.analyze()*1000;
float c = amp.analyze()*500;
fill(c, random(c), 200);
ellipse(width/2, height/2, d,d);
float s = map(mouseX, 0, width, 0, 1.0);
//song.amp(s);
}
this one I’m facing issues. It’s all one code