- Равносторонний треугольник длиной 100 см.
- Внутри каждого треугольника находится треугольник на 5 см внутрь.
- Внутри треугольника 5 см существует 25 треугольников.
Я использовал чат GPT и получил те же ответы.
Первый код и демо:
Код: Выделить всё
function drawEquilateralTriangle(ctx, x, y, size, color) {
const height = Math.sqrt(3) * size / 2;
ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x + size / 2, y + height);
ctx.lineTo(x - size / 2, y + height);
ctx.closePath();
ctx.strokeStyle = color;
ctx.stroke();
}
function drawSmallTriangles(ctx, x, y, size) {
const smallSize = 50;
const smallHeight = Math.sqrt(3) * smallSize / 2;
const rows = Math.floor(size / smallSize);
for (let row = 0; row < rows; row++) {
for (let col = 0; col
Подробнее здесь: [url]https://stackoverflow.com/questions/78710604/how-to-build-a-triangle-with-multiple-segments-on-canvas[/url]
Мобильная версия