1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function generateShapes() {
let rows = document.getElementById("rows").value;
let shapesDiv = document.getElementById("shapes");
shapesDiv.innerHTML = "";
// 生成三角形
for (let i = 1; i <= rows; i++) {
shapesDiv.innerHTML += "&nbsp".repeat(rows - i) + "&nbsp *".repeat(i) + "<br>";
}
shapesDiv.innerHTML += "<br>";

// 生成平行四边形
for (let i = 1; i <= rows; i++) {
shapesDiv.innerHTML += "&nbsp".repeat(rows - i) + "&nbsp *".repeat(rows) + "<br>";
}
shapesDiv.innerHTML += "<br>";

// 生成菱形
for (let i = 1; i <= rows; i++) {
shapesDiv.innerHTML += "&nbsp&nbsp;".repeat(rows - i) + "&nbsp;*".repeat(i * 2 - 1) + "<br>";
}
for (let i = rows - 1; i >= 1; i--) {
shapesDiv.innerHTML += "&nbsp&nbsp;".repeat(rows - i) + "&nbsp;*".repeat(i * 2 - 1) + "<br>";
}
}