Loading...
Logo
Processing Forum
Dear all interested readers,

I am trying to visualise actual data. I have made a moving graph, like a heart monitor. What would be the best way to add more values in order to make more graphs? Maybe I can make a class for it, or can I do this more simple?


Copy code
  1. float[] values;
    int numPoints;

    void setup(){
      size(800,600);
      frameRate(30);
      smooth();
      noStroke();
     
      frame.setResizable(true);
      numPoints = 20;
      values = new float[numPoints];
     
    }

    void draw(){
      background(255);


    if (frameCount % 10 == 0) {
      storeval();
      }


      values[0] = (height*0.01)*(mouseX);

    fill(100,250,100,150);
    beginShape();
    for (int i=0; i<numPoints; i++) {
        float value = values[i];
        float x = width - (width / numPoints) * i;
        float y = height - value;
        vertex(x, y);

    }

    vertex(0, height);
    vertex(width, height);
    endShape();
    }

    void storeval(){
     
       for(int i = numPoints-2; i >= 0; i--){
        values[i+1] = values[i];
       }
     
      }


Example of what I want to do:






Thanks in advance,


Joshua

Replies(6)

Do you know a maximum amount of types of data you will be displaying? Cause if you do, then you can just turn values[] into values[][] where the first dimension will equal the number of the type, and the second dimension will equal the values for that type. Then you just turn the for loop that displays the values into a double for loop where the first loop loops through the types of data. Did I answer the right question there? Does it make sense?
Also, that's a really cool visual, I think I might use that style for one of my programs if you don't mind.

edit: If you want the array to have a single dimension for whatever reason, you can use [typeNum+typeNum*valueNum].
(valueNum is the position it would have in the double array, not it's actual number, ofc).
Hi, yes you can use it. I don't have a problem with that.


I will work with 6 different values, recieved from a float.

Can you give me an example of how to implement this into the code?

Thanks in advance.
Sure.

Copy code
  1. int numTypes = 6;
  2. //other code
  3. void draw
  4. {
  5.       //your other code
  6.       for(int h = 0; h<numTypes; h++){
  7.             for (int i=0; i<numPoints; i++) {
  8.                   float value = values[h][i];
  9.                   float x = width - (width / numPoints) * i;
  10.                   float y = height - value;
  11.                   vertex(x, y);
  12.       }
  13.   }
  14. }
  15. void storeval() {
  16. for(int h = numTypes; h >= 0; h--){
  17.   for (int i = numPoints-2; i >= 0; i--) {
  18.     values[h+1][i+1] = values[h][i];
  19.   }
  20. }
Since the data is just linked to the mouse position, all of the data will be that same mouse position, so you'll have to make it so that each type corresponds to the data you need. Also, you don't have to use "h," in the double aray, I just use h cause it spells "hi" when using a double array, lol.
I tried it, but somehow failed? It's also not clear to me where to get the 6 floats from.

Copy code
  1. int numTypes = 6;
    //other code

    float[] values;
    int numPoints;

    void setup(){
      size(800,600);
      frameRate(30);
      smooth();
      noStroke();
     
      frame.setResizable(true);
      numPoints = 20;
      values = new float[numPoints];
     
    }


    void draw(){


      background(255);


      if (frameCount % 10 == 0) {
        storeval();
      }


      values[0] = (height*0.01)*(mouseX);

      fill(100, 250, 100, 150);
      beginShape();
      for (int i=0; i<numPoints; i++) {
        float value = values[i];
        float x = width - (width / numPoints) * i;
        float y = height - value;
        vertex(x, y);
      }

      vertex(0, height);
      vertex(width, height);
      endShape();
    }

    void storeval() {

      for (int i = numPoints-2; i >= 0; i--) {
        values[i+1] = values[i];
      }



    //your other code
    for (int h = 0; h<numTypes; h++) {
      for (int i=0; i<numPoints; i++) {
        float value = values[h][i];
        float x = width - (width / numPoints) * i;
        float y = height - value;
        vertex(x, y);
      }
    }
    }




     


You don't have the double array in the draw loop (see the code I posted for details). And that's where you declare what the value is equal to, so that's where you would input the data.
edit: Also, you have to declare it as "float[][] values;" now (on the 3rd/4th line in the code you posted). Sorry I forgot about that.
Once again, thank you for your help. 

I tried to make it work following your comments, but it doesn't work out. Can you show me how you would do it? I try to connect the floats I have, but I just don't get it.