在处理中蚀刻草图程序(java)(新程序员)

时间:2017-02-13 03:56:06

标签: java processing

我无法弄清楚如何让我的代码创建一个连续的行而不是一串点。 第一个问题是我的线函数是(posX,posY,posX,posY),这是创建点,但我不知道如何更改它以使其连续一行

float posX; //current mouseX position  
float posY; // current mouseY position  
float ballSpeed = 50f; //controls speed that the stylus moves  
final float OFF_SET = 250f; // allows ball to stay still if mouse is in center   of window  
void setup()  
{    
  size(500, 500);   
  posX= width/2; // next four lines of code make the stylus start in middle  
  posY=width/2;  

  background(255); //clears background once  
}  
void draw()  
{  

  drawLine(); //calls the drawLine function  
  moveStylus(); //calls the moveStylus function  
}  

void drawLine()  
{  
  line(posX, posY, posX, posY); //draws a  line starting previous to relative   mouse position and ending at to current to relative mouse position  
}  
void moveStylus()  
{  
  float moveX;   
  float moveY;  
  moveX = (mouseX-OFF_SET)/ballSpeed;  
  moveY = (mouseY-OFF_SET)/ballSpeed;  
  posX+= moveX;   
  posY+= moveY;  
  posX= max(width+1-width, posX);  // line will never leave right side of screen  
  posX = min(width-1, posX); //line will never leave left side of screen  
  posY= max(height+1-height, posY); //line will never leave bottom of screen  
  posY = min(width-1, posY); // line will never leave top of  screen  
}

1 个答案:

答案 0 :(得分:0)

看看这一行:

 line(posX, posY, posX, posY);

您在相同的坐标中传递线的起点和终点,只会绘制一个点。

如果你想绘制一条线,你将不得不为开始和结束传递不同的值。您可以将先前的位置存储在单独的变量中,也可以将下一个位置存储在临时变量中,绘制线条,然后通过将其指向临时值来更新当前位置。

但最终目标是为行的开头和结尾传递不同的值。