Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How to switch from one text to another according to time with the Geomerative library?!

$
0
0

Hi, I have an issue with Geomerative. I'd like to switch from text to text using this library according to a time schedule. It works but when switching to a shorter text I still see the previous text! How can I switch properly from a text to another?! Thanks a lot in advance for your help. Best, L

import geomerative.*;
// Liste de liste de points. La 1ère correspond au nombre de phrases, ici 4, la 2ème correspond au nom total de points par phrase
RPoint[][] myPoints = new RPoint[4][0];
RFont font;

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"
};

final color textColor = color(245);
// TIME
int startTime;


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

void setup() {
  size(1920, 1080, JAVA2D);

  smooth();
  RG.init(this);
  font = new RFont("FreeSans.ttf", 86, CENTER);
  stroke(textColor);
  strokeWeight(0.05);
  //INIT
  initAll();
  changePhrases(0);
  changePhrases(1);
  changePhrases(2);
  changePhrases(3);
  // TIME
  startTime=millis();
}

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

void draw() {
  background(255);



  translate(width/2, height/1.5);

  for (int i=0; i< myPoints.length; i++) {
    for (int j=0; j< myPoints[i].length-1; j++) {

      pushMatrix(); 
      translate(myPoints[i][j].x, myPoints[i][j].y-420+i*180);
      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();
    }
  }
  if (millis()-startTime > 0 && millis()-startTime < 3000) {
    changePhrases(0);
  }

  if (millis()-startTime > 3000 && millis()-startTime < 6000) {
    changePhrases(1);
  }

  if (millis()-startTime > 6000 && millis()-startTime < 9000) {
    changePhrases(2);
  }

  if (millis()-startTime > 9000 && millis()-startTime < 12000) {
    changePhrases(3);
  }

}

//----------------INITIALIZE---------------------------------
void initAll() {
  for (int j=0; j<FR1.length; j++) {
    RGroup myGroup = font.toGroup(FR1[j]);
    myGroup = myGroup.toPolygonGroup();
    myPoints[j] = myGroup.getPoints();
  }
}

//FUNCTION TO SWITCH PHRASES
void changePhrases(int state) {

  switch(state) {
  case 0:
    for (int j=0; j<FR1.length; j++) {
      RGroup myGroup = font.toGroup(FR1[j]);
      myGroup = myGroup.toPolygonGroup();
      myPoints[j] = myGroup.getPoints();
    }
    break;
  case 1:
    for (int j=0; j<FR2.length; j++) {
      RGroup myGroup = font.toGroup(FR2[j]);
      myGroup = myGroup.toPolygonGroup();
      myPoints[j] = myGroup.getPoints();
    }
    break;
  case 2:
    for (int j=0; j<FR3.length; j++) {
      RGroup myGroup = font.toGroup(FR3[j]);
      myGroup = myGroup.toPolygonGroup();
      myPoints[j] = myGroup.getPoints();
    }
    break;
  case 3:
    for (int j=0; j<FR4.length; j++) {
      RGroup myGroup = font.toGroup(FR4[j]);
      myGroup = myGroup.toPolygonGroup();
      myPoints[j] = myGroup.getPoints();
    }
    break;
  }
}
//////////////////////////////////////////////

Viewing all articles
Browse latest Browse all 2896

Trending Articles