       newFaces.push([c, ca, bc]);
        newFaces.push([ab, bc, ca]);
    }

    return subdivide(newVertices, newFaces, level - 1);
}

function normalize(vertices) {
    return vertices.map(v => {
        const length = Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
        return [v[0] / length, v[1] / length, v[2] / length];
    });
}

function draw() {
    ctx.clearRect(0, 0, canvas.width, canvas.height);
    ctx.strokeStyle = 'rgba(0, 0, 0, 0.3)';
    ctx.fillStyle = 'rgba(0, 0, 0, 0.1)';

    l