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;
}
感谢您的帮助。我一定会检查出来。 –