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);
У меня возникла проблема при обработке JS, из-за которой мой круг не отображается. Код следующий: [code]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); [/code] Кроме того, я задавал вопрос в Ханакадемии и пока не получил ответов. если хотите, вы можете увидеть его на: https://www.khanacademy.org/computer-programming/skill-tree/5042474092969984