xxxxxxxxxx
void setup() {
size(800, 600);
background(255);
stroke(0);
drawTree(width / 2, height, 150, -HALF_PI, 8); // Adjust parameters as needed
}
void drawTree(float x, float y, float length, float angle, int depth) {
if (depth == 0) {
// Draw an ellipse at the end of the branch when depth is zero
fill(255, 0, 0); // Change the fill color of the ellipse as needed
ellipse(x, y, 10, 10); // Adjust the size of the ellipse as needed
return; // The base case for recursion - stop drawing when depth is zero
}
// Calculate the endpoint of the branch
float endX = x + cos(angle) * length;
float endY = y + sin(angle) * length;
// Draw the branch
line(x, y, endX, endY);
// Recursively call the function to draw smaller branches on each side
float newLength = length * 0.7; // Adjust the branch length scale factor as needed
int newDepth = depth - 1; // Decrease the depth to stop recursion eventually
drawTree(endX, endY, newLength, angle - PI / 4, newDepth); // Left branch
drawTree(endX, endY, newLength, angle + PI / 4, newDepth); // Right branch
}