Plot an entire array
in
Programming Questions
•
22 days ago
Hi to everyone.
I have the following problem.
I would like to plot an array in a processing sketch but not one element at the time, everytime the entire array in a plot window of the same size of the entire array.
Now I´m using eclipse and processing together, so my code is the following:
- public void setup(){
- size(1000,300);
- background(0);
- this.serialString=new String("0,0,0");
- //this.serialInt=0;
- }
- public void draw(){
- if (this.serialString != null) {
- // xpos=0;
- //for (int i = 0; i < array_length-1; i++) {
- // set the drawing color. Pick a pretty color:
- stroke(123,128,158);
- //stroke(115);
- if (xpos >= width) {
- xpos = 0;
- // clear the screen by resetting the background:
- background(0);
- }
- else {
- // increment the horizontal position for the next reading:
- xpos++;
- }
- //System.out.println("(int)this.arraySerial[i]: "+(int)this.arraySerial[i]);
- // draw the line:
- //line(xpos, height, xpos, height - (int)this.serialInt/10);
- line(xpos, height, xpos, height - (int)this.arraySerial[0]);
- //line(i,(int)this.arraySerial[i],i+1,(int)this.arraySerial[i+1]);
- //point(xaxis,this.arraySerial);
- //xpos++;
- //}
- }
This sketch is related to the last of these 3 graphs and as you can see it is working ok.
But as I said I would like to print the entire array time to time. Is it possible?
My group leader told me that, he said that we should have a window of the same size of the array even if I didn´t really understand what he meant. I will also try to ask him again because to me it seems ok to do it in this way.
The graph is updated in real time and I have also the storage of the array so I can implement averaging functions and stuff like that.
Thanks for your time,
Fab.
1