首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在处理中蚀刻草图程序(Java)(新程序员)

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

Stack Overflow用户
提问于 2017-02-13 11:56:06
回答 1查看 350关注 0票数 2

我不知道如何让我的代码创建一条连续的线,而不是一串点。第一个问题是我的直线函数是(posX,posY,posX,posY),这是在创建点,但我不知道如何改变它,使其成为一条连续的直线

代码语言:javascript
复制
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  
}
EN

回答 1

Stack Overflow用户

发布于 2017-02-13 12:46:41

看这一行:

代码语言:javascript
复制
 line(posX, posY, posX, posY);

您将为直线的起点和终点传入相同的坐标,这将只绘制一个点。

如果你想画一条线,你必须为起点和终点传入不同的值。您可以将前一个位置存储在单独的变量中,也可以将下一个位置存储在临时变量中,绘制直线,然后通过将当前位置指向临时值来更新当前位置。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42196463

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档