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()
相关推荐
飞翔的佩奇5 小时前
【完整源码+数据集+部署教程】【天线&水】舰船战舰检测与分类图像分割系统源码&数据集全套:改进yolo11-repvit
前端·python·yolo·计算机视觉·数据集·yolo11·舰船战舰检测与分类图像分割系统
木头左6 小时前
最大回撤约束下ETF多因子动态止盈参数校准方案
python
汤姆yu6 小时前
2026版基于python的协同过滤音乐推荐系统
开发语言·python
汤姆yu6 小时前
基于python的电子商务管理系统
开发语言·python
may_一一7 小时前
pycharm\python 安装下载
ide·python·pycharm
后台开发者Ethan7 小时前
FastAPI之 Python的类型提示
python·fastapi·ai编程
hello kitty w7 小时前
Python学习(11) ----- Python的泛型
windows·python·学习
没有梦想的咸鱼185-1037-16637 小时前
AI Agent结合机器学习与深度学习在全球气候变化驱动因素预测中的应用
人工智能·python·深度学习·机器学习·chatgpt·数据分析
测试19989 小时前
Selenium自动化测试+OCR-获取图片页面小说详解
自动化测试·软件测试·python·selenium·测试工具·ocr·测试用例
闲人编程9 小时前
使用MLflow跟踪和管理你的机器学习实验
开发语言·人工智能·python·机器学习·ml·codecapsule