using an arrayList to keep track and create alot of different classes.

heres the code I'm getting a null pointer exception on line 73 and I don't know what is wrong. im trying to get this thing to run so i can fix it up.

/* alec burns * love data visualization project * 6/19/2015

  • this program reads through text files that have
  • lines with love in them from a single document or text book
  • creates a visualization for them each text represented by a
  • glowing particle that fades in and out of space. click on it
  • and you can read the line, hover over it and lines connect all
  • the balls from the same text

    */

    //color sceme: //tan int alpha = 100; color c1 = color(255,241,225); //cool-red color c2 = color(242,0,88); //pink color c3 = color(255,174,172); //black color c4 = color(0,0,5); //blue-gray color c5 = color(174,169,209); //create a textParticles object to keep track of the particles for that text file TextParticles quranParts;

void setup(){ //constructing the object for testing quranParts = new TextParticles(loadStrings("quran_love.txt")); background(c4); //testing color pallet size(400,400); rectMode(CORNER); float m = width / 5; noStroke(); fill(c1); rect(0,0,m,height); fill(c2); rect(m,0,m * 2, height); fill(c3); rect(m 2, 0, m3, height); fill(c4); rect(m3, 0, m4, height); fill(c5); rect(m*4, 0, m * 5, height);

}

void draw(){ quranParts.display(); }

class TextParticles { String[] txtFile; ArrayList particles; Boolean hoverOn = false; String displayText = ""; float xoff = 0; float yoff = 0.0;

TextParticles(String[] file){ txtFile = file; for(int lineNum = 0; lineNum < txtFile.length; lineNum++){ String line = txtFile[lineNum]; particles.add(new DustParticle(line, lineNum)); } }

void display(){ float offsetSizeX = map(noise(xoff),0,1,0,.3); float offsetSizeY = map(noise(yoff),0,1,0,.3);

for (int i = 0; i < particles.size(); i++){ float x = map(noise(xoff, yoff), 0, 1, width, height); float y = map(noise(xoff, yoff), 0, 1, width, height); DustParticle currPart = particles.get(i); currPart.xpos = x; currPart.ypos = y; //fill of the particles is the second color in the scheme fill(c2); if (currPart.stopMoving == true){ if ((mouseX == pmouseX) && (mouseY == pmouseY)){ ellipse(pmouseX,pmouseY,2+offsetSizeX,2+offsetSizeY);
ellipse(pmouseX,pmouseY,1+offsetSizeX,1+offsetSizeY); } else { currPart.stopMoving = false; } } if(hoverOn = false){ /* * if hover on is true: * all the dust particles from the same book light up */ // if mouse is close to or hovering over a dot hoveron is set to true if ((mouseX > x - 2) && (mouseX < x + 2) && (mouseY > y - 2) && (mouseY < y + 2)){ hoverOn = true; currPart.stopMoving = true; if(mousePressed){ //if the mouse is pressed while hovering over a particle the text of //that ball will be displayed displayText = currPart.loveLine; }
} else{ hoverOn = false; } ellipse(x,y,1+offsetSizeX,1+offsetSizeY); } else{ //if hoverOn is true (if the mouse is hovering over a particle) give each particle a glow and draw a line between them if(i > 0){ DustParticle pastPart = particles.get(i - 1); //draws a line from the last particle to the current particle //line color is fifth color in color pallet stroke(c5); line(pastPart.xpos, pastPart.ypos, currPart.xpos, currPart.ypos); }

ellipse(x,y,1+offsetSizeX,1+offsetSizeY);
} xoff += .01; yoff += .01; } } }

class DustParticle { String loveLine; int lineNumber; float xpos; float ypos; boolean stopMoving = false; DustParticle(String lovLin, int linNum){ loveLine = lovLin; lineNumber = linNum; xpos = random(width); ypos = random(height); } /* void generateLoc(){ xpos = random(width); ypos = random(height); */
}

Tagged:

Answers

  • You'll get a better response if you format your code. Here's how:

    http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text

  • Answer ✓
    //color sceme: //tan 
    int alpha = 100; 
    color c1 = color(255, 241, 225);
    //cool-red 
    color c2 = color(242, 0, 88); 
    //pink 
    color c3 = color(255, 174, 172); 
    //black 
    color c4 = color(0, 0, 5);
    //blue-gray 
    color c5 = color(174, 169, 209); 
    
    //create a textParticles object to keep track of the particles for that text file
    TextParticles quranParts;
    
    String[] testtext = {
      "love is king", "God is love", "love all", "love reigns", "love your neighbour", "love your enemy"
    };
    
    void setup() {
      size(400, 400);
    
      //constructing the object for testing
      // quranParts = new TextParticles(loadStrings("quran_love.txt"));
      quranParts = new TextParticles(testtext); 
    
      background(c4); 
    
      if (false) {
    
        //testing color pallet
        rectMode(CORNER); 
        float m = width / 5;
        noStroke(); 
        fill(c1); 
        rect(0, 0, m, height); 
        fill(c2); 
        rect(m, 0, m * 2, height); 
        fill(c3); 
        rect(m * 2, 0, m*3, height); 
        fill(c4); 
        rect(m * 3, 0, m*4, height); 
        fill(c5); 
        rect(m * 4, 0, m * 5, height);
      }
      //
    }
    
    void draw() { 
      quranParts.display();
    }
    
    class TextParticles { 
      //  String[] txtFile; 
      ArrayList<DustParticle> particles = new ArrayList(); // tells the ArrayList its type 
      Boolean hoverOn = false; 
      String displayText = ""; 
      float xoff = 0; 
      float yoff = 0.0;
    
      TextParticles(String[] file) { 
        //txtFile = file; 
        for (int lineNum = 0; lineNum < file.length; lineNum++) { 
          String line1 = file[lineNum]; 
          particles.add(new DustParticle(line1, lineNum));
        }
      }
    
      void display() { 
        float offsetSizeX = map(noise(xoff), 0, 1, 0, .3); 
        float offsetSizeY = map(noise(yoff), 0, 1, 0, .3);
    
        for (int i = 0; i < particles.size (); i++) { 
          float x = map(noise(xoff, yoff), 0, 1, 0, width); 
          float y = map(noise(xoff, yoff), 0, 1, 0, height); 
          DustParticle currPart = particles.get(i); 
          currPart.xpos = x; 
          currPart.ypos = y; 
          //fill of the particles is the second color in the scheme 
          fill(c2); 
          if (currPart.stopMoving) { 
            if ((mouseX == pmouseX) && (mouseY == pmouseY)) { 
              fill(255); 
              ellipse(pmouseX, pmouseY, 2+offsetSizeX, 2+offsetSizeY);
              ellipse(pmouseX, pmouseY, 1+offsetSizeX, 1+offsetSizeY);
            } else { 
              currPart.stopMoving = false;
            }
          } 
          if (hoverOn = false) { 
            /* 
             * if hover on is FALSE: 
             * all the dust particles from the same book light up 
             */
            // if mouse is close to or hovering over a dot hoveron is set to true
            if ((mouseX > x - 2) && (mouseX < x + 2) && (mouseY > y - 2) && (mouseY < y + 2)) { 
              hoverOn = true; 
              currPart.stopMoving = true; 
              if (mousePressed) { 
                //if the mouse is pressed while hovering over a particle the text of 
                //that ball will be displayed 
                displayText = currPart.loveLine;
                fill(255); 
                text(displayText, currPart.xpos, currPart.ypos );
              }
            } else { 
              hoverOn = false;
            } 
            fill(255); 
            ellipse(x, y, 1+offsetSizeX, 1+offsetSizeY);
          } else { 
            //if hoverOn is true (if the mouse is hovering over a particle) give each particle a glow and draw a line between them
            if (i > 0) { 
              DustParticle pastPart = particles.get(i - 1);
              //draws a line from the last particle to the current particle
              //line color is fifth color in color pallet 
              stroke(c5); 
              line(pastPart.xpos, pastPart.ypos, 
              currPart.xpos, currPart.ypos);
            }
    
            ellipse(x, y, 1+offsetSizeX, 1+offsetSizeY);
          } 
          xoff += .01; 
          yoff += .01;
        }
      }
    }
    
    class DustParticle { 
      String loveLine; 
      int lineNumber; 
      float xpos; 
      float ypos; 
      boolean stopMoving = false;
    
      DustParticle(String lovLin, int linNum) { 
        loveLine = lovLin; 
        lineNumber = linNum; 
        xpos = random(width); 
        ypos = random(height);
      }
    
      /* void generateLoc(){ 
       xpos = random(width); 
       ypos = random(height); 
       */
    }
    //
    
  • Answer ✓

    not finished yet....................

  • do not accept an answer too soon...

    or is it solved?

Sign In or Register to comment.