0
我正在嘗試可視化一些數據,並且我需要交互性。我代表我想要形象化爲像太陽系一樣移動的球的實體。爲了獲得這個我使用了旋轉和平移。但是,當我使用距離函數來顯示實體的名稱時,它會發生故障並在其他位置顯示名稱,並且交互需要在其他位置進行,這與我的想法不同。以下是帶有註釋的代碼的簡化版本。對dist函數p5js應用旋轉。旋轉導致dist發生故障
//the angle (t) and theta factor as tt
var t=0;
var tt=0.01;
function setup()
{
//creating canvas to darw
createCanvas(600,600);
}
function draw()
{
background(255);
//translating the 0,0 point to the center of the canvas
translate(width/2,height/2);
//applying rotation on the matrix
rotate(1);
//gaining circular movement through sine and cosine oscillation
x=sin(t)*100;
y=cos(t)*50;
//drawing the ball
ellipse(x,y,10,10);
//when the mouse is inside the ball, a text is supposed to appear with the ball that says "on it"
if(dist(mouseX,mouseY,width/2+x,height/2+y)<5)
{
text("on it",x,y);
}
//incrementing the angle
t+=tt;
}
感謝您的幫助。我一定會檢查出來。 –