import ddf.minim.*;
import com.hamoid.*;

Minim minim;
AudioPlayer player;
VideoExport videoExport;

float colorisationR;
float colorisationV;
float colorisationB;

float angle = 100; // début du dessin du cercle
float offset = 0; // offset de la spiral
float scalar = 80; // taille du premier loop
float speed = 0.01; // vitesse de la spirale
int t=1; // timeline


float movieFPS = 30;
float soundDuration = 364; // in seconds

void setup() {

surface.setSize(3840, 2160);
smooth();
background(255);


// Chargement du fichier MP3 et lecture
minim = new Minim(this);
player = minim.loadFile("); // charger un son ici
player.play();
player.mute();

videoExport = new VideoExport(this);
videoExport.setFrameRate(movieFPS);
videoExport.setAudioFileName("");
videoExport.startMovie();
}
void draw() {

float time1 = 10000;
float currentTime = millis();


if (frameCount % 500000 ==0) { //an if statement, where if we have a factor of 27 seconds, changes t from 1 to -1
t= t* -1;
}
if (t== 1) { //quand t est positif

smooth(); //smooth lines
float x = 1920 + cos(angle) * scalar; //creates the x position of spiral
float y = 1080 + sin(angle) * scalar; // creates the y position of spiral

ellipse( x, y, player.left.get(t)*30, player.right.get(t)*30); //creates spiral
angle += speed; //creates circular pattern
scalar += 5*speed; // the amount of space in each spiral

float size = player.left.get(t)*13;
colorisationR = map(size, -5, 12, 0, 255);
colorisationV = map(angle, 50, 1200, 150, 255);
colorisationB = 20;

fill(colorisationR, colorisationV, colorisationB); //couleur de l'élipse
noStroke();


}

videoExport.saveFrame();

// End when we have exported enough frames
// to match the sound duration.
if(frameCount > round(movieFPS * soundDuration)) {
videoExport.endMovie();
exit();
}
}

void keyPressed() {
if (key == 'q') {
videoExport.endMovie();
exit();
}
}