Turtle画图(一)

图片一

py 复制代码
import turtle
t = turtle.Turtle()

t.goto(-100,0)
t.pensize(5) #设置外花边的大小
t.color('red', 'yellow') #参数一是笔画颜色,参数二是填充颜色
t.begin_fill()
for i in range(0, 20):
  t.forward(200)
  t.left(170)
    
t.end_fill()
t.done()

图片二 :画一个狮子

绘制过程

效果如下 :

然后绘制 眼睛鼻子 :

补全其他部分 :

最后绘制三角形组合的鬓毛即可。

结果与代码

py 复制代码
import turtle


# 画圆形, 颜色为 color, 圆心为 (x, y), 半径为 radius
def draw_circle(color, x, y, radius):
    turtle.penup()  # 提笔,不画线
    turtle.goto(x, y - radius)
    turtle.pendown()  # 落笔,开始画线
    turtle.color(color)
    turtle.begin_fill()
    turtle.circle(radius)
    turtle.end_fill()

# """ 画鬃毛 """

def draw_mane():
    turtle.penup()
    turtle.goto(0, -120)
    turtle.pendown()
    turtle.color("orange")
    for _ in range(36):
        turtle.begin_fill()
        turtle.circle(40, steps=3)  # 三角形鬃毛
        turtle.end_fill()
        turtle.right(10)


def draw_lion():
    turtle.speed(10)  # value 可以是 0 到 10 之间的整数, 10 是最快
    turtle.bgcolor("white")

    # 画鬃毛
    draw_mane()

    # 画头部
    draw_circle("goldenrod", 0, -50, 100)

    # 画眼睛
    draw_circle("white", -40, 30, 20)
    draw_circle("white", 40, 30, 20)
    draw_circle("black", -35, 35, 8)
    draw_circle("black", 35, 35, 8)

    # 画鼻子
    draw_circle("black", 0, 0, 15)

    # 画嘴巴(微笑曲线)
    turtle.penup()
    turtle.goto(-20, -20)
    turtle.pendown()
    turtle.width(3)
    turtle.setheading(-60)  # setheading(angle) 直接将乌龟的方向调整到指定的角度,而不是相对旋转。
    turtle.circle(20, 120)

    # 画耳朵
    draw_circle("goldenrod", -60, 60, 30)
    draw_circle("goldenrod", 110, 60, 30)

    # 画耳朵内部
    draw_circle("peru", -70, 65, 15)
    draw_circle("peru", 100, 65, 15)

    turtle.hideturtle()


draw_lion()
turtle.done()
相关推荐
取个名字真难呐44 分钟前
相对位置2d矩阵和kron运算的思考
人工智能·pytorch·python·深度学习·线性代数·矩阵
珈百列1 小时前
如何在jupyter notebook中使用django框架
ide·python·jupyter
旧厂街小江1 小时前
LeetCode第93题:复原IP地址
c++·python·算法
憨憨睡不醒啊1 小时前
自从有了Trae,让我实现从 conda 到 uv 的 Python 包管理自由😋😋😋
python·llm·trae
自由鬼2 小时前
企业在本地部署 Hugging Face后如何微调
人工智能·python·深度学习
没逻辑2 小时前
深入 Python 性能分析:工具与实战指南
后端·python
带娃的IT创业者2 小时前
《Python实战进阶》第32集:使用 TensorFlow 构建神经网络
python·神经网络·tensorflow
CodeCraft Studio2 小时前
Excel处理控件Aspose.Cells指南:如何在不使用 Microsoft Excel 的情况下解锁 Excel 工作表
python·microsoft·excel
这里有鱼汤2 小时前
一篇文章搞定Python数据分析用到的所有库
后端·python·程序员
这里有鱼汤2 小时前
Python自动化办公宝典,一篇文章搞定文档处理:PDF、Word、Excel文档全攻略
后端·python·程序员