使用Python的turtle库
方法一:
```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
import turtle
def draw_heart():
turtle.pencolor("red")
turtle.fillcolor("pink")
turtle.speed(5)
turtle.begin_fill()
turtle.left(45)
turtle.forward(100)
turtle.circle(50, 180)
turtle.right(90)
turtle.circle(50, 180)
turtle.forward(100)
turtle.end_fill()
turtle.hideturtle()
if __name__ == "__main__":
draw_heart()
```
方法三:
```python
import turtle
def draw_heart():
screen = turtle.Screen()
screen.title("爱心代码")
screen.bgcolor("white")
love = turtle.Turtle()
love.shape("turtle")
love.color("red")
love.speed(1)
love.begin_fill()
love.left(140)
love.forward(224)
love.circle(-112, 200)
love.left(120)
love.circle(-112, 200)
love.forward(224)
love.end_fill()
love.hideturtle()
turtle.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() ``` 使用其他编程语言 方法一
```c
include
int main() {
printf(" \n"); printf(" * * * *\n"); printf(" printf("* * * *\n"); printf("*\n"); printf("* * * *\n"); printf(" printf(" * * * *\n"); printf(" return 0; } ``` 方法二
在支持Unicode的编辑器或文本输入框中,输入以下字符组合:
```
<3
```
这些方法涵盖了从简单的Python脚本到复杂的数学图形绘制,你可以根据自己的需求和编程水平选择合适的方法来绘制爱心。