// Forked from "Barnsley fern" by reinder
// https://turtletoy.net/turtle/7e604ce874

const levels = 50; // min=5, max=50, step=1
const baseSize = 130; // min=10, max=200, step=10
const scaleFactor = 0.96; // min=0.5, max=0.99, step=0.01
const curveFactor = 105; // min=10, max=200, step=5

Canvas.setpenopacity(1);

const turtle = new Turtle();

function drawStupa(levels, size, scaleFactor, curveFactor) {
    for (let i = 0; i < levels; i++) {
        // Draw a rounded layer of the stupa
        turtle.circle(size / 2, curveFactor); // Draw an arc
        turtle.right(180 - curveFactor); // Adjust for symmetry
        turtle.circle(size / 2, curveFactor); // Draw the other side of the arc
        
        // Move up to the next smaller layer
        turtle.penup();
        turtle.forward(size * (1 - scaleFactor) / 2);
        turtle.right(90);
        turtle.forward(size * (1 - scaleFactor) / 2);
        turtle.left(90);
        turtle.pendown();
        
        // Reduce the size for the next layer
        size *= scaleFactor;
    }
}

// Move the turtle to a starting position for better centering
turtle.penup();
turtle.goto(0,0);
turtle.pendown();

// Draw a stupa with parameters
drawStupa(levels, baseSize, scaleFactor, curveFactor);