« Projet tango » : différence entre les versions

De Wikilipo
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
Ligne 161 : Ligne 161 :
   http://code.compartmental.net/minim/distro/minim-2.0.2-lib.zip
   http://code.compartmental.net/minim/distro/minim-2.0.2-lib.zip
   Il faut mettre cette librairie dans repertoire nommé libraries.
   Il faut mettre cette librairie dans repertoire nommé libraries.
   Il faut aussi mettre le tango (ici "Malena.mp3") dans un repertoire data.  
   Il faut aussi mettre le tango (ici "Isabela.mp3") dans un repertoire data.  
  Ca marche pas mal avec http://www.archive.org/details/Tango_de_Liliane___Marcos_Oliva
  Ca marche un peu avec http://www.archive.org/details/Isabela
   Le tango peut être au format WAV, AIFF, AU, SND, ou MP3.
   Le tango peut être au format WAV, AIFF, AU, SND, ou MP3.
   On a donc cette structure de repertoires:
   On a donc cette structure de repertoires:
Ligne 167 : Ligne 169 :
             |- glissant.pde
             |- glissant.pde
             |- data -|
             |- data -|
                       |- Malena.mp3
                       |- Isabela.mp3
             |- librairies -|
             |- librairies -|
                             |- minim -| (etc..)
                             |- minim -| (etc..)
Ligne 176 : Ligne 178 :
import ddf.minim.analysis.*;
import ddf.minim.analysis.*;


String fichier_du_tango = "Malena.mp3";
String fichier_du_tango = "Isabela.mp3";


int tempsDernierMot = 0;
int tempsDernierMot = 0;
Ligne 229 : Ligne 231 :
   //pour voir la "regle" qu'on traine
   //pour voir la "regle" qu'on traine
   //angleMeter.draw();
   //angleMeter.draw();
      
boolean battement = beat.isRange(0,5,1);
//boolean battement = beat.isKick();
if(battement){
     //pour dessiner un rectangle quand on voit un battement   
    rect(0,width/2,20,20);
}
//pour voir les bandes qu'on peut donner en argument à isRange
beat.drawGraph(this);


  //if(frameCount > tempsDernierMot+20 && beat.isKick()){
  //if(frameCount > tempsDernierMot+20 && beat.isKick()){
  if(frameCount > tempsDernierMot+20 && beat.isRange(0,4,1)){
  if(frameCount > tempsDernierMot+20 && battement){
    //pour dessiner un rectangle quand on voit un battement   
    //rect(0,width/2,20,20);
      
      
     index = (int)random(dico.length);
     index = (int)random(dico.length);
Ligne 240 : Ligne 248 :
     tempsDernierMot = frameCount;
     tempsDernierMot = frameCount;
   }
   }
  //pour voir les bandes qu'on peut donner en argument à isRange
  beat.drawGraph(this);


   // tracer tous les mots du tableau mots
   // tracer tous les mots du tableau mots

Version du 18 mars 2010 à 10:53

Voici une page où mettre les sketches processing sur lesquels nous travaillons:

Cercles par Andreas

ArrayList lastValues = new ArrayList();
int nbCircles = 40;
int diameterIncrement = 20;

void setup() {
  size(400, 400);
  smooth(); 
  noStroke();
  //framerate(60);
  while(lastValues.size()<nbCircles*2){
    lastValues.add(new int[]{0,0});
  }
}

void draw() {
  background(0);
  lastValues.remove(0);
  lastValues.add(new int[]{mouseX,mouseY});
  
  drawCirles(nbCircles, lastValues, diameterIncrement);
}

void drawCirles(int nb,java.util.List lastValues,int diameterIncrement){
  int firstValue = lastValues.size() -1 - (nb-1) * 2;
  int largestDiameter = 40 + diameterIncrement *nb;
  for(int i = 0; i<nb; i++){
    int fillColor = (i%2==0) ? 255 : 0;
    fill(fillColor, fillColor, fillColor);

    int [] xy = (int[])lastValues.get(firstValue + i*2);
    int diameter = largestDiameter - diameterIncrement * i;
    ellipse(xy[0], xy[1], diameter, diameter);
  }
}

Mots_objet, par Ambroise

Ce script n'est pas encore propre. Il s'agit de créer une class d'objets txt, avec un constructeur txt() et une méthode, ecrire(). Ça ne fonctionne pas encore correctement, mais c'est une esquisse pour traiter les mots qui sont tracés sur le fond comme des objets à part entière, qui peuvent donc avoir des comportements variés, indépendamment les uns des autres. Merci de faire vos corrections.

// initialisation du tableau mots contenant des objets de type txt
txt[] mots = new txt[0];
String[] dico = {"tango","salsa","electro"};
PFont myFont = createFont("Monospaced.italic", 30);

void setup() 
{
  size(400, 400);
  background(0.0);
  colorMode(RGB, 1.0);
  noStroke();
  
  textFont(myFont);
  fill(#FF0000);

}

void draw() 
{
  // creer un nouveau mot chaque 1.5 secondes
  if (frameCount % 90 == 0) {
    mots = (txt[]) append(mots, new txt());
  }
  // tracer tous les mots du tableau mots
  // il y a un problème à l'exécution, outofmemory après une quinzaine d'objets créés
  for (int a=0;a<mots.length;a++) {
    mots[a].ecrire();
  }
}

// la classe txt, avec son constructeur txt() qui choisit un mot aléatoirement dans dico
// et une methode ecrire() qui place ce mot à la position de la souris:

class txt {
  int x=mouseX; int y=mouseY;
  int i = int(random(dico.length));
  void ecrire() {
    text(dico[i],x,y);
  }
}

J'ai pas pu m'empêcher de faire une version sans la classe txt, qui ne sert pas encore à grand chose. La classe txt commencera à être utile si on se décide à représenter les mots différemment selon le temps, par exemple si on veut les faire vibrer ou disparaitre.

//version simplifiée du sketch précédent
String[] dico = {"tango","salsa","electro"};

void setup() 
{
  size(400, 400);
  background(0.0);
  colorMode(RGB, 1.0);

  textFont(createFont("Monospaced.italic", 30));
  fill(#FF0000);

}

void draw() 
{
  // creer un nouveau mot chaque 1.5 secondes
  if (frameCount % 90 == 0) {
    int index = int(random(dico.length));
    for(int i=0; i<10;i++){
      //pour répliquer l'effet du sketch original il faut écrire plusieurs fois le même mot
      //au même endroit. Il y a surement une meilleure manière d
      text(dico[index],mouseX,mouseY);
    }
  }
}

brouillon

Ce sketch montre comment obtenir des effets avec lesquels nous avions joué lors de la première réunion processing:

String [] mots = {"bonjour","au revoir","merci"};
int index;

void setup() 
{
  size(400, 400);
  colorMode(RGB, 1.0);
  noStroke();
  PFont myFont = createFont("FFScala", 32);
  textFont(myFont);
}

void draw() 
{
  background(0);
  fill(0.0, 100, 100); 
  
  //plus on s'approche de "l'horizon", plus les mots changent vite
  float distToCenter = abs(mouseY - width/2.0)/width;
  int refreshPeriod = max(1,(int)(50 * distToCenter));
  if(frameCount % refreshPeriod== 0){
    index = (int)random(mots.length);
  }
  String mot = mots[index];
  
  //rotation du mot sur lui-même
  translate(mouseX,mouseY);
  rotate(TWO_PI*(frameCount%200/200.0));
  text(mot,-textWidth(mot)/2, 8); 
}

Glissant

/* glissant.pde
   Ce sketch utilise la librairie minim 
   http://code.compartmental.net/minim/distro/minim-2.0.2-lib.zip
   Il faut mettre cette librairie dans repertoire nommé libraries.
   Il faut aussi mettre le tango (ici "Isabela.mp3") dans un repertoire data. 
   Ca marche pas mal avec http://www.archive.org/details/Tango_de_Liliane___Marcos_Oliva
   Ca marche un peu avec http://www.archive.org/details/Isabela
   Le tango peut être au format WAV, AIFF, AU, SND, ou MP3.
   On a donc cette structure de repertoires:
   glissant -|
             |- glissant.pde
             |- data -|
                      |- Isabela.mp3
             |- librairies -|
                            |- minim -| (etc..)
   
*/

import ddf.minim.*;
import ddf.minim.analysis.*;

String fichier_du_tango = "Isabela.mp3";

int tempsDernierMot = 0;

Minim minim;
AudioSource in;
BeatDetect beat;
BeatListener bl;

String [] dico = {"bonjour","au revoir","merci"};
Txt[] mots = new Txt[0];

int index;
AngleMeter angleMeter = new AngleMeter(20);

void setup() 
{
  size(600, 450);
  
  minim = new Minim(this);
  // get a stereo line-in: sample buffer length of 2048
  // default sample rate is 44100, default bit depth is 16
  //in = minim.getLineIn(Minim.STEREO, 2048);
  in = minim.loadFile(fichier_du_tango, 2048);
  ((AudioPlayer)in).play();
  // a beat detection object that is FREQ_ENERGY mode that 
  // expects buffers the length of song's buffer size
  // and samples captured at songs's sample rate
  beat = new BeatDetect(in.bufferSize(), in.sampleRate());
  // set the sensitivity to 300 milliseconds
  // After a beat has been detected, the algorithm will wait for 300 milliseconds 
  // before allowing another beat to be reported. You can use this to dampen the 
  // algorithm if it is giving too many false-positives. The default value is 10, 
  // which is essentially no damping. If you try to set the sensitivity to a negative value, 
  // an error will be reported and it will be set to 10 instead. 
  beat.setSensitivity(300);  
  // make a new beat listener, so that we won't miss any buffers for the analysis
  bl = new BeatListener(beat, in);  
  
  //colorMode(RGB, 1.0);
  PFont myFont = createFont("FFScala", 32);
  textFont(myFont);
  fill(255); 
}

void draw() 
{
  background(0);

  //rotation
  angleMeter.drag(mouseX,mouseY);
  //pour voir la "regle" qu'on traine
  //angleMeter.draw();
 
 boolean battement = beat.isRange(0,5,1); 
 //boolean battement = beat.isKick();
 if(battement){
    //pour dessiner un rectangle quand on voit un battement    
    rect(0,width/2,20,20); 
 }
 //pour voir les bandes qu'on peut donner en argument à isRange
 beat.drawGraph(this);

 //if(frameCount > tempsDernierMot+20 && beat.isKick()){
 if(frameCount > tempsDernierMot+20 && battement){
    
    index = (int)random(dico.length);
    mots = (Txt[]) append(mots, new Txt(mouseX,mouseY,angleMeter.angle,dico[index]));
    tempsDernierMot = frameCount;
  }

  // tracer tous les mots du tableau mots
  for (int a=0;a<mots.length;a++) {
    mots[a].ecrire();
  }
}

class Txt {
  int x,y;
  float angle;
  String palabra;  
  float originalDrift = 100;
  float drift = originalDrift;
  
  
  Txt(int x, int y, float angle, String palabra){
    this.x = x;
    this.y = y;
    this.angle = angle;
    this.palabra = palabra;
  }
  
  void ecrire() {
    drift = drift*0.99;
    pushMatrix();
    translate(x,y);
    rotate(angle);
    text(palabra,-textWidth(palabra)+originalDrift-drift,0);
    popMatrix();
  }
}

/** Une espece de regle qu'on traine traine derriere soi 
    pour savoir dans l'angle dans lequel on se deplace**/
class AngleMeter{
  float [] draggedPoint = new float[2];
  float angle, distance;
  AngleMeter(float distance){
    this.distance = distance;
  }
  void drag(float x, float y){
    angle = atan2(y - draggedPoint[1],x - draggedPoint[0]);  
    draggedPoint[0] = x - (cos(angle) * distance);
    draggedPoint[1] = y - (sin(angle) * distance);
  }
  void draw(){
    strokeWeight(2.0);
    stroke(145,0,0);
    pushMatrix();
    translate(draggedPoint[0],draggedPoint[1]);
    rotate(angle);
    line(0, 0, distance, 0);
    popMatrix();
    noStroke();
  }
}


class BeatListener implements AudioListener
{
  private BeatDetect beat;
  private AudioSource source;
  
  BeatListener(BeatDetect beat, AudioSource source)
  {
    this.source = source;
    this.source.addListener(this);
    this.beat = beat;
  }
  
  void samples(float[] samps)
  {
    beat.detect(source.mix);
  }
  
  void samples(float[] sampsL, float[] sampsR)
  {
    beat.detect(source.mix);
  }
}