怎么编程做一个爱心图形

时间:2025-01-28 07:28:35 网络游戏

Python 使用 turtle 库

```python

from turtle import *

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()

done()

```

Python 使用 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', fontsize=18)

plt.axis('equal')

plt.grid(True)

plt.show()

```

JavaScript 使用 HTML5 Canvas

```html

Your browser does not support the HTML5 canvas tag.