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

huangyanli00 2019-09-11

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

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

python & turtle

python的turtle库,最早还是在小甲鱼的【零基础入门学习Python】中接触的,好久没用了有些生疏,带大家一起回顾下模块的使用吧。

如果你是想认真学习这个库,推荐去官网仔细学习 https://docs.python.org/3.7/library/turtle.html

但如果你只是跟我一样玩票性质的,那么你简单看看就好。我帮你整理了一些常用的方法:

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

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

练习画月饼

话不多说,先来一波!

然后,还没开团呢,先送一血了…为什么pycharm会告警呢?

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

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

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

问题解决了,开始写吧:

相关推荐