您现在的位置是:群英 > 开发技术 > Python语言
怎么用python画一个猪脑袋的效果
Admin发表于 2022-05-09 17:22:161518 次浏览
这篇文章给大家分享的是“怎么用python画一个猪脑袋的效果”,文中的讲解内容简单清晰,对大家认识和了解都有一定的帮助,对此感兴趣的朋友,接下来就跟随小编一起了解一下“怎么用python画一个猪脑袋的效果”吧。


用python画猪头的方法:首先设置画布和画笔,代码为【a.screensize(400,300)a.setup(width=400,height=300)】;然后画脸型,代码为【.goto(-100,100)】;最后留存图像在画布上即可。

用python画猪头的方法:

画布和画笔设置

import turtle as a
a.screensize(400,300)//设置屏幕大小
a.setup(width=400,height=300)//设置画布大小
a.pensize(15)//设置画笔宽度
a.speed(5)//设置画笔速度
a.hideturtle()//隐藏画笔

画脸盘子

a.penup()//提笔
a.goto(-100,100)//移动画笔位置
a.setheading(180)//设置朝向正西
a.pencolor("pink")
a.pendown()//放笔
a.circle(200)

取名字

a.penup()//取名
a.goto(-150,10)
yourname=a.textinput("请老实回答","你的名字是?")
name=yourname+"崽崽"
a.pendown()
a.write(name,font=("elephant",25,"bold"))//打印文本

画眼睛

a.penup()//画左眼
a.goto(-200,0)
a.pendown()
a.circle(25)
a.penup()
a.goto(-200,-14)
a.pendown()
a.circle(9)
a.penup()//光晕
a.goto(-190,-20)
a.pencolor("white")
a.pendown()
a.dot(10)
a.penup()//画右眼
a.pencolor("pink")
a.goto(0,0)
a.pendown()
a.circle(25)
a.penup()//光晕
a.goto(0,-14)
a.pendown()
a.circle(9)
a.penup()
a.goto(-10,-20)
a.pencolor("white")
a.pendown()
a.dot(10)

画鼻子

a.penup()//画鼻子
a.speed(10)//设置画笔速度
a.pencolor("pink")
a.goto(-150,-75)
a.setheading(45)
a.pendown()
for i in range(90):
    a.forward(1.5)
    a.right(1)
for i in range(3): //圆化棱角,每转16度向前走3个像素
    a.right(16)
    a.forward(3)
a.forward(15)
for i in range(3): //圆化棱角
    a.right(16)
    a.forward(3)
a.setheading(225)
for i in range(90):
    a.forward(1.5)
    a.right(1)
for i in range(3): //圆化棱角
    a.right(16)
    a.forward(3)
a.forward(15)
for i in range(3): //圆化棱角
    a.right(16)
    a.forward(3)
a.penup()
a.speed(5)//设置画笔速度
a.goto(-125,-70)//第一条杠
a.setheading(270)
a.pendown()
a.forward(50)
a.penup()
a.goto(-70,-65)//第二条杠
a.pendown()
a.forward(55)

画嘴巴

a.penup()//画嘴巴
a.speed(10)//设置画笔速度
a.goto(-135,-165)
a.setheading(305)
a.pendown()
for i in range(120):
    a.forward(1)
    a.left(1)

画耳朵

a.penup()//画右耳朵
a.speed(5)
a.setheading(0)
a.goto(-17,90)
a.pendown()
a.forward(60)
a.penup()
a.goto(28,75)//跳到下一笔起始位置
a.setheading(45)
a.pendown()
a.forward(110)
a.right(45)
a.forward(40)
a.setheading(225)
a.forward(40)
a.setheading(270)
for i in range(7): //圆化棱角
    a.right(2.5)
    a.forward(10)
a.forward(80)
a.penup()//画左耳朵
a.goto(-183,90)
a.setheading(180)
a.pendown()
a.forward(60)
a.penup()
a.goto(-230,75)//跳到下一笔起始位置
a.setheading(135)
a.pendown()
a.forward(110)
a.left(45)
a.forward(40)
a.setheading(-45)
a.forward(40)
a.setheading(270)
for i in range(10): //圆化棱角
    a.left(2.5)
    a.forward(15)

画腮红

a.penup()//画左腮红
a.pencolor("tomato")//设置成番茄色
a.goto(-250,-100)
a.setheading(270)
a.pendown()
a.forward(20)
a.penup()
a.goto(-210,-100)
a.pendown()
a.forward(20)
a.penup()//画右腮红
a.goto(10,-100)
a.pendown()
a.forward(20)
a.penup()
a.goto(50,-100)
a.pendown()
a.forward(20)
a.done() //留存图像在画布上

献上完整源代码

#!/usr/bin/env python3.7 #指明用什么可执行程序运行这个文件代码
#-*- coding:UTF-8 -*-   #保证能顺利解析中文
#author:Boosirit time:2020/4/5
import turtle as a
a.screensize(400,300)#设置屏幕大小
a.setup(width=400,height=300)#设置画布大小
a.pensize(15)#设置画笔宽度
a.speed(5)#设置画笔速度
a.hideturtle()#隐藏画笔
a.penup()#画脸
a.goto(-100,100)
a.setheading(180)#设置朝向正西
a.pencolor("pink")
a.pendown()
a.circle(200)
a.penup()#取名
a.goto(-150,10)
yourname=a.textinput("请老实回答","你的名字是?")
name=yourname+"崽崽"
a.pendown()
a.write(name,font=("elephant",25,"bold"))#打印文本
a.penup()#画左眼
a.goto(-200,0)
a.pendown()
a.circle(25)
a.penup()
a.goto(-200,-14)
a.pendown()
a.circle(9)
a.penup()#光晕
a.goto(-190,-20)
a.pencolor("white")
a.pendown()
a.dot(10)
a.penup()#画右眼
a.pencolor("pink")
a.goto(0,0)
a.pendown()
a.circle(25)
a.penup()#光晕
a.goto(0,-14)
a.pendown()
a.circle(9)
a.penup()
a.goto(-10,-20)
a.pencolor("white")
a.pendown()
a.dot(10)
a.penup()#画鼻子
a.speed(10)#设置画笔速度
a.pencolor("pink")
a.goto(-150,-75)
a.setheading(45)
a.pendown()
for i in range(90):
    a.forward(1.5)
    a.right(1)
for i in range(3):#圆化棱角,每转16度向前走3个像素
    a.right(16)
    a.forward(3)
a.forward(15)
for i in range(3):#圆化棱角
    a.right(16)
    a.forward(3)
a.setheading(225)
for i in range(90):
    a.forward(1.5)
    a.right(1)
for i in range(3):#圆化棱角
    a.right(16)
    a.forward(3)
a.forward(15)
for i in range(3):#圆化棱角
    a.right(16)
    a.forward(3)
a.penup()
a.speed(5)#设置画笔速度
a.goto(-125,-70)#第一条杠
a.setheading(270)
a.pendown()
a.forward(50)
a.penup()
a.goto(-70,-65)#第二条杠
a.pendown()
a.forward(55)
a.penup()#画嘴巴
a.speed(10)#设置画笔速度
a.goto(-135,-165)
a.setheading(305)
a.pendown()
for i in range(120):
    a.forward(1)
    a.left(1)
    
a.penup()#画右耳朵
a.speed(5)
a.setheading(0)
a.goto(-17,90)
a.pendown()
a.forward(60)
a.penup()
a.goto(28,75)#跳到下一笔起始位置
a.setheading(45)
a.pendown()
a.forward(110)
a.right(45)
a.forward(40)
a.setheading(225)
a.forward(40)
a.setheading(270)
for i in range(7):#圆化棱角
    a.right(2.5)
    a.forward(10)
a.forward(80)
a.penup()#画左耳朵
a.goto(-183,90)
a.setheading(180)
a.pendown()
a.forward(60)
a.penup()
a.goto(-230,75)#跳到下一笔起始位置
a.setheading(135)
a.pendown()
a.forward(110)
a.left(45)
a.forward(40)
a.setheading(-45)
a.forward(40)
a.setheading(270)
for i in range(10):#圆化棱角
    a.left(2.5)
    a.forward(15)
    
a.penup()#画左腮红
a.pencolor("tomato")#设置成番茄色
a.goto(-250,-100)
a.setheading(270)
a.pendown()
a.forward(20)
a.penup()
a.goto(-210,-100)
a.pendown()
a.forward(20)
a.penup()#画右腮红
a.goto(10,-100)
a.pendown()
a.forward(20)
a.penup()
a.goto(50,-100)
a.pendown()
a.forward(20)
a.done()#留存图像在画布上

关于“怎么用python画一个猪脑袋的效果”的内容就介绍到这,感谢各位的阅读,相信大家对怎么用python画一个猪脑袋的效果已经有了进一步的了解。大家如果还想学习更多知识,欢迎关注群英网络,小编将为大家输出更多高质量的实用文章!

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。

标签: python编程画猪
相关信息推荐
2022-05-16 11:37:28 
摘要:作为一个前端开发,在浏览别人家的页面时总是会习惯性的查看他们页面的源码,发现大多数网站的页面中用到的最多的布局元素无外乎就是div、p、span、ul、dl、ol、li、dt、dd、strong、b,不管是什么样的效果都是由这些元素组成。
2022-07-22 17:16:10 
摘要:python中导入模块的关键字是import。import语法:【import 模块名1 [as 别名1], 模块名2 [as 别名2], 模块名n [as 别名n]】。如果要使用模块中的成员,那么需要使用模块名作为前缀。
2022-02-16 18:08:24 
摘要:这篇文章我们来了解PHP中include的作用、使用及需要注意的问题,对大家学习和理解include有帮助,下文有详细的介绍,有需要的朋友可以参考,接下来就跟随小编来一起学习一下吧!
群英网络助力开启安全的云计算之旅
立即注册,领取新人大礼包
  • 联系我们
  • 24小时售后:4006784567
  • 24小时TEL :0668-2555666
  • 售前咨询TEL:400-678-4567

  • 官方微信

    官方微信
Copyright  ©  QY  Network  Company  Ltd. All  Rights  Reserved. 2003-2019  群英网络  版权所有   茂名市群英网络有限公司
增值电信经营许可证 : B1.B2-20140078   粤ICP备09006778号
免费拨打  400-678-4567
免费拨打  400-678-4567 免费拨打 400-678-4567 或 0668-2555555
微信公众号
返回顶部
返回顶部 返回顶部