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()
相关推荐
感谢地心引力1 天前
【Python】基于 PyQt6 和 Conda 的 PyInstaller 打包工具
数据库·python·conda·pyqt·pyinstaller
xiaohanbao091 天前
Transformer架构与NLP词表示演进
python·深度学习·神经网络
love530love1 天前
【笔记】 Podman Desktop 中部署 Stable Diffusion WebUI (GPU 支持)
人工智能·windows·笔记·python·容器·stable diffusion·podman
程序员晚枫1 天前
Python 3.14正式发布!这5大新特性太炸裂了
python
先做个垃圾出来………1 天前
SortedList
python
这里有鱼汤1 天前
从DeepSeek到Kronos,3个原因告诉你:Kronos如何颠覆传统量化预测
后端·python·aigc
晓宜1 天前
Java25 新特性介绍
java·python·算法
深栈1 天前
机器学习:决策树
人工智能·python·决策树·机器学习·sklearn
MediaTea1 天前
Python:匿名函数 lambda
开发语言·python
hui函数1 天前
Python全栈(基础篇)——Day07:后端内容(函数的参数+递归函数+实战演示+每日一题)
后端·python