Help with random text

Hi everyone, I am working on an installation based on visual and texts. I would like to extract random quotes from a txt file and show them for a fixed time (eg. 5 seconds) but I am having some trouble. Here is the part of code related to the issue. Thanks in advance!

PFont f;

//Database variables String[] lines; int index = 0;

void setup() { size(800, 800, P3D); noStroke(); frameRate(30); f = createFont("AmericanTypewriter", 16, true);

lines = loadStrings("OBLQ.txt");

}

void draw() { background(230);

//Database if (index < lines.length) { String[] pieces = split(lines[index], " "); if (pieces.length == 2) { int x = int(pieces[' ']) ; int y = int(pieces[1]) ;

println(x); index = index + 1;

//HERE IS WHERE I WOULD LIKE TO INSERT THE TEXT();

} } //Loop database if(index > 20) { index = 0;

} }

Answers

  • PFont f;
    
    //Database variables 
    String[] lines={"sdfds", "asdvfd", "sdfgsad", "qqqq", "wwwww"}; 
    int index = 0;
    int startTime;
    
    float xPos;
    
    void setup() { 
      size(800, 800, P3D); 
      noStroke(); 
      frameRate(30); 
      f = createFont("AmericanTypewriter", 16, true);
    
      // lines = loadStrings("OBLQ.txt");
    
    
      index=int(random(lines.length));
      xPos=random(width);
      startTime=millis();
      background(230);
    }
    
    void draw() { 
      background(230);
    
    
    
      fill(0);
      text(lines[index], xPos, 100); 
    
    
      if (millis() > startTime+1000) {
        index=int(random(lines.length));
        xPos=random(width);
        startTime=millis();
      }
    }
    
  • you need this

      textFont(f);  
    
  • Thank you so much Chrisir! Have a nice day!

Sign In or Register to comment.