本文是利用python语言来实现写对联
以下是运行结果和代码:
大家可以在此代码的基础上进行修改,改成自己喜欢的文字,祝大家新年快乐哟~
import turtle
turtle.speed(3)
# 绘制右边红色矩形
turtle.penup()
turtle.goto(95, 150)
turtle.pendown()
turtle.color("red", "red")
turtle.begin_fill()
for _ in range(2):
turtle.forward(60)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.end_fill()
# 在右边矩形上写字
turtle.penup()
turtle.goto(100, -250)
turtle.pendown()
turtle.color("black")
turtle.write("一\n帆\n风\n顺\n年\n年\n好", font=("华文行楷", 40))
# 绘制左边红色矩形
turtle.penup()
turtle.goto(-155, 150)
turtle.pendown()
turtle.color("red", "red")
turtle.begin_fill()
for _ in range(2):
turtle.forward(60)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.end_fill()
# 在左边矩形上写字
turtle.penup()
turtle.goto(-150, -250)
turtle.pendown()
turtle.color("black")
turtle.write("万\n事\n如\n意\n步\n步\n高", font=("华文行楷", 40))
# 绘制横批矩形
turtle.penup()
turtle.goto(-100, 190)
turtle.pendown()
turtle.color("red", "red")
turtle.begin_fill()
for _ in range(2):
turtle.forward(210)
turtle.left(90)
turtle.forward(60)
turtle.left(90)
turtle.end_fill()
# 在横批矩形上写字
turtle.color("black")
turtle.write("五福临门", font=("华文行楷", 40))
turtle.hideturtle()
turtle.done()