drawing - Processing in Java - drawn clearing rectangle breaks after calling a method -


i using processing in java perpetually draw line graph. requires clearing rectangle draw on drawn lines make room new part of graph. works fine, when call method, clearing stops working did before. clearing works drawing rectangle in front of line at

below 2 main methods involved. drawgraph function works fine until call redrawgraph redraws graph based on zoom. think center variable cause of problem cannot figure out why.

public void drawgraph()      {          checkzoom();          int currentvalue = seismograph.getcurrentvalue();          int lastvalue = seismograph.getlastvalue();          step = step + zoom;          if(step>offset){              if(restartdraw == true)              {                  drawongraphics(step-zoom, lasty2, step, currentvalue);                  image(graphgraphics, 0, 0);                  restartdraw = false;              }else{                               drawongraphics(step-zoom, lastvalue, step, currentvalue);              image(graphgraphics, 0, 0);              }          }                                                   // draw graph (connect last current point                                                                          // increase step - x axis          float xclear = step+10;                                                                          // being clearing area in front of current graph          if (xclear>width - 231)  {              xclear = offset - 10;                                                                       // adjust far side of screen          }          graphgraphics.begindraw();          if (step>graphsizex+offset)  {                                                                  // draw 2 clearing rectangles when graph isn't split  //             left = bg.get(0, 0, math.round(step-graphsizex), height - 200);                                                 // capture clearing rectangle left side of background image  //             graphgraphics.image(left, 0, 0);                                                                           // print left clearing rectangle  //             if (step+10<width)  {  //             right = bg.get(math.round(step+10), 0, width, height - 200);                                                 // capture clearing rectangle right side of background image  //                 // print right clearing rectangle  //             }           }  else  {                                                                                     // draw 1 clearing rectangle when graph split                    center = bg.get(math.round(xclear), lasty2, offset,  height - 200);                                // capture clearing rectangle center of background image                    graphgraphics.image(center, xclear - 5, 0);// print center clearing rectangle          }           if (step > graphsizex+offset)  {                                                                           // reset set when graph reaches end                    step = 0+offset;              }           graphgraphics.enddraw();           image(graphgraphics, 0 , 0);           system.out.println("step: " + step + " zoom: " + zoom + " currentvalue: "+ currentvalue + " lastvalue: " + lastvalue);       }

private void redrawgraph()                                                      //resizes graph when zooming {     checkzoom();     object[] data = seismograph.thedata.toarray();     cleargraph();     step = offset;     int y2, y1 = 0;     int zoomsize = (int)((width - offset) / zoom);     int tempcount = 0;     graphgraphics.begindraw();     graphgraphics.strokeweight(2);                                                                                     // line thickness     graphgraphics.stroke(242,100,66);     graphgraphics.smooth();     while(tempcount < data.length)         {             try             {                 y2 = (int)data[tempcount];                 step = step + zoom;                 if(step > offset && y1 > 0 && step < graphsizex+offset){                     graphgraphics.line(step-zoom, y1, step, y2);                 }                 y1 = y2;                 tempcount++;                 lasty2 = y2;             }             catch (exception e)             {                 system.out.println(e.tostring());             }         }     graphgraphics.enddraw();     image(graphgraphics, 0, 0);     restartdraw = true;     }  

any , criticisms welcome. thank valuable time.

i'm not sure if approach best. can try simple this:

// learning processing // daniel shiffman // http://www.learningprocessing.com  // example: graph of random numbers  float[] vals;  void setup() {   size(400,200);   smooth();   // array of random values   vals = new float[width];   (int = 0; < vals.length; i++) {     vals[i] = random(height);   } }   void draw() {    background(255);   // draw lines connecting points   (int = 0; < vals.length-1; i++) {     stroke(0);     strokeweight(2);     line(i,vals[i],i+1,vals[i+1]);   }    // slide down in array   (int = 0; < vals.length-1; i++) {     vals[i] = vals[i+1];    }   // add new random value   vals[vals.length-1] = random(height);//use seismograph.getcurrentvalue(); here instead  } 

you can same using pgraphics buffer code suggests:

// learning processing // daniel shiffman // http://www.learningprocessing.com  // example: graph of random numbers  float[] vals;  pgraphics graph;  void setup() {   size(400,200);   graph = creategraphics(width,height);    // array of random values   vals = new float[width];   (int = 0; < vals.length; i++) {     vals[i] = random(height);   } }   void draw() {   graph.begindraw();   graph.background(255);   // draw lines connecting points   (int = 0; < vals.length-1; i++) {     graph.stroke(0);     graph.strokeweight(2);     graph.line(i,vals[i],i+1,vals[i+1]);   }   graph.enddraw();   image(graph,0,0);     // slide down in array   (int = 0; < vals.length-1; i++) {     vals[i] = vals[i+1];    }   // add new random value   vals[vals.length-1] = random(height);//use seismograph.getcurrentvalue(); here instead  } 

the main idea cycle newest data in array , draw values shifting array. long clear previous frame (background()) graph should ok.


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -