Loading...
Logo
Processing Forum
Hi all,

I am trying to draw out my data with lines going from top of sketch to bottom, spaced evenly apart with line widths determined by data from a spreadsheet. So, I am trying to get a simple gradient effect with my data.

Right now, I am getting a black box, or maybe it's with no spacing! 

Is something wrong in my for-loop?
Copy code
  1. float readVal;
    float lineWidth;

    SimpleSpreadsheetManager sm;
    void setup() {
      size(800,800);
      background(255);
      lineWidth = 3;
    }
     

    void draw(){
          SimpleSpreadsheetManager sm = new SimpleSpreadsheetManager();
          sm.init("sensor log3","@gmail.com", "WWWWWWWWWW4");
          sm.fetchSheetByKey("0Ai-_2FVf77didEVZODdhUlBFNUJIS2lVLTU5d0FUR3c", 0);

           for (int c=0; c < sm.currentTotalCols ; c++){
            for (int r=0; r < sm.currentTotalRows ; r++){
              
             
              float tempVal = Float.parseFloat(sm.getCellValue(2,r));
                  readVal = tempVal;
                  readVal = map(readVal,0,350,0,1);
                  println(readVal);
                  lineWidth = readVal;
             
            
                  strokeWeight(1*lineWidth);
                   line(r+5,0,r+5,height);
              }
           }
          
    }

Replies(3)

It is hard to tell without the library and the spreadsheet.
But there are several things looking odd.
You connect to your spreadsheet and get data on each frame, ie. 30 times per second. Not sure if you really need this rate, I doubt the data is updating so fast... Perhaps you need a noLoop() in setup().
You do some unnecessary things, like two assignments to readVal (the first value is just overwritten), multiply lineWidth by 1, etc. But that's not the problem, of course.
I don't know how many columns you have, but you will draw the same lines over and over with various widths.
Likewise, perhaps you could println() row and col numbers to verify you do a loop at all.
Hey Breegeek,

I also don't have this library, so I pasted your coded and overwrited the values got from the library with a set of random(350), which I hope will give the same effect. What you should modify on your code is basically keep track of the last line drawn, that means, the X pos of the line, The line Width and its Left Margin. Every time you go through a cycle in the loop, you should increment this var with the value of the new line. Use this var as parameter (x1,x2) to draw your lines on the screen. I Hope that helps. Keep in mind that this is a very quick solution, I think the code can be revised and optimized a lot. Here it is:

float readVal;
float lineWidth;

void setup() {
  size(800,800);
  background(255);
  lineWidth = 3;
}
 

void draw(){
       background(255);
        float prevVal = 0;
        for (int r=0; r < 10 ; r++){             
          float tempVal = random(350);
              readVal = tempVal;
              readVal = map(readVal,0,350,0,4); //I have Changed to 0,4 to get more ticker lines.
              lineWidth = readVal;
              strokeWeight(1*lineWidth); 
              line(prevVal,0,prevVal,height);
              //This is where you should mod your code.
              prevVal += readVal + r + 5; // 5 is for the space between lines.;
              println(prevVal);
       }
       
}
Thanks guys! I managed to shore it up from your suggestions and am closer to understanding what I was doing wrong.

Also, I realized the mapping from 0 to 350 didnt match with my data, which was more 300-350, making the results less obvious when visualized.

Anyway, thanks for the help!