How to draw simple flowers using Python?
To draw a simple flower with Python, you can use the turtle library. Below is an example code that draws a simple flower.
import turtle
# 设置画布大小和背景色
turtle.setup(width=800, height=600)
turtle.bgcolor("white")
# 设置画笔参数
turtle.pensize(2)
turtle.pencolor('red')
# 绘制花瓣
for _ in range(18):
turtle.forward(100)
turtle.right(100)
turtle.forward(100)
turtle.right(80)
# 绘制花蕊
turtle.pencolor('yellow')
turtle.circle(10)
# 隐藏画笔
turtle.hideturtle()
# 显示绘图窗口
turtle.done()
After running the code above, a window will pop up displaying the drawn flower. By adjusting the parameters in the code, you can draw flowers of different shapes and colors.