用python里的turtle库画一个杰尼龟
使用turtle库可以通过一系列指令来画出杰尼龟。以下是一个简单的例子:
import turtle
# 设置画布大小和背景颜色
turtle.setup(800, 600)
turtle.bgcolor("#F0E68C")
# 画杰尼龟的头部
turtle.penup()
turtle.goto(-50, 0)
turtle.pendown()
turtle.begin_fill()
turtle.circle(100)
turtle.end_fill()
# 画杰尼龟的眼睛
turtle.penup()
turtle.goto(-30, 50)
turtle.pendown()
turtle.begin_fill()
turtle.circle(15)
turtle.end_fill()
turtle.penup()
turtle.goto(-30, 50)
turtle.pendown()
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
turtle.penup()
turtle.goto(30, 50)
turtle.pendown()
turtle.begin_fill()
turtle.circle(15)
turtle.end_fill()
turtle.penup()
turtle.goto(30, 50)
turtle.pendown()
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
# 画杰尼龟的嘴巴
turtle.penup()
turtle.goto(-40, 0)
turtle.pendown()
turtle.setheading(-60)
turtle.circle(40, 120)
# 画杰尼龟的身体
turtle.penup()
turtle.goto(-50, -100)
turtle.pendown()
turtle.begin_fill()
turtle.circle(50)
turtle.end_fill()
# 画杰尼龟的四肢
turtle.penup()
turtle.goto(-80, -100)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(50, -100)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(-80, -160)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
turtle.penup()
turtle.goto(50, -160)
turtle.pendown()
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
# 完成绘制
turtle.done()
运行以上代码,将会在一个800x600的画布上绘制出一个杰尼龟的形状。你可以根据自己的需求进行调整和修改
原文地址: https://www.cveoy.top/t/topic/h6Nl 著作权归作者所有。请勿转载和采集!