Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java绘制的清除矩形中的处理在调用方法后中断_Java_Drawing_Processing - Fatal编程技术网

Java绘制的清除矩形中的处理在调用方法后中断

Java绘制的清除矩形中的处理在调用方法后中断,java,drawing,processing,Java,Drawing,Processing,我正在使用Java中的处理来永久地绘制一个线图。这需要一个空白矩形在绘制的直线上绘制,以便为图形的新部分腾出空间。一切都很好,但是当我调用一个方法时,清除会像以前一样停止工作。基本上,清理工作是在线条当前所在位置的前面绘制一个矩形 以下是涉及的两种主要方法。drawGraph函数工作正常,直到我调用redrawGraph,它根据缩放重新绘制图形。我认为中心变量是问题的原因,但我不知道为什么 public void drawGraph() { checkZoom(); int currentVa

我正在使用Java中的处理来永久地绘制一个线图。这需要一个空白矩形在绘制的直线上绘制,以便为图形的新部分腾出空间。一切都很好,但是当我调用一个方法时,清除会像以前一样停止工作。基本上,清理工作是在线条当前所在位置的前面绘制一个矩形

以下是涉及的两种主要方法。drawGraph函数工作正常,直到我调用redrawGraph,它根据缩放重新绘制图形。我认为中心变量是问题的原因,但我不知道为什么

public void drawGraph()
{
checkZoom();
int currentValue=地震仪。getCurrentValue();
int lastValue=seismograph.getLastValue();
步长=步长+缩放;
如果(步骤>偏移){
if(restartDraw==true)
{
DrawongGraphics(步长缩放、lastY2、步长、当前值);
图像(图形,0,0);
restartDraw=false;
}否则{
DrawongGraphics(步长缩放、lastValue、步长、currentValue);
图像(图形,0,0);
}
}//绘制图形(最后连接到当前点//增加步长-x轴
float xClear=step+10;//正在清除当前图形前面的区域
如果(xClear>宽度-231){
xClear=offset-10;//调整屏幕的远端
}
graphGraphics.beginDraw();
如果(step>graphSizeX+offset){//在图形未拆分时绘制两个清除矩形
//left=bg.get(0,0,Math.round(step graphSizeX),高度-200);//从背景图像的左侧捕获清除矩形
//graphGraphics.image(左,0,0);//打印左清除矩形
//如果(步骤+10 graphSizeX+偏移量){//当图形到达终点时重置设置
步长=0+偏移量;
}
graphGraphics.endDraw();
图像(图形,0,0);
System.out.println(“步骤:+step+”缩放:+zoom+”当前值:+currentValue+“lastValue:+lastValue”);

}
我不确定这种方法是否是最好的。您可以尝试以下简单方法:

//学习处理
//丹尼尔·希夫曼
// http://www.learningprocessing.com
//示例:随机数的图形
浮动[]VAL;
无效设置(){
尺寸(400200);
光滑的();
//随机值数组
VAL=新浮动[宽度];
对于(int i=0;i
您可以使用PGraphics缓冲区轻松地执行代码建议的相同操作:

// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example: a graph of random numbers

float[] vals;

PGraphics graph;

void setup() {
  size(400,200);
  graph = createGraphics(width,height);

  // An array of random values
  vals = new float[width];
  for (int i = 0; i < vals.length; i++) {
    vals[i] = random(height);
  }
}


void draw() {
  graph.beginDraw();
  graph.background(255);
  // Draw lines connecting all points
  for (int i = 0; i < 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 everything down in the array
  for (int i = 0; i < vals.length-1; i++) {
    vals[i] = vals[i+1]; 
  }
  // Add a new random value
  vals[vals.length-1] = random(height);//use seismograph.getCurrentValue(); here instead

}
//学习处理
//丹尼尔·希夫曼
// http://www.learningprocessing.com
//示例:随机数的图形
浮动[]VAL;
图形;
无效设置(){
尺寸(400200);
图形=创建图形(宽度、高度);
//随机值数组
VAL=新浮动[宽度];
对于(int i=0;i

其主要思想是循环数组中的最新数据,并简单地从这个移位数组中提取值图表看起来应该没问题。

如果你发布了一篇文章,你的运气会好得多。我刮去了旧代码,并根据这种方法重新编写了它,它使代码更干净。谢谢。很酷,很高兴它起作用。如果有帮助,你可以投票/标记答案。谢谢:)
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example: a graph of random numbers

float[] vals;

PGraphics graph;

void setup() {
  size(400,200);
  graph = createGraphics(width,height);

  // An array of random values
  vals = new float[width];
  for (int i = 0; i < vals.length; i++) {
    vals[i] = random(height);
  }
}


void draw() {
  graph.beginDraw();
  graph.background(255);
  // Draw lines connecting all points
  for (int i = 0; i < 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 everything down in the array
  for (int i = 0; i < vals.length-1; i++) {
    vals[i] = vals[i+1]; 
  }
  // Add a new random value
  vals[vals.length-1] = random(height);//use seismograph.getCurrentValue(); here instead

}