怎么编程出等边三角形

时间:2025-01-29 03:17:44 网络游戏

1. 使用Python的turtle库

```python

import turtle

def draw_equilateral_triangle(length, color):

turtle.penup()

turtle.goto(-length/2, length/2)

turtle.pendown()

turtle.color(color)

for _ in range(3):

turtle.forward(length)

turtle.left(120)

设置画布和三角形参数

turtle.setup(800, 600)

draw_equilateral_triangle(100, "blue")

turtle.done()

```

2. 使用JavaScript和HTML/CSS

```html