[英]why aren't these ellipses being placed correctly?
顯然,我需要練習更多的技巧。 我試圖位置的數字圈等於categories.length
圍繞中心軸。 這是我正在使用的代碼(p5.js):
var categoryX, categoryY;
for (var j=0; j<categories.length; j++){
categoryX = width/2 + (250*cos(frameCount/3000) * cos(j*PI/categories.length));
categoryY = height/2 + (250*sin(frameCount/3000) * cos(j*PI/categories.length));
ellipse(categoryX, categoryY, 250, 250);
圓應隨時間移動(因此為frameCount),但也應沿圓的不同弧度開始。 此代碼無效。
誰能告訴我為什么?
您不應該將(余弦)正弦相乘。 而是將它們的參數加在一起以用於一個(余弦)正弦。 我還認為您想用2π而不是π來固定j ,因此您覆蓋了中心點周圍的整個弧:
cos(frameCount/3000 + j*2*PI/categories.length)
正弦相同。
因此,代碼將變為:
var categoryX, categoryY;
for (var j=0; j<categories.length; j++){
categoryX = width/2 + 250*cos(frameCount/3000 + j*2*PI/categories.length);
categoryY = height/2 + 250*sin(frameCount/3000 + j*2*PI/categories.length);
ellipse(categoryX, categoryY, 250, 250);
// ...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.