189 8069 5689

通过Turtle库在Python中绘制一个鼠年福鼠-创新互联

turtle库是一个很经典的绘图库,其最初来自于1967年创造的logo编程语言,之后被Python编写放到了Python的内置模块中。网络上有很多借助于turtle绘制精美图像的案例。比如小猪佩奇、皮卡丘、柯基犬等等。趁着新年假期还未结束,今天州的先生(https://zmister.com)为大家带来一个福鼠的绘制。

创新互联是一家专注于成都网站设计、做网站与策划设计,安吉网站建设哪家好?创新互联做网站,专注于网站建设10多年,网设计领域的专业建站公司;建站业务涵盖:安吉等地区。安吉做网站价格咨询:13518219792

一、绘制鼠头

首先,咱们(https://zmister.com)把鼠的头给绘制了。鼠头主要是由圆来构成,脸庞是一个大圆,耳朵、眉毛、眼睛、嘴角和鼻子也都是由不同弧度的圆构成。鼠头的绘制代码如下所示:

def head():
 turtle.color('black')

 # 脸轮廓
 turtle.pd() # 落笔
 turtle.circle(50) # 画一个半径为50的圆
 turtle.pu() # 提笔

 # 右耳轮廓
 turtle.goto(50,60) # 移动到x=50,y=60的位置
 turtle.pd() # 落笔
 turtle.circle(30,260) # 画一个半径为30,角度为245的圆弧
 turtle.pu() # 提笔
 # 右耳耳纹
 turtle.goto(30,90)
 turtle.pd()
 turtle.seth(65)
 turtle.circle(-30,70)
 turtle.pu()

 # 左耳轮廓
 turtle.goto(-50,60)
 turtle.pd()
 turtle.seth(180) # 设置方向为西,
 turtle.circle(-30,260)
 turtle.pu()
 # 左耳耳纹
 turtle.goto(-30,90)
 turtle.pd()
 turtle.seth(120)
 turtle.circle(30,70)
 turtle.pu()

 # 面部五官
 # 右侧眉毛
 turtle.goto(5,80)
 turtle.seth(20)
 turtle.pd()
 turtle.circle(-25,40)
 turtle.pu()
 # 左侧眉毛
 turtle.goto(-5,80)
 turtle.seth(160)
 turtle.pd()
 turtle.circle(25,40)
 turtle.pu()

 # 右侧眼睛
 turtle.begin_poly()
 turtle.goto(8,60)
 turtle.seth(45)
 turtle.pd()
 turtle.circle(-15,120)
 turtle.pu()
 turtle.goto(8,60)
 turtle.seth(40)
 turtle.pd()
 turtle.circle(-15,100)
 turtle.pu()
 turtle.end_poly()

 # 左侧眼睛
 turtle.goto(-8,60)
 turtle.seth(135)
 turtle.pd()
 turtle.circle(15,120)
 turtle.pu()
 turtle.goto(-8,60)
 turtle.seth(140)
 turtle.pd()
 turtle.circle(15,100)
 turtle.pu()

 # 鼻子
 # 鼻子上瓣
 turtle.goto(-6,45)
 turtle.seth(70)
 turtle.pd()
 turtle.circle(-6,150)
 turtle.pu()
 # 鼻子下瓣
 turtle.goto(-6,45)
 turtle.seth(-70)
 turtle.pd()
 turtle.circle(6,150)
 turtle.pu()

 # 鼻线
 turtle.goto(0,40)
 turtle.seth(270)
 turtle.pd()
 turtle.forward(7)
 turtle.pu()

 # 上嘴线
 turtle.seth(200)
 turtle.pd()
 turtle.circle(-15,60)
 turtle.pu()

 turtle.goto(0,33)
 turtle.seth(-20)
 turtle.pd()
 turtle.circle(15,60)
 turtle.pu()

 # 下嘴线
 turtle.goto(10,33)
 turtle.seth(260)
 turtle.pd()
 turtle.circle(-15,65)
 turtle.pu()

 turtle.goto(-10,33)
 turtle.seth(280)
 turtle.pd()
 turtle.circle(15,65)
 turtle.pu()

 # 牙齿
 turtle.goto(4,33)
 turtle.seth(270)
 turtle.pd()
 turtle.forward(4)
 turtle.seth(180)
 turtle.forward(8)
 turtle.seth(90)
 turtle.forward(4)
 turtle.pu()

 # 胡须
 turtle.pensize(2)
 turtle.goto(30,30)
 turtle.seth(8)
 turtle.pd()
 turtle.circle(-60,40)
 turtle.pu()

 turtle.goto(30,25)
 turtle.seth(-5)
 turtle.pd()
 turtle.circle(-60,40)
 turtle.pu()


 turtle.goto(-30,30)
 turtle.seth(172)
 turtle.pd()
 turtle.circle(60,40)
 turtle.pu()

 turtle.goto(-30,25)
 turtle.seth(188)
 turtle.pd()
 turtle.circle(60,40)
 turtle.pu()

 # 睫毛
 turtle.pensize(1)
 turtle.goto(30,58)
 turtle.seth(20)
 turtle.pd()
 turtle.circle(20,20)
 turtle.pu()

 turtle.pensize(1)
 turtle.goto(28,62)
 turtle.seth(25)
 turtle.pd()
 turtle.circle(20,12)
 turtle.pu()

 turtle.pensize(1)
 turtle.goto(-30,58)
 turtle.seth(160)
 turtle.pd()
 turtle.circle(-20,20)
 turtle.pu()

 turtle.pensize(1)
 turtle.goto(-28,62)
 turtle.seth(165)
 turtle.pd()
 turtle.circle(-20,12)
 turtle.pu()

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章题目:通过Turtle库在Python中绘制一个鼠年福鼠-创新互联
URL地址:http://jkwzsj.com/article/jjgeg.html

其他资讯