ベクトルを表示するクラスを作成しようとしています。 1つのベクトルオブジェクトを作成すると、すべてが意図どおりに機能します。私のサンプルコードでは、オブジェクトlin1
はdraw()
関数の助けを借りて描画されます。2番目のオブジェクトを作成すると、クラスの関数がもう機能しなくなる
ここで2番目のベクトルオブジェクトを作成すると、オブジェクト自体は変更されていなくても、(変更されていない)描画関数は何も行いません。これは他の方法と同じです:第2のオブジェクトが唯一のものであるか、描画可能ですが、lin1
が存在しない限りです。
誰かが私の間違いを知っていますか?
vector lin;
vector lin2;
void setup()
{
size(500,500);
background(255);
cenX = width/2;
cenY = height/2;
noLoop();
}
void draw()
{
coordSys();
lin = new vector(0,0,100,100);
lin2 = new vector(0,0,-200,-200);
lin.draw();
lin2.draw();
lin.getAll();
}
class vector
{
float x1,y1,x2,y2;
float length;
float angle;
float gegenK, anK;
vector(float nx1, float ny1, float nx2, float ny2)
{
translate(cenX,cenY);
x1 = nx1; y1 = -ny1; x2 = nx2; y2 = -ny2;
strokeWeight(2);
// Gegenkathete
gegenK = ny2 - ny1;
// Ankathete
anK = x2 - x1;
// length and angle
length = sqrt(sq(anK) + sq(gegenK));
angle = winkel(gegenK, anK);
}
void draw()
{
stroke(0);
line(x1,y1,x2,y2);
}
}
}
あなたは 'lin2.getAll()'を呼び出すことはありません理由はありますか? – Ishnark
ソースコードを 'stroke()'と 'line()'に表示できますか? 'stroke(0)'は何をするのですか? –
これは処理内部関数です。線は線を描画し、線は線の色を設定します。 – user7948346