python画玉桂狗代码
时间: 2023-10-12 20:13:31 浏览: 856
以下是使用Python绘制玉桂狗的代码:
```python
import turtle
# 绘制身体
def draw_body():
turtle.penup()
turtle.goto(0, -150)
turtle.pendown()
turtle.begin_fill()
turtle.color('#BC8F8F')
turtle.circle(150)
turtle.end_fill()
# 绘制头部
def draw_head():
turtle.penup()
turtle.goto(0, 0)
turtle.pendown()
turtle.begin_fill()
turtle.color('#BC8F8F')
turtle.circle(100)
turtle.end_fill()
# 绘制耳朵
def draw_ears():
turtle.penup()
turtle.goto(-55, 50)
turtle.pendown()
turtle.begin_fill()
turtle.color('#F4A460')
turtle.right(30)
turtle.forward(100)
turtle.left(120)
turtle.forward(100)
turtle.left(150)
turtle.forward(70)
turtle.end_fill()
turtle.penup()
turtle.goto(55, 50)
turtle.pendown()
turtle.begin_fill()
turtle.color('#F4A460')
turtle.right(180)
turtle.right(30)
turtle.forward(100)
turtle.left(120)
turtle.forward(100)
turtle.left(150)
turtle.forward(70)
turtle.end_fill()
# 绘制眼睛
def draw_eyes():
turtle.penup()
turtle.goto(-35, 80)
turtle.pendown()
turtle.begin_fill()
turtle.color('white')
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(35, 80)
turtle.pendown()
turtle.begin_fill()
turtle.color('white')
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(-35, 90)
turtle.pendown()
turtle.begin_fill()
turtle.color('black')
turtle.circle(10)
turtle.end_fill()
turtle.penup()
turtle.goto(35, 90)
turtle.pendown()
turtle.begin_fill()
turtle.color('black')
turtle.circle(10)
turtle.end_fill()
# 绘制鼻子
def draw_nose():
turtle.penup()
turtle.goto(0, 40)
turtle.pendown()
turtle.begin_fill()
turtle.color('black')
turtle.circle(20)
turtle.end_fill()
# 绘制嘴巴
def draw_mouth():
turtle.penup()
turtle.goto(-30, 0)
turtle.pendown()
turtle.right(90)
turtle.circle(30, 180)
# 绘制玉桂花
def draw_flower():
turtle.penup()
turtle.goto(20, -150)
turtle.pendown()
turtle.begin_fill()
turtle.color('yellow')
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(40, -130)
turtle.pendown()
turtle.begin_fill()
turtle.color('#8B0000')
turtle.left(45)
turtle.forward(30)
turtle.right(90)
turtle.forward(30)
turtle.right(135)
turtle.forward(42)
turtle.end_fill()
turtle.penup()
turtle.goto(-20, -150)
turtle.pendown()
turtle.begin_fill()
turtle.color('yellow')
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(-40, -130)
turtle.pendown()
turtle.begin_fill()
turtle.color('#8B0000')
turtle.left(45)
turtle.forward(30)
turtle.right(90)
turtle.forward(30)
turtle.right(135)
turtle.forward(42)
turtle.end_fill()
# 绘制玉桂狗
def draw_dog():
turtle.speed(0)
draw_body()
draw_head()
draw_ears()
draw_eyes()
draw_nose()
draw_mouth()
draw_flower()
turtle.done()
draw_dog()
```
该代码使用了Turtle库来绘制玉桂狗,其中分别绘制了身体、头部、耳朵、眼睛、鼻子、嘴巴以及玉桂花的部分。最后将这些部分组合在一起,便绘制出了一个玉桂狗的图案。
阅读全文