Turtle库入门案例:Python一键画出海绵宝宝小可爱!! |
您所在的位置:网站首页 › 画海绵宝宝海绵宝宝 › Turtle库入门案例:Python一键画出海绵宝宝小可爱!! |
前文 嗨!!编程的小伙伴儿大家好,木木子又来了,不知道大家又没看我的文 章得出一个结论,那就是木木子很喜欢一些有代码的文章,像:画图的 哈哈 哈 自从学了python ,画图跟游戏项目的是必不可少的一个环节。 Turtle库是真的真的很好用!!!今天带大家看看童年的经典,海绵宝宝跟派大星看过没? 我看过,是不是有点儿暴露年龄了!哈哈哈 话不多说,开始画图啦! 环境安装:开发工具:pycharm 开发环境:python3.7, Windows10 使用工具包:turtle 海绵宝宝效果图: 项目思路解析(1)明确turtle基本配置,然后我们在确定画框的高度以及画笔的大小,还 有对应画框标题和画笔运行的速度。 screensize(800, 600, 'white') pensize(3) title('海绵宝宝') speed(19)(2)首先咱们调整画笔位置,找到对应原点位置。 def go_to(x, y): penup() goto(x, y) pendown()go_to(0, 0)(3)画出海绵宝宝的头部海绵,选取对应宽度,坐标大小可自行调整 定位的 函数可以重复使用,海绵宝宝周围为波浪线,添加上对应的弧度,添加上黄 色。 def head(): go_to(-200, 180) fillcolor('yellow') begin_fill() seth(-30) for _ in range(6): circle(36, 60) circle(-36, 60) seth(-125) for _ in range(5): circle(40,60) circle(-40,60) seth(-210) for _ in range(4): circle(45,60) circle(-45,60) seth(65) for _ in range(5): circle(40,60) circle(-40,60) end_fill()什么都没有的海绵宝宝身体。 给海绵宝宝添加上面部表情,眼睛的数据多为圆弧,鼻子为小倒勾尺寸可自行 调整。 乍一看就是一块大海绵。 (4)慢慢加上眼睛、睫毛...... def eye(): # 眼白 go_to(14, -5) fillcolor('#f0f0f0') begin_fill() circle(65, 360) end_fill() begin_fill() go_to(13,12) seth(98) circle(-65,360) end_fill() #眼球 go_to(-10,20) fillcolor('blue') begin_fill() circle(20,360) end_fill() go_to(-22,20) fillcolor('black') begin_fill() circle(7,360) end_fill() go_to(40,15) fillcolor('blue') begin_fill() circle(-20, 360) end_fill() go_to(53,15) fillcolor('black') begin_fill() circle(-7,360) end_fill() #睫毛 go_to(-95,65) left(20) forward(40) go_to(-50,87) right(25) forward(32) go_to(0,70) right(25) forward(40) go_to(40, 75) left(35) forward(40) go_to(90, 87) right(18) forward(30) go_to(120, 70) right(25) forward(40)def nose(): fillcolor('yellow') go_to(0, -7) begin_fill() right(50) circle(-60, 30) color('yellow') goto(15,-40) end_fill() color('black') go_to(0, -7) seth(-75) forward(30) go_to(30,-7) seth(-105) forward(30)这是画上眼睛的海绵宝宝。 (5)添加上嘴 加上海绵宝宝有代表性的大白牙。 def mouth(): go_to(-120, - 60) seth(-45) circle(200, 30) seth(0) forward(100) seth(15) circle(200, 30)def tooth(): go_to(-30,-114) seth(-95) fillcolor('white') begin_fill() forward(30) seth(0) forward(40) seth(95) forward(30) go_to(-30,-114) end_fill() go_to(30, -114) seth(-95) fillcolor('white') begin_fill() forward(30) seth(0) forward(40) seth(95) forward(30) go_to(60, -114) end_fill()加上大门牙的小家伙儿挺精神的。 效果图: (6)面部完成之后开始完善身体的一些结构增加小白衬衫和海绵宝宝的手 臂。 def body(): go_to(-170,-180) seth(-120) circle(150, 30) seth(0) forward(40) seth(100) forward(35) seth(-80) forward(100) fillcolor('brown') begin_fill() seth(0) forward(300) seth(80) forward(110) seth(-100) forward(65) seth(180) forward(315) go_to(-118,-400) end_fill() go_to(-170,-255) fillcolor('yellow') begin_fill() seth(-75) forward(80) seth(0) forward(17) seth(105) forward(85) end_fill() go_to(200, -170) seth(-60) circle(-150,30) seth(-180) forward(45) begin_fill() seth(0) forward(20) seth(-100) forward(85) seth(180) forward(20) end_fill()(7)你是不是觉得可以了,不不不,还有非常重要的一点,那就是它的红色 红领巾啦。 def tie(): go_to(-50,-225) seth(-40) forward(40) seth(30) forward(52) go_to(30,-225) seth(-30) forward(40) seth(40) forward(45) fillcolor('red') go_to(0, -240) begin_fill() seth(-60) forward(10) seth(0) forward(30) seth(60) forward(15) go_to(30,-225) end_fill() go_to(4,-250) begin_fill() seth(-100) forward(80) seth(0) forward(55) seth(100) forward(80) end_fill()结尾如视频对你有帮助,“关注点赞”和评论是对我最大的支持! 文章全部代码即可免费领取! 小编创建的小白学习群号:959755565。群资源免费拿,分享给大家一起学 习交流,有问题在群里也可以互相解答讨论,遇到问题比自己想几天都想不出 来不如别人的三言两语来的好。 👑 源码基地:关注小编公众号:Python顾木子吖 海量源码随你挑~最后记得点“再看”、“评论”、欢迎“转发”啦~ |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |