python动态爱心烟花代码
时间: 2023-09-12 22:03:13 浏览: 46
python爱心烟花代码
好的,以下是Python动态爱心烟花代码:
```python
import turtle
import random
def draw_heart(x, y, color):
turtle.up()
turtle.goto(x, y)
turtle.down()
turtle.color(color)
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_firework(x, y):
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
turtle.up()
turtle.goto(x, y)
turtle.down()
turtle.color(random.choice(colors))
turtle.begin_fill()
for i in range(5):
turtle.forward(25)
turtle.right(144)
turtle.end_fill()
turtle.undo()
def main():
turtle.hideturtle()
turtle.tracer(0)
for i in range(25):
draw_heart(random.randint(-300, 300), random.randint(-300, 300), "red")
for i in range(100):
draw_firework(random.randint(-400, 400), random.randint(-400, 400))
turtle.update()
if __name__ == '__main__':
main()
```
希望您喜欢这个代码!
阅读全文