Turtle母亲节爱心贺卡代码
时间: 2023-06-15 22:08:24 浏览: 1015
以下是一个简单的 Python Turtle 母亲节爱心贺卡代码:
```python
import turtle
# 画爱心函数
def draw_heart():
turtle.color('red')
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()
# 画字母函数
def draw_text():
turtle.penup()
turtle.goto(-80, 60)
turtle.pendown()
turtle.color('white')
turtle.write('Happy Mother\'s Day!', font=('Arial', 16, 'bold'))
# 画背景函数
def draw_background():
turtle.color('pink')
turtle.begin_fill()
turtle.goto(-250, -250)
turtle.setheading(0)
turtle.forward(500)
turtle.setheading(90)
turtle.forward(500)
turtle.setheading(180)
turtle.forward(500)
turtle.setheading(270)
turtle.forward(500)
turtle.end_fill()
# 主函数
def main():
turtle.speed(0)
draw_background()
draw_heart()
draw_text()
turtle.hideturtle()
turtle.done()
if __name__ == '__main__':
main()
```
运行代码后,会在窗口中显示一个粉色背景,上面画着一个红色的爱心和白色的文字“Happy Mother's Day!”。你可以根据自己的喜好修改颜色、字体和文字内容。
阅读全文