Rounded Triangles

Rounded Triangles ....
Originally, I just want to design a logo...

Inspired by Rounded rectangle 💳

Log in to post a comment.

const sideLength = 10; // Length of the sides of the triangle
const borderRadius = 2; // Radius of the rounded corners
const turtle = new Turtle();


function drawRoundedTriangle(x, y, side, cornerRadius) {
    turtle.radians();

    // Calculate the height of the triangle
    const height = side/Math.sqrt(3) - cornerRadius ;

    // Calculate the offset caused by the rounded corners
    const cornerOffset = cornerRadius * (1 - Math.cos(Math.PI / 6));

    // Calculate the starting position
    const startX = x - side / 2;
    const startY = y -( cornerRadius + side/(2. * Math.sqrt(3)));

    // Position the turtle at the starting point
    turtle.penup();
    turtle.goto(startX, startY);
    turtle.pendown();

    // Function to draw a side and a rounded corner
    function drawSideAndCorner() {
        turtle.forward(side);
        turtle.circle(cornerRadius, 2 * Math.PI / 3); // 120 degrees for a triangle's corner
    }

    // Draw the triangle
    for (let i = 0; i < 3; i++) {
        drawSideAndCorner();
    }
}

const yOffset = -10;
// The walk function will be called until it returns false.
function walk(i) {
    drawRoundedTriangle(Math.random()*2 -1, yOffset + Math.random()*2 -1, sideLength + i*0.01, borderRadius+0.25*i);
    drawRoundedTriangle(0, yOffset, sideLength + 110 + i*4, borderRadius+0.2*i);
    return i < 100;
}