Python turtle drawing and drawing Mid-Autumn moon cake

I wish everyone a happy Mid-Autumn Festival! Not much to say, just go to the code!

Mid-Autumn Mooncake Code:

'''绘制中秋月饼'''
import turtle as t

t.bgcolor("#fdf291")        #设置背景颜色
t.title("中秋佳节")          #设置窗口名称
t.speed(0)                  #设置画笔速度:速度在0~10之间,数字越大速度越快。

'''绘制月饼第一层'''
t.pencolor("#af5125")       #设置月饼第一层颜色
t.dot(245)                  #绘制一个直径245像素的圆点
for i in range(16):         #循环遍历16次
    t.penup()               #起笔
    t.forward(110)          #抬笔前进110像素后画小圆点
    t.pendown()             #落笔
    t.dot(50)               #绘制一个直径50像素的小圆点
    t.penup()
    t.backward(110)         #画完小圆点,抬笔后退110像素,回到初始位置
    t.pendown()
    t.right(360/16)         #画笔旋转360/16的角度1,进入循环画下一个小圆点

'''绘制月饼第二层'''
t.pencolor("#fbbe11")
t.dot(230)
for i in range(16):
    t.penup()
    t.forward(105)
    t.pendown()
    t.dot(45)
    t.penup()
    t.backward(105)
    t.pendown()
    t.right(360/16)

'''绘制月饼第三层'''
t.pencolor("#ffed91")
t.dot(205)
l=92
for i in range(16):
    t.penup()
    t.forward(l)
    t.pendown()
    t.dot(40)
    t.penup()
    t.backward(l)
    t.pendown()
    t.right(360/16)

'''绘制月饼第四层'''
t.pencolor("#ffbe11")
t.dot(190)
x=85
for i in range(16):
    t.penup()
    t.forward(x)
    t.pendown()
    t.dot(38)
    t.penup()
    t.backward(x)
    t.pendown()
    t.right(360/16)

t.delay(0)              #用更快的速度画螺旋线
'''画棒棒糖螺旋线'''
def luoxuanxian():      #自定义函数
    t.pencolor("#e19420")   #设置画笔颜色
    t.pensize(4)        #设置画笔粗细
    for i in range(32):
        t.circle(1 * i, 10)     #绘制半径 1*i,角度为10的圆弧
        t.left(10)              #向左旋转10度后,进入循环画下一个圆

for j in range(16):             #画16个螺旋线
    t.left(360/16*j)            #当j为0时,画第一个螺旋线,画笔向左转
    t.penup()
    t.forward(78)               #画笔移动78像素后再开始画螺旋线
    t.pendown()
    luoxuanxian()               #调用自定义函数
    t.penup()
    t.home()                    #画完螺旋线,让画笔回到坐标原点
    t.pendown()

t.speed(5)                  #将速度减慢画后面的图形
t.delay(1)
'''画正六边形'''
t.delay(20)
t.pensize(6)
t.penup()
t.seth(-90)                 #让画笔头部朝下
t.forward(50)
t.seth(0)                   #让画笔头部朝右
t.pendown()
t.circle(50,360,6)          #画半径为50的正六边形

'''写文字'''
t.pencolor("#af5125")
t.penup()
t.home()
t.pendown()
t.write("中秋",align="center",font=("微软雅黑",20,"bold"))    #书写文字“”,居中显示,字体为微软雅黑,字号为20,文字加粗

t.penup()
t.goto(0,-30)           #画笔移动到(0,-30)
t.pendown()
t.write("快乐",align="center",font=("微软雅黑",20,"bold"))

t.hideturtle()          #隐藏箭头显示

operation result:

 illustrate:

(1) Command t.speed(n): Set the speed of the brush. The speed is between 0 and 10. The larger the number, the faster the speed. When the number is greater than 10 or less than 0.5, it is the fastest, which is equivalent to the number 0. It needs to be placed before the drawing of graphics starts to work.

(2) Background color

#fdf291 background color
#af5125 deep yellow
#fbbe11 medium yellow
#fed91 light yellow

Guess you like

Origin blog.csdn.net/weixin_45820024/article/details/126796882