topical media & game development

talk show tell print

graphic-processing-algorithm-Appendix-p331-x4-p331-x4.pde / pde



  String lines[];
  
  void setup(){
    PFont myFont = createFont("Verdana",10);
    textFont(myFont, 10);
    lines = loadStrings("names.txt");
    size(300,22*lines.length);
  
    int k = lines.length-1;
    String temp = "";
    //swap 50 times randomly
    for (int i=0; i < 50; i++) {
      int r1 = int(random(k));
      int r2 = int(random(k));
      temp = lines[r1];
      lines[r1] = lines[r2];
      lines[r2] = temp;
    }
    saveStrings("names.altered.txt", lines);
  }
  
  void draw(){
    background(255);
    fill(0);
    for (int i=0; i < lines.length; i++) {
      text(lines[i], 10, (i+1)*20);
    }
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.