How to switch from one text (using Geomerative) to an other according to a changing duration timer?!

edited June 19 in Library Questions

Hello, I asked a very close question brillantly answered by @jeremydouglas few time ago, now I'd like to have a different duration for each text. In the sketch below the changePhraseTimer() works, but not the changePhraseTimerN(), we don't see the last text and it doesn't loop properly. Could someone help me with this issue please ?! Thanks a lot in advance. L

import generativedesign.*;
import geomerative.*;
// List of a list of points. 1rst the numbre of phrases: 4,  the 2nd indicate the number of points
RPoint[][] myPoints = new RPoint[5][0];
RFont font;
PFont f;
Attractor attractor;

String [][] phraseSets = new String [4][0];
String [] FR1 = {
  "On me dit de te haïr et je m'y efforce", 
  "Je t'imagine cruel, violent, implacable", 
  "Mais à te voir je n'ai bientôt plus de force", 
  "Et de te blesser je suis bien incapable", 
};
String [] FR2 = {
  "Tous mes camarades combattent avec rage", 
  "Et pleurent la nuit au souvenir des supplices", 
  "Infligés à leurs frères qui sont du même âge", 
  "Et rêvent comme eux de toucher une peau lisse"
};
String [] FR3 =
  {"Et de pouvoir enfin caresser des obus", 
  "Autres que ceux produits par le pouvoir obtus", 
  "Je rêve de quitter ces boyaux infernaux"
};
String [] FR4 = {
  "De laisser ces furieux des deux bords du Rhin", 
  "Et de pouvoir embrasser ta chute de rein", 
  "Et porter notre amour sur les fonts baptismaux"
};

//TEXT
final color textColor = color(245);
int fontSize;

// TIME
int startTime;
int initTime;
int lineSpacing;
int index;
int state;
float duration;
int dur1;

//----------------SETUP---------------------------------------------------------------------------------------

void setup() {
  size(1920, 1080, JAVA2D);
  //add phrases to list
  phraseSets[0]=FR1;
  phraseSets[1]=FR2;
  phraseSets[2]=FR3;
  phraseSets[3]=FR4;

  smooth();
  RG.init(this);
  font = new RFont("FreeSans.ttf", 86, CENTER);
  stroke(textColor);
  strokeWeight(0.05);
  //INIT
  drawPhrases(phraseSets[0]);

   // TIME
  startTime=millis();
  initTime=millis();
  index=0;
  lineSpacing =150;
}

//----------------DRAW----------------------------------------------------------------------------------

void draw() {
  background(255);
  state =0;


  // TEXTS
  // draw on the center of the screen
  translate(width/2, height/2);
  // draw phrases vertically centered by moving the top up by half the line spaces
  translate(0, -1.0*lineSpacing*(phraseSets[index].length-1)/2.0);
  // loop through lines
  for (int i=0; i< myPoints.length; i++) {
    // draw a line
    for (int j=0; j< myPoints[i].length-1; j++) {
      pushMatrix(); 
      translate(myPoints[i][j].x, myPoints[i][j].y);
      noFill();
      stroke(0, 200);
      strokeWeight(0.25);
      float angle = TWO_PI*10;
      rotate(j/angle);
      bezier(-2*(noise(10)), 10, 25*(noise(10)), -5, 2*noise(5), -15, 10, -3);
      //bezier(-10*(noise(20))+mouseX/15, 30+mouseY/10, -10*(noise(10))+mouseX/15, 20+mouseY/15, -20*noise(20)+mouseX/15, -20+mouseY/5, 10+mouseX/15, -10+mouseY/15);
      popMatrix();
    }
    // move to the next line
    translate(0, lineSpacing);
  }
  //check Timer and redraw phrases if time has passed

  changePhraseTimerN();
  //changePhraseTimer(duration*4, phraseSets);

}

//----------------INITIALIZE----------------------------------------------------------------------------------------------------------------------------------------
void drawPhrases(String [] phrases) {
  myPoints = new RPoint[phrases.length][0];
  for (int j=0; j<phrases.length; j++) {
    RGroup myGroup = font.toGroup(phrases[j]);
    myGroup = myGroup.toPolygonGroup();
    myPoints[j] = myGroup.getPoints();
  }
}

//----------------TIMER----------------------------------------------------------------------------------------------------------------------------------------

/*void changePhraseTimer( float duration, String [][] phraseSets) {
 duration = sounds[0].length()-150;
 if (millis()-startTime > duration*4) {
 index =(index+1) % phraseSets.length; 
 //drawPhrases(phraseSets[index]);
 //startTime = millis();
 }
 }*/

void changePhraseTimerN() {
  dur1=11500;

  if (millis()-startTime > dur1+1400) {
    index =(index+1) % phraseSets[1].length; 
    drawPhrases(phraseSets[index]);
    startTime= millis();
  } else if (millis()-startTime > dur1-800) {
    index =(index+1) % phraseSets[2].length; 
    drawPhrases(phraseSets[index]);
    startTime= millis();
  } else if (millis()-startTime > dur1+1000) {
    index =(index+1) % phraseSets[3].length; 
    drawPhrases(phraseSets[index]);
    startTime= millis();
  } else if (millis()-startTime > dur1*2-8000) {
    drawPhrases(phraseSets[0]);
    startTime= millis();
  }
}


//----------------TEXT ATTRACTOR INIT----------------------------------------------------------------------------------------------------------------------------------------
void initAttractor(int i) {
  if (i>=4 && i<8) {
    i-=4;
  } else if (i>=8 && i<11) {
    i-=8;
  } else if (i>=11 && i<14) { 
    i-=11;
  } else if (i>14) {
    i=0;
  }

  float x = 0;
  float y =-50; 
  // println(i); 
  attractor = new Attractor(x, y, myPoints[i]);
}


class Attractor {

  float force_radious = 100;
  float maxForce = 15;
  RPoint position;
  RPoint[] points;

  Attractor(float x, float y, RPoint[] p) {
    points = p;
    position = new RPoint(x, y);
  }

  void attract() {

    for (int i =0; i < points.length; i++) {

      float d= points[i].dist(position);
     // println ("d : "+d);
      if (d < force_radious) {   
        RPoint desired = new RPoint(points[i]);
        //points[i]= new RPoint(points[i]);
        //println( "avant x : "+ points[i].x +" y: "+points[i].y);
        desired.sub(position);
        desired.normalize();
        desired.scale(map(d, 0, force_radious, maxForce, 0));
        points[i].add(desired);
         //println( "après x : "+ points[i].x +" y: "+points[i].y);
      }
    }
  }
  void display () {
    stroke(0);
   strokeWeight(2);
  // ellipse (position.x, position.y-750, 30, 30);
  }
  void moveTo(float x, float y){
    position.x=x;
    position.y=y;

  }
}

Answers

This discussion has been closed.