使用Python的turtle库
打开文本编辑器 ,如Notepad或VSCode。输入以下代码
```python
import turtle
def draw_heart():
penup()
goto(0, -100)
pendown()
color('red')
begin_fill()
setheading(150)
circle(200, 90)
left(90)
circle(200, 90)
end_fill()
hideturtle()
draw_heart()
turtle.done()
```
运行代码,将会看到一个红色的爱心形状出现在屏幕上。
使用Python的matplotlib库
安装matplotlib库(如果尚未安装):
```bash
pip install matplotlib
```
输入以下代码 ```python import numpy as np import matplotlib.pyplot as plt t = np.linspace(0, 2 * np.pi, 1000) x = 16 * np.sin(t)3 y = 13 * np.cos(t) - 5 * np.cos(2*t) - 2 * np.cos(3*t) - np.cos(4*t) plt.figure(figsize=(8, 6)) plt.plot(x, y, color='red') plt.fill(x, y, color='red', alpha=0.6) plt.title('Python Heart') plt.axis('equal') plt.grid(True) plt.show() ```运行代码
,将会看到一个红色的爱心形状出现在屏幕上。
使用JavaScript
创建一个HTML文件,例如`index.html`。
输入以下代码
```html