您的位置:首页 > 编程语言 > Python开发

使用Python为中秋节绘制一块美味的月饼

2019-09-12 11:40 1891 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/devcloud/article/details/100737880

每逢佳节…

对于在外的游子,每逢佳节倍思亲。而对于996ICU的苦逼程序猿们,最期待的莫过于各种节假日能把自己丢在床上好好休息一下了。这几天各公司都陆续开始发中秋礼品了。朋友圈各种秀高颜值的月饼,所以今天我也提前给大家送去一份中秋的美味月饼吧!

python & turtle

python的turtle库,最早还是在小甲鱼的【零基础入门学习Python】中接触的,好久没用了有些生疏,带大家一起回顾下模块的使用吧。
如果你是想认真学习这个库,推荐去官网仔细学习 https://docs.python.org/3.7/library/turtle.html
但如果你只是跟我一样玩票性质的,那么你简单看看就好。我帮你整理了一些常用的方法:

参数 说明
turtle.setup(width,height,startx,starty) 起始点坐标:左上角相对于屏幕的坐标,默认在屏幕中央
turtle.begin_fill() 准备开始填充图形
turtle.end_fill() 填充完成
turtle.goto(x,y) 将海龟走到该坐标位置 绝对坐标
turtle.bk(d) 海龟后退 海龟坐标
turtle.fd(d) 海龟前进
turtle.circle(r,angle) 海龟左侧某一点为圆心曲线运行
turtle.seth(angle) 海龟转向,绝对坐标
turtle.left(angle) 左转
turtle.right(angle) 右转
penup() 抬起画笔
pendown() 落下画笔
pencolor() 笔的颜色
pensize() 笔的大小
turtle.colormode(mode) 改变RGB模式,mode=1.0小数值,mode=255整数值 RGB颜色,如white的RGB整数值为:255.255.255,修改数值可以改变颜色
turtle.done() 画完之后不关闭窗口

就以上这些完全够你强势装13了…

练习画月饼

话不多说,先来一波!
然后,还没开团呢,先送一血了…为什么pycharm会告警呢?

但是使用又是正常的好奇怪,网上搜了一下解决办法。从import turtle进入源码,把142行开始的all注释掉,手动引用下turtle的所有方法即可。

[code]# __all__ = (_tg_classes + _tg_screen_functions + _tg_turtle_functions +
#            _tg_utilities + ['Terminator']) # + _math_functions)

__all__ = ['ScrolledCanvas', 'TurtleScreen', 'Screen', 'RawTurtle', 'Turtle', 'RawPen', 'Pen', 'Shape', 'Vec2D', 'back',
'backward', 'begin_fill', 'begin_poly', 'bk', 'addshape', 'bgcolor', 'bgpic', 'bye', 'clearscreen',
'colormode', 'delay', 'exitonclick', 'getcanvas', 'getshapes', 'listen', 'mainloop', 'mode', 'numinput',
'onkey', 'onkeypress', 'onkeyrelease', 'onscreenclick', 'ontimer', 'register_shape', 'resetscreen',
'screensize', 'setup', 'Terminator', 'setworldcoordinates', 'textinput', 'title', 'tracer', 'turtles',
'update', 'window_height', 'window_width', 'write_docstringdict', 'done', 'circle', 'clear', 'clearstamp',
'clearstamps', 'clone', 'color', 'degrees', 'distance', 'dot', 'down', 'end_fill', 'end_poly', 'fd',
'fillcolor', 'filling', 'forward', 'get_poly', 'getpen', 'getscreen', 'get_shapepoly', 'getturtle', 'goto',
'heading', 'hideturtle', 'home', 'ht', 'isdown', 'isvisible', 'left', 'lt', 'onclick', 'ondrag', 'onrelease',
'pd', 'pen', 'pencolor', 'pendown', 'pensize', 'penup', 'pos', 'position', 'pu', 'radians', 'right', 'reset',
'resizemode', 'rt', 'seth', 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setx',
'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle', 'speed', 'st', 'stamp', 'tilt',
'tiltangle', 'towards', 'turtlesize', 'undo', 'undobufferentries', 'up', 'width', 'write', 'xcor', 'ycor']

问题解决了,开始写吧:

看看效果:

 

The End

OK,今天的内容就到这里,如果觉得内容对你有所帮助,欢迎点赞。

期待你关注我的公众号 清风Python,如果觉得不错,希望能动动手指转发给你身边的朋友们。

作者:清风Python

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: