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()
相关推荐
szephyr1 分钟前
用 Python 写自动化脚本:定时任务、文件批处理、自动出报表
python·自动化·pandas·脚本·定时任务
wuyk5555 分钟前
Python实战项目01:简易记事本系统
开发语言·python
凤城老人11 分钟前
从零手写开源私有云盘|Flask+Vue3+Electron全栈网盘,单容器一键部署
python·docker·electron·vue
lpfasd12323 分钟前
配置文件格式对比 与 AI Coding 的选择逻辑
python·flask·numpy
2601_9628857226 分钟前
如何用 Python 把 A 股行情批量导出到 Excel/CSV?(多股票多 Sheet)
python
2601_962218611 小时前
万象生鲜系统多终端统一数据协议PC手机PDA数据实时同步
大数据·数据库·人工智能·python·算法
科技苑1 小时前
Python AI自动剪辑视频简易程序
人工智能·python
夜雪一千1 小时前
Python爬虫实战:把Bootstrap栅格Div伪表格转为原生Table表格
python
“AI国潮设计-小江”2 小时前
【SDXL实战】Python自动化生成3D潮汕美食IP,附ComfyUI工作流与商用变现思路
开发语言·人工智能·python·prompt·aigc
tellmewhoisi2 小时前
python的鬼畜写法(从js角度看)
python