2
我無法弄清楚如何讓我的代碼創建一個連續的線條而不是一串點。 第一個問題是,我的線功能(POSX,波西,POSX,波西),這是產生點,但我不知道如何去改變它,這樣它絡繹不絕蝕刻處理中的素描程序(java)(新程序員)
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
}
line(posX,posY,posX,posY)的調用令人擔憂。這是否意味着「從(posX,posY)開始並在(posX,posY)結束」畫一條線?最後兩個參數可能應該與前兩個不同。 –