Код следующий:
Код: Выделить всё
var circleY;
var circleX;
stroke(0, 0, 0);
var bob = function(text1,x1,y1){
noFill();
var textWidthValue = textWidth(text1); // Get the width of the text
stroke(0, 0, 0);
var circleDiameter = max(circleDiameter, textWidthValue + 40);
var circleRadius = circleDiameter/2;
circleX = x1;
circleY = (3 / 5) * height - circleRadius;
line(x1,y1,x1,y1-(3 / 5) * height);
stroke(0, 0, 0);
// Calculate text width and adjust circle diameter
circleDiameter = max(circleDiameter, textWidthValue + 40);
circleRadius = circleDiameter/2;
// Ensure circle can fit text
stroke(0, 0, 0);
// Draw the circle
fill(255, 0, 0);
ellipse(circleX, circleY, circleDiameter, circleDiameter);
fill(255, 0, 0); // Set text color to red
textAlign(CENTER, CENTER);
// Draw the text centered inside the circle
text(text1, circleX, circleY);
};
bob("Bob is Your uncle",256,784);
text("circleX, circleY", circleX, circleY);
Кроме того, я задавал вопрос на Ханакадемии и пока не получил ответов. если хотите, вы можете увидеть это по адресу: https://www.khanacademy.org/computer-pr ... 4092969984
Я понял, что если я удалю var из второго определения CircleX и CircleY, я смогу обновить вместо переопределения переменных. Теперь текст отладки полностью исчез и (вероятно) находится поверх круга! ура! Раньше я был в замешательстве, теперь нет четкого пути вперед!
Подробнее здесь: https://stackoverflow.com/questions/798 ... ut-it-back