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()
相关推荐
炸炸鱼.21 分钟前
Python 操作 MySQL 数据库
android·数据库·python·adb
_深海凉_1 小时前
LeetCode热题100-颜色分类
python·算法·leetcode
AC赳赳老秦1 小时前
OpenClaw email技能:批量发送邮件、自动回复,高效处理工作邮件
运维·人工智能·python·django·自动化·deepseek·openclaw
zhaoshuzhaoshu2 小时前
Python 语法之数据结构详细解析
python
AI问答工程师2 小时前
Meta Muse Spark 的"思维压缩"到底是什么?我用 Python 复现了核心思路(附代码)
人工智能·python
zfan5203 小时前
python对Excel数据处理(1)
python·excel·pandas
小饕3 小时前
我从零搭建 RAG 学到的 10 件事
python
老歌老听老掉牙3 小时前
PyQt5+Qt Designer实战:可视化设计智能参数配置界面,告别手动布局时代!
python·qt
格鸰爱童话4 小时前
向AI学习项目技能(六)
java·人工智能·spring boot·python·学习
悟空爬虫-彪哥4 小时前
VRChat开发环境配置,零基础教程
python