Код следующий:
Код: Выделить всё
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;
var circleX = x1;
var 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
Подробнее здесь: https://stackoverflow.com/questions/798 ... ut-it-back