2017-02-13 9 views
2

コードでドットの代わりに連続した行を作成する方法を理解できません。処理中のスケッチプログラムをエッチする(新しいプログラマー)

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 
} 
+0

行の呼び出し(posX、posY、posX、posY)が気になるです。 「(posX、posY)で始まり(posX、posY)で終わる行を描く」という意味ですか?最後の2つの引数は最初の2つとは異なるはずです。 –

答えて

0

ように、その連続線、この行を見 最初の問題は、私のライン機能(POSX、POSY、POSX、POSY)で、これはドットを形成していることですが、私はそれを変更する方法見当がつかない:

line(posX, posY, posX, posY); 

1つの点だけを描画する線の開始点と終了点に同じ座標を渡しています。

行を描画する場合は、開始と終了の値を別々に渡す必要があります。以前の位置を別々の変数に格納することもできますし、次の位置を一時変数に格納して線を描画し、一時的な値をポイントすることで現在の位置を更新することもできます。

しかし最終目標は、行の開始と終了のために異なる値を渡すことです。

関連する問題