编写五星红旗和爱心的代码
时间: 2023-10-29 14:55:19 浏览: 63
以下是用Python语言编写五星红旗和爱心的代码:
五星红旗代码:
```
import turtle
# 设置画布大小
turtle.setup(800, 600)
# 画红旗
turtle.penup()
turtle.goto(-300, 200)
turtle.pendown()
turtle.color('red')
turtle.begin_fill()
for i in range(2):
turtle.forward(600)
turtle.right(90)
turtle.forward(400)
turtle.right(90)
turtle.end_fill()
# 画大星星
turtle.penup()
turtle.goto(-250, 120)
turtle.pendown()
turtle.color('yellow')
turtle.begin_fill()
turtle.right(75)
for i in range(5):
turtle.forward(100)
turtle.right(144)
turtle.end_fill()
# 画小星星1
turtle.penup()
turtle.goto(-95, 170)
turtle.pendown()
turtle.begin_fill()
turtle.right(75)
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 画小星星2
turtle.penup()
turtle.goto(-95, 70)
turtle.pendown()
turtle.begin_fill()
turtle.right(75)
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 画小星星3
turtle.penup()
turtle.goto(-30, 120)
turtle.pendown()
turtle.begin_fill()
turtle.right(75)
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
# 画小星星4
turtle.penup()
turtle.goto(-160, 120)
turtle.pendown()
turtle.begin_fill()
turtle.right(75)
for i in range(5):
turtle.forward(40)
turtle.right(144)
turtle.end_fill()
turtle.done()
```
爱心代码:
```
import turtle
# 设置画布大小
turtle.setup(600, 600)
# 画爱心
turtle.penup()
turtle.goto(0, -150)
turtle.pendown()
turtle.color('red', 'pink')
turtle.begin_fill()
turtle.left(45)
turtle.forward(200)
turtle.circle(-100, 180)
turtle.right(90)
turtle.circle(-100, 180)
turtle.forward(200)
turtle.end_fill()
# 写上“爱你”
turtle.penup()
turtle.goto(0, 0)
turtle.color('white')
turtle.write("爱你", font=('Arial', 40, 'bold'), align="center")
turtle.done()
```
阅读全文