今天是端午节。首先祝大家端午节身体健康。或者喜欢传统的白粽子,你喜欢哪种粽子呢?在大家吃着好吃的粽子的时候,本文就为大家画了一盘粽子。作为先睹为快,我们来看看最终的效果图:从图中我们可以看出,整体由盘子、粽子、文字三部分组成。下面展开说一下相应的实现。盘子的实现首先我们来画一个盘子。板块的构成比较简单,就是一个椭圆加一个填充色。代码实现如下:#画一个平板defplate(a,b,angle,steps,rotateAngle):minAngle=(2*math.pi/360)*angle/stepsrotateAngle=rotateAngle/360*2*math.pipenup()#开始画笔setpos(b*math.sin(rotateAngle),-b*math.cos(rotateAngle))pendown()#pendownforiinrange(steps):nextPoint=[a*math.sin((i+1)*minAngle),-b*math.cos((i+1)*minAngle)]nextPoint=[nextPoint[0]*math.cos(rotateAngle)-nextPoint[1]*math.sin(rotateAngle),nextPoint[0]*math.sin(rotateAngle)+nextPoint[1]*math.cos(rotateAngle)]setpos(nextPoint)的效果如下:粽子实现接下来我们看一下本文的核心部分——粽子的实现。实现代码如下:#画粽子defrice_dumpling():pensize(2)#笔刷宽度pencolor(2,51,12)#笔刷颜色fillcolor(4,77,19)#填充颜色begin_fill()fd(200)#向前画圆(15,120)#画圆弧fd(200)circle(15,120)fd(200)circle(15,120)fd(200)circle(15,60)fd(100)circle(15,90)fd(173)circle(1,90)end_fill()penup()fd(100)right(60)back(105)a=pos()pendown()color(60,67,0)fillcolor(85,97,9)begin_fill()fd(120)goto(a)penup()back(15)left(90)fd(20)right(90)pendown()fd(150)right(120)fd(24)right(60)fd(120)right(60)fd(24)end_fill()begin_fill()left(110)fd(65)left(100)fd(24)left(80)fd(50)end_fill()效果如下:文字实现了,我们继续来看看如何添加文字。比如我要加的文字是:祝大家端午节身体健康。添加文本很容易。它只需要一行代码。代码如下:write("祝大家端午节身体健康",move=False,align="center",font=("ComicSans",18,"bold"))文章中的所有代码已经为大家整理好了,需要的话可以在公众号蟒蛇小二后台回复端午获取
