Spend the Mid-Autumn Festival with code, do you want to try the python turtle mooncake?

        Table of contents:

1. Mid-Autumn Festival blessings in 2022

Second, the main method of Python turtle drawing

(1) The main steps of turtle drawing

(2) Coordinate system of turtle drawing

(3) Some suggestions for turtle drawing

3. Common commands for turtle drawing

1. Initialization

2. Brush properties

3. Brush motion command

4. Brush color control command

5. Global control commands

4. Appreciation of pictures of Mid-Autumn Mooncakes

5. Collection of "Drawing Mooncakes with Code" series:​

1. Snowskin Mooncake

2. Crossin brand "moon cake"

3. Fortune Mooncake

4. Patterned moon cakes

5. MATLAB draws a 2.5D moon cake

6. 2022 Mid-Autumn Festival Programmer Portfolio


1. Mid-Autumn Festival blessings in 2022

   The theme of this 2022 CSDN Mid-Autumn Festival essay is 100 ways for programmers to celebrate the Mid-Autumn Festival. Am I a programmer? the answer is negative. If a person can clearly position himself as soon as possible, he can achieve the ultimate in a certain aspect, and the sooner he can make achievements, this method is correct. Everyone's talents are different, and life experiences are also different. I didn't position myself at a certain fixed point, because I think many things seem to be unrelated, but they are related. Once you understand, you can find and understand some. . .

  The world is changing every day, especially the rapid progress of some high-tech (not referring to a certain aspect, but a combination of various high-tech), sometimes it really makes people feel. . . If something incredible happens to you, don't be afraid, take care of yourself, and cherish everyone around you who is kind to you. Don't be complacent easily, there will always be people and groups who are better than you in this world.

  The topic is too far away, let's talk about the Mid-Autumn Festival. Programmers can use code to weave a unique blessing for the Mid-Autumn Festival and send a unique gift to the people around them. For example, custom moon cakes with codes, custom mid-autumn greeting cards, and more.

  This Mid-Autumn Festival, I used python to draw moon cakes for everyone. The python animation picture concept: picturesque mountains and rivers, bright moon in the sky, melodious piano music , and sober adversity. I will use the platform of CSDN to share the Mid-Autumn Festival moon cakes with you. I wish everyone a happy Mid-Autumn Festival!

  I still laugh and sigh after walking for half my life. May you let go of the sorrow and cold in the world, and see the gains and losses as plain. May you be happy and never be alone, and let happiness permeate. May the starlight guide you in the darkness, and the fireflies have clear eyes to distinguish between true and false. May there always be strength behind you, and may you be your own sun! May you stay forever!

Second, the main method of Python turtle drawing

  Turtle drawing (turtle library) is an internal module of python, you can import turtleku before use

  Turtles have several key properties: orientation, position and brush properties

(1) The main steps of turtle drawing

  Usually when we draw

  The first step is to import the turtle library and some libraries that may be used in drawing, such as random function library random, numpy library, etc., depending on the actual situation.

  Instructions:

  import turtle

  import random

  

  The second step, use setup() to set the canvas size

  Canvas:

  The canvas is the area we use for drawing, we can set its size and initial position

  Set canvas size:

  1. turtle.screensize(canvwidth=None, canvheight=None, bg=None)

  The parameters are the width (unit pixel), height, and background color of the canvas.

  turtle.screensize() default size (400, 300)

  Example: turtle.screensize(800, 600, "black")

  2. turtle.setup(width=value, height=value, startx=None, starty=None)

  setup() sets the size and position of the form.

  parameter:

  width, height: when it is an integer, it means pixels;

  width, height: when it is a decimal, it means the proportion of the computer screen

  turtle.setup(width=0.5, height=0.85, startx=None, starty=None)

  turtle.setup(width=0.6, height=0.6)

  (startx, starty): This coordinate represents the position of the upper left corner of the rectangular window. If it is empty, the window is at the center of the screen

  如:turtle.setup(width=800, height=800, startx=100, starty=100)

  The third step, set the brush

  Use Pen() to set the turtle drawing object, that is, the brush: turtle.Pen()

  t = turtle.Pen()

  Use t instead of turtle.Pen(). A once-and-for-all approach that simplifies entering code.

(2) Coordinate system of turtle drawing

  After the code is executed, the canvas is created, and the turtle (arrow) can be seen in the middle of the screen.

  In the turtle drawing, the starting point of the turtle, that is, the center of the canvas is (0,0), the moving unit is pixel (pixel), and the head of the turtle is the x-axis direction, which is 0 degrees.

    In turtle drawing, the position and direction are used to describe the state of the turtle (brush).

  Imagine a robotic turtle in the drawing area, starting at (0, 0) in the xy plane. Execute import turtle first, then execute turtle.forward(15), which will advance (on the screen) 15 pixels in the positive x-axis direction it is facing, drawing a line segment as it moves. Then execute turtle.right(25), it will turn right in place 25 degrees.

  Two words are used to describe turtles: the origin of coordinates (position), facing the positive x-axis (direction),

  During the drawing process, if the coordinates and angles are not specified, then all angles and positions are relative (relative to the current position and angle of the turtle) .

Circles are often used to draw moon cakes: turtle.circle(radius, extent=None, steps=None)

parameter:

  • radius -- a numeric value

  • extent -- a number (or None)

  • steps -- an integer (or None)

  Draws a circle with the radius specified by radius.

  The center of the circle is radius units to the left of the turtle;

  extent is an included angle used to determine a part of the drawn circle. If extent* is not specified, the entire circle is drawn. If *extent is not a full circumference, an arc is drawn with the current pen position as an endpoint. The arc is drawn in a counterclockwise direction if radius is positive, clockwise otherwise.

  Eventually the orientation of the turtle will change according to the value of extent.

  The circle is actually approximated by its inscribed regular polygon, with the number of sides specified by steps.

  If the number of sides is not specified, it is automatically determined. This method can also be used to draw regular polygons.

  Draw a circle with a radius of 100, circle(100). Note that the center of the circle is not at the origin after drawing.

(3) Some suggestions for turtle drawing

      a. Using Turtle Drawing, you can write programs that repeat simple actions to draw intricate and complex shapes.

from turtle import *

speed(0)

color('blue', '#87CEFA')

begin_fill()

while True:

    forward(200)

    left(170)

    if abs(pos()) < 1:

        break

end_fill()

Arrange text in a circle:

import turtle as t

text="I wish everyone a happy Mid-Autumn Festival"

for i in text:

    t.write(i,align="center",font=("黑体",20,"normal"))

    t.right(360/len(text))

    t.penup()   

    t.forward(40)

t.hideturtle()

t.done()

  b. Hide the brush; set the speed, you can draw faster;

  c. For the color code of turtle drawing, please refer to the following link

Color color comparison table series (1~5) 300 colors, (hexadecimal, RGB, CMYK, HSV, Chinese and English names)

    Pick out the color you like, copy the corresponding color code value and put it into the turtle color settings.

3. Common commands for turtle drawing

1. Initialization

code command

effect

import turtle

Import the turtle library

t = turtle.Pen()

Get the Turtle Brush from the Toolbox

turtle.setup()

Canvas settings (dimensions, distances)

turtle.bgcolor("black")

Canvas background color (e.g. black)

screensize( )  

Set the width, height and background color of the canvas window

2. Brush properties

code command

effect

turtle.pensize(width numeric value)

Brush thickness, set the thickness of the brush line to the specified size

turtle.color('brush color')

brush color string "green", "red" or RGB 3-tuple

turtle.speed(0)

Set the brush movement speed

The speed range of the brush to draw is an integer in the range of [0, 10], the larger the number, the slower the brush speed. Value 1~9, 0 is the fastest t.speed(0)

turtle.hideturtle()

Hide turtle icon (hide brush arrow)

turtle.showturtle()

Show turtle icon (show brush arrow)

3. Brush motion command

code command

effect

turtle.forward()

fd(distance)         

Move forward, move forward a specified distance in the current direction

bk(distance)

Move backward, move back a specified distance in the opposite direction to the current one

turtle.right (rotation angle)

The brush turns right, turtle. right (90) The direction of the turtle turns 90° to the right

turtle.left (rotation angle)

The brush turns left, turtle.left(90) turns the turtle direction 90° to the left

turtle.penup()

lift the pen, lift the pen

turtle.pendown()

drop pen, drop pen

turtle.goto(x, y horizontal, vertical)

Control the brush to move to the specified position, and the turtle moves to the (x,y) position

turtle.setx(x)

The x-coordinate of the turtle is moved to the specified position, and the ordinate remains unchanged

turtle.sety(y)

The y-coordinate of the turtle moves to the specified position, and the abscissa remains unchanged

turtle.circle (specified radius, radian)

draw circle, draws a circle or arc with a specified radius and angle e

turtle.dot(radius, color)

draw a dot (solid) draws a dot with a specified radius and color

turtle.setheading(angle指向角度)

turtle.seth(angle)

设置当前朝向为angle角度。画笔的指向,右是0,逆时针0-360递增

turtle.home()

设置当前画笔位置为原点,朝向东(默认值)

4、 画笔颜色控制命令

代码命令

作 用

turtle.fillcolor('颜色')

设置 填充颜色

turtle.color(color1, color2)

设置 画笔颜色为color1,填充颜色为color2

可以使用颜色名称或十六进制RGB代码

turtle.begin_fill()

开始填充颜色

turtle.end_fill()

填充完成,结束填充

turtle. pencolor(‘颜色’)

设置画笔颜色

turtle. filling()

返回填充的状态,True为填充。False为未填充

5、全局控制命令

代码命令

作 用

turtle.clear()

清空turtle窗口,但是turtle的位置和状态不会改变(当前窗口清空,当前画笔位置不改变)

turtle.reset()

清空turtle窗口,重置turtle状态为起始状态(当前窗口清空,画笔位置等状态为初始时的默认值)

turtle.undo()

撤销上一个turtle动作(撤销画笔的最后一步动作)

turtle.isvisible()

返回当前turtle是否可见

turtle.done()

关闭画笔,结束绘制,但画面保留

              

代码命令

作 用

t.write("文本" ,align="center",font=("黑体",20,"normal"))

写文本,可指定显示字体,字体大小等align(可选):left,right,center;font(可选):字体名称,字体大小,字体类型(normal,bold,italic)

四、中秋月饼图片欣赏

       要画月饼先要留意月饼长什么样,中秋节少不了月饼,现在的月饼除了传统口味的,还出了不少新口味,外观造型上也有创新,一起来看一下吧。

莲蓉月饼

蛋黄莲蓉月饼

白莲双黄

豆沙月饼

绿豆月饼

五仁月饼

水晶月饼

苏式月饼

五仁月饼(大)

冰皮月饼

绿茶月饼

奶油椰蓉

溏心蛋黄

杨枝甘露

韵香乌龙茶

白桃茉莉花

蓝莓黑莓

夏威夷果仁巧克力

芋泥芝士奇亚籽

金沙奶黄

枣泥核桃

臻品奶黄

栗蓉

红豆

奶黄

黑芝麻

南瓜

五、收集的“用代码画月饼”作品系列:

       这次我用python 海龟画的月饼,因时间的关系,除了增加了情景底图,其他的在代码上没有什么独特之处(我的代码就先不贴出来了),月饼的画法主要借鉴了下面几个作品的思路。让我们一起来学一下吧。

1.冰皮月饼

        个人观点:这款月饼画法简洁,纯海龟作图,入门简单,封装调用,只需修改几个参数就可制作出同款月饼。欠缺的是外观的月饼花纹。

from turtle import *

# 隐藏海龟
hideturtle()
# 颜色模式
colormode(255)
'''
函数说明:

pensize:画笔粗细
pencolor:画笔颜色
fillcolor:填充颜色
begin_fill:开始填充
fd:前进
circle:画圆
right:右转
end_fill():结束填充

'''


def MoonCake(bgcolor, mkcolor, wdcolor, words):
    '''
    参数说明:
    
    bgcolor: 背景颜色
    mkcolor: 月饼颜色
    wdcolor: 文字颜色
    words: 文字(4个字)
    '''
    pensize(2)
    pencolor(0, 0, 0)
    fillcolor(bgcolor)

    begin_fill()
    for i in range(12):
        if i == 5:
            p = pos()
        circle(30, 120)
        right(90)
    end_fill()
    
    penup()
    fd(20)
    pendown()

    fillcolor(mkcolor)
    
    begin_fill()
    for i in range(12):
        circle(30, 120)
        right(90)
    end_fill()

    pencolor(wdcolor)

    left(90)
    fd(140)
    left(90)
    fd(140)
    left(90)
    fd(72)
    p = pos()
    wd1 = words[0:2]
    wd2 = words[2:4]
    write(wd1, font=('Arial', 70, 'normal'))
    fd(70)
    write(wd2, font=('Arial', 70, 'normal'))
    left(90)
    fd(140)


# MoonCake((231, 162, 63), (255, 166, 16), (204, 22, 58), '五仁月饼')

MoonCake((97, 154, 195),(186, 204, 217) ,(17, 101, 154), '冰皮月饼')
mainloop()

作者:二哥不像程序员
原文地址:中秋节快到了,别学Python了,进来排队领块月饼吧【纯手工哪种】!_二哥不像程序员的博客-CSDN博客

2、Crossin牌“月饼”

        个人观点:这款月饼画法上用到了numpy和matplotlib库,需要掌握相应的基础知识。

import numpy as np
from numpy import sin, cos, pi
import matplotlib.pyplot as plt
import matplotlib.patches as mpatch
from matplotlib.patches import Arc, Circle, Wedge
from matplotlib.collections import PatchCollection

length = 20
R = 3**0.5*length/(3**0.5*cos(pi/12)-sin(pi/12))
r = 2*sin(pi/12)*R/3**0.5

arc1 = Arc([0, length], width=2*r, height=2*r, angle=0, theta1=30, theta2=150, ec='orange', linewidth=4)
arc2 = Arc([-length/2, length/2*3**0.5], width=2*r, height=2*r, angle=0, theta1=60, theta2=180, ec='orange', linewidth=4)
arc3 = Arc([-length/2*3**0.5, length/2], width=2*r, height=2*r, angle=0, theta1=90, theta2=210, ec='orange', linewidth=4)
arc4 = Arc([-length, 0], width=2*r, height=2*r, angle=0, theta1=120, theta2=240, ec='orange', linewidth=4)
arc5 = Arc([-length/2*3**0.5, -length/2], width=2*r, height=2*r, angle=0, theta1=150, theta2=270, ec='orange', linewidth=4)
arc6 = Arc([-length/2, -length/2*3**0.5], width=2*r, height=2*r, angle=0, theta1=180, theta2=300, ec='orange', linewidth=4)
arc7 = Arc([0, -length], width=2*r, height=2*r, angle=0, theta1=210, theta2=330, ec='orange', linewidth=4)
arc8 = Arc([length/2, -length/2*3**0.5], width=2*r, height=2*r, angle=0, theta1=240, theta2=360, ec='orange', linewidth=4)
arc9 = Arc([length/2*3**0.5, -length/2], width=2*r, height=2*r, angle=0, theta1=270, theta2=390, ec='orange', linewidth=4)
arc10 = Arc([length, 0], width=2*r, height=2*r, angle=0, theta1=300, theta2=420, ec='orange', linewidth=4)
arc11 = Arc([length/2*3**0.5, length/2], width=2*r, height=2*r, angle=0, theta1=330, theta2=450, ec='orange', linewidth=4)
arc12 = Arc([length/2, length/2*3**0.5], width=2*r, height=2*r, angle=0, theta1=0, theta2=120, ec='orange', linewidth=4)

art_list = [arc1, arc2, arc3, arc4, arc5, arc6, arc7, arc8, arc9, arc10, arc11, arc12]

circle = Circle((0,0), R, ec='orange', fc='white', linewidth=4)

wedge1 = Wedge([-2, 2], R-5, 90, 180, ec='orange', fc=r'white', linewidth=4)
wedge2 = Wedge([-5, 5], R-12, 90, 180, ec='orange', fc=r'white', linewidth=4)
wedge3 = Wedge([-2, -2], R-5, 180, 270, ec='orange', fc=r'white', linewidth=4)
wedge4 = Wedge([-5, -5], R-12, 180, 270, ec='orange', fc=r'white', linewidth=4)
wedge5 = Wedge([2, -2], R-5, 270, 360, ec='orange', fc=r'white', linewidth=4)
wedge6 = Wedge([5, -5], R-12, 270, 360, ec='orange', fc=r'white', linewidth=4)
wedge7 = Wedge([2, 2], R-5, 0, 90, ec='orange', fc=r'white', linewidth=4)
wedge8 = Wedge([5, 5], R-12, 0, 90, ec='orange', fc=r'white', linewidth=4)

art_list.extend([circle, wedge1, wedge2, wedge3, wedge4, wedge5, wedge6, wedge7, wedge8])
fig, ax = plt.subplots(figsize=(8,8))
ax.set_aspect('equal')
for a in art_list:
    ax.add_patch(a)

plt.text(-18, -2.5, 'CROSSIN', fontfamily=r'Times New Man', bbox=dict(boxstyle='square', fc="w", ec='orange', linewidth=4),  fontsize=50, color='orange')

plt.ylim([-35, 35])
plt.xlim([-35, 35])

plt.show()

作者:Crossin的编程教室
原文地址:

中秋节到了,送你一个Python做的Crossin牌“月饼”_Crossin的编程教室的博客-CSDN博客

3、福字月饼

        个人观点:这款月饼是python 海龟月饼,有花纹

import turtle
 
def goto(x, y):#定义提笔的位置
    turtle.penup() #将笔提起,移动时无图
    turtle.goto(x, y)
    turtle.pendown() #将笔放下,移动时绘图。
 
 
def yuebing_wai():
    turtle.pensize(20)#画笔调粗点
    turtle.color( "#F8CD32","#FBA92D")#填充颜色,F8CD32是圆圈的边缘颜色,FBA92D是圆圈的填充颜色
    goto(0, -200)#画笔起点位于(0,0)点的下方200向量处
    turtle.begin_fill()#准备开始填充
    turtle.circle(200)#定义半径
    turtle.end_fill()#填充结束
 
 
def yuebing_zhong():
    goto(0, 0)#画笔起点位于(0,0)处
    turtle.color("#F0BE7C")
    for _ in range(20):#_是占位符,表示临时变量,仅用一次,后面无需再用到 
        turtle.right(18)#顺时针移动18度
        turtle.begin_fill()
        turtle.forward(220)#向前移动的距离
        turtle.circle(40, 180)#上一条向前移动220之后,开始画半径40的半圆
        turtle.goto(0, 0)#画完半圆之后回到(0,0)
        turtle.right(360)#顺时针转个360度
        turtle.end_fill()
 
 
def yuebing_nei():#逻辑同上
    turtle.right(360)
    turtle.color('#F5E16F')#内层颜色
    goto(0, -180)
    for _ in range(12):
        turtle.begin_fill()
        turtle.circle(60, 120)
        turtle.left(180)
        turtle.circle(60, 120)
        turtle.end_fill()
 
 
def fu():#
    turtle.right(50)
    goto(-70, -80)#更高坐标尽量使字靠中间
    turtle.color("Gold")#颜色
    turtle.write("福", font=("华文隶书", 120, "bold"))
    turtle.done()
 
 
if __name__ == '__main__':
    turtle.speed(90)
    yuebing_zhong()
    yuebing_wai()
    yuebing_nei()
    fu()
 
 
turtle.done()  

作者:weixin_39912368
原文地址: 

python趣味代码_趣味项目:用Python代码做个月饼送给你!_weixin_39912368的博客-CSDN博客


4、花纹月饼

       个人观点:这款月饼属纯python 海龟绘制,外观精致,有花纹和文字,用函数定义了月饼的不同部分,修改起来不难。

import turtle

t = turtle.Pen()  # 画笔一 用于画图
t.speed(0)


# 花纹颜色 #F29407
# 饼身颜色 #F8B41A

# 画 饼身部分
def outfill_flower(flower_num: "花瓣数量", flower_color: "花瓣颜色"):
    for i in range(flower_num):
        t.left(i * (360 // flower_num))
        t.color(flower_color)
        t.penup()
        t.forward(200)
        t.pendown()
        t.fillcolor(flower_color)
        t.begin_fill()
        t.circle(60)
        t.end_fill()
        t.penup()
        t.home()


# 画 饼身外围 花纹部分
def out_line_flower(flower_num: "花纹数量", flower_color: "花纹颜色"):
    for i in range(flower_num):
        t.pensize(5)
        t.left(i * (360 // 18))
        t.color(flower_color)
        t.penup()
        t.forward(192)
        t.pendown()
        t.circle(60)
        t.penup()
        t.home()


# 画内测的大圆 大圆的填充色比饼身略亮
def big_circle(circle_color: "大圆颜色", circle_fill_color: "大圆填充颜色", circle_size: "大圆半径"):
    t.goto(circle_size, 0)
    t.left(90)
    t.pendown()
    t.pensize(8)
    t.color(circle_color)
    t.fillcolor(circle_fill_color)
    t.begin_fill()
    t.circle(circle_size)
    t.end_fill()
    t.penup()
    t.home()


# 饼上印花文字 文字内容和坐标用字典存储
def write_font(text_content: "文本内容", text_color: "文本颜色", size: "文字大小"):
    t.color(text_color)
    for x in text_content:
        t.penup()
        t.goto(text_content[x])
        t.write(x, align='center', font=('simhei', size, 'bold'))
    t.penup()
    t.home()
    t.color('#F29407')


# 饼身中间矩形条纹部分
def body_center_line(width: "矩形宽度", height: "矩形高度"):
    t.penup()
    t.home()
    t.pensize(4)
    t.pendown()
    t.backward(width / 2)
    t.forward(width)
    t.left(90)
    t.forward(height)
    t.left(90)
    t.forward(width)
    t.left(90)
    t.forward(height * 2)
    t.left(90)
    t.forward(width)
    t.left(90)
    t.forward(height)
    t.penup()
    t.home()


# 矩形条纹两侧的四个花纹 画笔轨迹是一样的 所以只需要传入不同的初始位置和角度即可复用代码
def center_flower(start_point: "落笔位置", start_angle: "落笔朝向", angle_direction_change: "新朝向",
                  rectangle_height: "矩形高度", circle_direction: "花纹弧度"):
    t.penup()
    t.goto(start_point)
    t.pendown()
    t.setheading(start_angle)
    t.forward(10)
    t.setheading(angle_direction_change)
    t.forward(20)
    t.backward(rectangle_height * 2)
    t.forward(rectangle_height * 2)
    t.setheading(start_angle)
    t.circle(circle_direction * 70, 90)
    t.setheading(start_angle + 180)
    t.forward(60)
    t.setheading(angle_direction_change)
    t.forward(30)
    t.penup()
    t.home()


# 饼身上下左右的花纹
def out_flower(begin_x: "落笔横坐标", begin_y: "落笔纵坐标", start_angle: "落笔朝向"):
    t.penup()
    t.goto(begin_x, begin_y)
    t.pendown()
    t.setheading(start_angle)
    t.forward(20)
    t.right(90)
    t.circle(-100, 20)

    t.penup()
    t.goto(begin_x, begin_y)
    t.pendown()
    t.setheading(start_angle)
    t.right(90)
    t.circle(-100, 30)
    t.left(90)
    t.forward(45)
    t.left(95)
    t.circle(190, 50)
    t.left(95)
    t.forward(45)
    t.left(90)
    t.circle(-100, 31)
    t.setheading(start_angle)
    t.forward(20)
    t.left(90)
    t.circle(100, 20)
    t.penup()
    t.home()

# 以下代码开始调用各种功能
if __name__ == "__main__":
	# 设置画布名称
    t.screen.title('中秋快乐')
    # 画 饼身部分
    outfill_flower(18, '#F8B41A')
    # 画 饼身外围 花纹部分
    out_line_flower(18, '#F29407')
    # 画内测的大圆 大圆的填充色比饼身略亮
    # big_circle('#F29407','#F8B41A',200)
    big_circle('#F29407', '#F8B51D', 200)
    # 饼上印花文字 文字内容和坐标用字典存储
    text_content = {'花': (-100, 70), '好': (100, 70), '月': (100, -120), '圆': (-98, -125)}  # 圆字坐标最后向下微调了一下
    # write_font(text_content,'#F29407',40)
    write_font(text_content, '#FC932B', 40)
    # 饼身中间矩形条纹部分
    body_center_line(12, 80)
    # 矩形条纹两侧的四个花纹
    center_flower((6, 60), 0, 90, 80, -1)
    center_flower((6, -60), 0, -90, 80, 1)
    center_flower((-6, 60), 180, 90, 80, 1)
    center_flower((-6, -60), 180, -90, 80, -1)
    # 饼身上下左右的花纹
    out_flower(6, 110, 90)
    out_flower(-110, 6, 180)
    out_flower(-6, -110, 270)
    out_flower(110, -6, 360)
    # 可以再加点字
    # text_content2 = {'天': (-50, 30), '地': (50, 30), '仁': (50, -60), '和': (-50, -60)}  # 圆字坐标最后向下微调了一下
    # write_font(text_content2, '#F29407',30)

    # 隐藏画笔
    t.hideturtle()
    # 保持画布显示
    turtle.done()



Author: Lang Tao 3000
Original address: Python draws Mid-Autumn moon cakes, uses turtle library to draw Mid-Autumn moon cakes

5. MATLAB draws a 2.5D moon cake

        Personal opinion: This moon cake is drawn by MATLAB, and the moon cake pattern is exquisite and three-dimensional. Perspective can be slightly modified.

function moonCake
% @author:slandarer
ax=gca;
hold(ax,'on');
axis equal
ax.XLim=[-15,15];
ax.YLim=[-15,15];
CSet=[0.92 0.51 0.11;1 0.7 0.09;0.87 0.41 0.05];


for i=[1:7,9,8]
    if i==1
        tt=linspace(0,-pi/16,100);
    elseif i==9
        tt=linspace(-pi+pi/16,-pi,100);
    else
        tt=linspace(-pi/16-(i-2)*pi/8,-pi/16-(i-1)*pi/8,100);
    end
    xSet=cos(tt).*(10+abs(cos(tt.*8)));
    xMin=find(xSet==min(xSet));tt(xMin)
    xMax=find(xSet==max(xSet));
    t1=min([xMin(1),xMax(1)]);
    t2=max([xMin(1),xMax(1)]);
    xSet=cos(tt(t1:t2)).*(10+abs(cos(tt(t1:t2).*8)));
    ySet=sin(tt(t1:t2)).*(10+abs(cos(tt(t1:t2).*8)))-3;
    fill([xSet(1),xSet,xSet(end)],[ySet(1)+3,ySet,ySet(end)+3],CSet(mod(i,2)+1,:),'EdgeColor','none')
    
    
end
t=linspace(0,2*pi,640);
fill(cos(t).*(10+abs(cos(t.*8))),sin(t).*(10+abs(cos(t.*8))),CSet(1,:),'EdgeColor','none')
plot(cos(t).*(9+abs(cos(t.*8))),sin(t).*(9+abs(cos(t.*8)))-0.3,'Color',CSet(3,:),'LineWidth',6)
plot(cos(t).*8.7,sin(t).*8.7-0.3,'Color',CSet(3,:),'LineWidth',4)
plot(cos(t).*(9+abs(cos(t.*8))),sin(t).*(9+abs(cos(t.*8))),'Color',CSet(2,:),'LineWidth',6)
plot(cos(t).*8.7,sin(t).*8.7,'Color',CSet(2,:),'LineWidth',4)

plot([0 0],[-7 7]-0.3,'Color',CSet(3,:),'LineWidth',4)
plot([-7 7],[0 0]-0.3,'Color',CSet(3,:),'LineWidth',4)
plot([0 0],[-7 7],'Color',CSet(2,:),'LineWidth',4)
plot([-7 7],[0 0],'Color',CSet(2,:),'LineWidth',4)


t4=linspace(0,pi/2,100);
xSet4=[cos(t4).*6+1,1,6,cos(t4(1:end-12)).*5+1,2,4.8,cos(t4(17:end-40)).*3.9+1];
ySet4=[sin(t4).*6+1,1,1,sin(t4(1:end-12)).*5+1,2,2,sin(t4(17:end-40)).*3.9+1];

plot(xSet4,ySet4-0.3,'Color',CSet(3,:),'LineWidth',4)
plot(-xSet4,ySet4-0.3,'Color',CSet(3,:),'LineWidth',4)
plot(xSet4,-ySet4-0.3,'Color',CSet(3,:),'LineWidth',4)
plot(-xSet4,-ySet4-0.3,'Color',CSet(3,:),'LineWidth',4)
plot(xSet4,ySet4,'Color',CSet(2,:),'LineWidth',4)
plot(-xSet4,ySet4,'Color',CSet(2,:),'LineWidth',4)
plot(xSet4,-ySet4,'Color',CSet(2,:),'LineWidth',4)
plot(-xSet4,-ySet4,'Color',CSet(2,:),'LineWidth',4)
end

Author: slandarer
Original address: The Mid-Autumn Festival is coming, use MATLAB to draw a 2.5D moon cake together_slandarer's blog - CSDN blog

6. 2022 Mid-Autumn Festival Programmer Portfolio

Python version of Mid-Autumn Festival mooncake snapping script

The big visual screen of Mid-Autumn Festival

[using python pyecharts as a tool]

Author: Pushkin. Author: Hou Xiaojiu
Python version of the Mid-Autumn Festival moon cake snapping script - Pushkin. Blog - CSDN Blog

A large-scale visualization of Mid-Autumn Festival flavor [using python pyecharts as a tool] - Hou Xiaojiu's blog - CSDN Blog

Pygame makes a rabbit picking moon cake game Python Mid-Autumn Festival Chang'e feeding game
Qingyuan Xiaoruan Ape Tongxue

It's the Mid-Autumn Festival again | Using Python Pygame to make a rabbit and moon cake game - Programmer Sought

[Mid-Autumn Festival Essay] Using Python Mid-Autumn Festival Chang'e Feeding Game "Qianli Chanjuan" - Programmer Sought

mid autumn greeting card
Author: Gu Muzi
[Mid-Autumn Festival Series] Python's Mid-Autumn Festival greeting card, it's not too late to learn! _Gu Muzi acridine's blog - CSDN blog

      

       How do programmers spend the Mid-Autumn Festival? There are many things that can be done, such as editing Mid-Autumn Festival-themed games and small programs, using code to create various special effects and romantic scenes for the Mid-Autumn Festival, and analyzing various data related to the Mid-Autumn Festival theme. . . .

       In fact, there is not much difference between programmers and people in other industries. All walks of life have their own ups and downs and difficulties. But on the Mid-Autumn Festival, all we can do is to cherish everything and spend more time with your family.

 

 

Guess you like

Origin blog.csdn.net/weixin_69553582/article/details/126624379