程序员过节指南:如何用代码做一个月饼?

  • 回答 (29)
  • 关注 (9)
  • 查看 (2727)

2021年中秋即将到来,作为程序员,前有「产品迭代」,后有「运营需求」。

  • 开发中秋活动相关页面( 时间太急,可能有 BUG )
图片来源于网络
  • 开发与货币直接相关的,比如电商、抢购业务( 后果严重,容易在假期前后被攻击 )
图片来源于网络

作为程序员的你:

  1. 在中秋节接过什么样的产品 or 运营需求?
  2. 有什么高效完成需求小技巧,优雅度过中秋?

快来分享你的心得吧!

图片来源于网络

内容要求

● 围绕如何在中秋节前高效完成需求,发表见解 50 字以上(需原创,禁止转载)

奖励

回答赞同数 TOP10 的用户将有机会获得精美定制小礼品一份

评选标准

  • 回答需符合活动中所提及的要求,符合社区规范
  • 请遵守社区规范,如有违规行为,一经发现即取消参与资格

评选结果 & 公示

腾讯云开发者社区小助手 9 月 24 日在获奖评论下通知答主,奖品将于30日内发放

更多精彩问答与定制好礼,尽请关注 【云+有奖问答专题】 \( ̄▽ ̄)/

腾讯云开发者社区腾讯云开发者社区

腾讯云 · 产品运营 (已认证)

修改于
用户6557788邀请了用户1747748来回答
回忆大大邀请了liuzhen007来回答
西门呀在吹雪

腾云先锋 · 腾云先锋(TDP)成员 (已认证)

非典型性程序员回答于
 public static void main(String[] args) {
        int r = 20;
        for (int y = 0; y <= 2 * r; y += 4) {
            int x = (int) Math.round(r - Math.sqrt(2 * r * y - y * y));
            int len = 2 * (r - x);
            for (int i = 0; i <= x; i++) {
                System.out.print(' ');
            }
            System.out.print('*');

            if(y==r){
                for (int j = 0; j <= len/4; j++) {
                    System.out.print("月饼");
                }
            }else {
                for (int j = 0; j <= len; j++) {
                    System.out.print(' ');
                }
            }
            System.out.println('*');
        }
    }

效果

                     * *
         *                         *
     *                                 *
   *                                     *
 *                                         *
 *月饼月饼月饼月饼月饼月饼月饼月饼月饼月饼月饼*
 *                                         *
   *                                     *
     *                                 *
         *                         *
                     * *
量子态的沐子呓

腾讯科技有限公司 · 高级架构工程师 (已认证)

一名摸着石头过河的资深小白修改于

首先来张效果图把:

实现步骤

1、首先我们需要导入画图和数据计算的相关库。

#导入画图和数据计算的相关库
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
from matplotlib.font_manager import FontProperties

2、为了在图片上显示中文,需要先加载Alibaba-PuHuiTi-Medium字体下载地址:

#为了在图片上显示中文,加载字体
!wget http://tianchi-media.oss-cn-beijing.aliyuncs.com/DSW/Python/miniproject/01_draw_moon_cake/Alibaba-PuHuiTi-Medium.ttf

3、然后设置3个变量,这3个变量的用途到后面会有解释:

#设置变量
length = 20R = 3**0.5*length/(3**0.5*cos(pi/12)-sin(pi/12))r = 2*sin(pi/12)*R/3**0.5

4、接下来我们要画弧线,弧线是月饼边缘的花纹:

arc1 = Arc([0, length], width=2.9*r, height=2.9*r, angle=0, theta1=60, theta2=420, ec='orange', linewidth=4)

5、其中 [0, length] 是这个Arc弧线的圆心,因为这个Arc类是一个椭圆形的一部分,所以其包含圆心、横轴、纵轴等参数,length变量就是arc1圆心的纵坐标,width=2r 和 height=2r 就说明这个椭圆的纵轴和横轴长度相等,其是一个圆,而不是椭圆,变量 r 就是这个圆的半径。angle=0 就是我们不需要对这个圆进行旋转,theta1=30 和 theta2=150 是指明这个弧线的起始角度和终止角度,这里的角度分别是30度和150度。而 ec=‘orange’ 和linewidth=4 分别指边线的颜色和线条宽度,颜色我们设为橙色,宽度为4。而这些弧线的效果图如图2所示,在图中笔者标出了arc1、arc5和arc9这3条弧线的位置,所有弧线按照逆时针方向排列。这些位置大同小异,大家只要计算好其各自的位置参数就行,这里就不再赘述了。

接下来我们要画剩下的11条弧线

#绘制弧线
arc1 = Arc([0, length], width=2.9*r, height=2.9*r, angle=0, theta1=60, theta2=420, ec='orange', linewidth=4)
arc2 = Arc([-length/2, length/2*3**0.5], width=2.9*r, height=2.9*r, 
           angle=0, theta1=120, theta2=480, ec='orange', linewidth=4)
arc3 = Arc([-length/2*3**0.5, length/2], width=2.9*r, height=2.9*r, 
            angle=0, theta1=180, theta2=540, ec='orange', linewidth=4)
arc4 = Arc([-length, 0], width=2.9*r, height=2.9*r,  angle=0, theta1=240, theta2=600, ec='orange', linewidth=4)
arc5 = Arc([-length/2*3**0.5, -length/2], width=2.9*r, height=2.9*r, 
            angle=0, theta1=300, theta2=660,ec='orange', linewidth=4)
arc6 = Arc([-length/2, -length/2*3**0.5], width=2.9*r, height=2.9*r,
           angle=0, theta1=360, theta2=720, ec='orange', linewidth=4)
arc7 = Arc([0, -length], width=2.9*r, height=2.9*r, angle=0, theta1=420, theta2=780, ec='orange', linewidth=4)
arc8 = Arc([length/2, -length/2*3**0.5], width=2.9*r, height=2.9*r,
           angle=0, theta1=480, theta2=840, ec='orange', linewidth=4)
arc9 = Arc([length/2*3**0.5, -length/2], width=2.9*r, height=2.9*r,
           angle=0, theta1=540, theta2=900, ec='orange', linewidth=4)
arc10 = Arc([length, 0], width=2.9*r, height=2.9*r, angle=0, theta1=600, theta2=960, ec='orange', linewidth=4)
arc11 = Arc([length/2*3**0.5, length/2], width=2.9*r, height=2.9*r,
            angle=0, theta1=660, theta2=1020, ec='orange', linewidth=4)
arc12 = Arc([length/2, length/2*3**0.5], width=2.9*r, height=2.9*r,
            angle=0, theta1=720, theta2=1080, ec='orange', linewidth=4)

6、然后我们再画一个圆,这个圆是月饼的主体部分,其圆心和整个月饼的中心是重合的,圆心位置我们选在了坐标原点,代码如下:

circle = Circle((0,0), R, ec='orange', fc='white', linewidth=4) ##ec为线条颜色,fc为填充颜色,可以自由替换
circle2 = Circle((0,0), (1/4+1)*R, ec='orange', fc='brown', linewidth=4)

7、这里变量R就是这个大圆的半径,边线颜色(ec)设置为橙色,表面颜色设为白色。 接下来我们再画上一些花纹,这些花纹主要由8个扇形组成,其中有4个大的扇形和4个小的扇形,我们先画一个,代码如下:

wedge1 = Wedge([-2, 2], R-5, 90, 180,
               ec='orange', fc=r'white', linewidth=4) ##ec为线条颜色,fc为填充颜色,可以自由替换

8、其中[-2, 2]是这个Wedge所代表的圆的圆心,R-5 是其半径,90 和180分别代表起始和终止角度,ec、fc和linewidth这些都和前面Arc类的用法相似,这8个扇形的效果图如图4所示。在图中笔者标出了wedge1、wedge2、wedge5和wedge6的位置,所有扇形按照逆时针方向放置。 了解以后我们把剩下的部分给画完

wedge1 = Wedge([-2, 2], R-5, 90, 180,
               ec='orange', fc=r'white', linewidth=4) ##ec为线条颜色,fc为填充颜色,可以自由替换
wedge2 = Wedge([-5, 5], R-12, 90, 180, ec='orange',
               fc=r'brown', 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'brown', 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'brown', 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'brown', linewidth=4)

9、最后我们再把自己取好的名称加上,因为代码不多,所以把剩余所有代码都写在这里:

art_list = [circle2,arc1, arc2, arc3, arc4, arc5, arc6, arc7, arc8, arc9, arc10, arc11, arc12]
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.axis('off')
font_set = FontProperties(fname=r"Alibaba-PuHuiTi-Medium.ttf", size=12) ##可以自由下载字体使用
plt.text(-15, 7, '中',fontproperties=font_set,color='orange',fontsize=49) ##ec为线条颜色,color为字体颜色,可以自由替换
plt.text(-15, -13, '快',fontproperties=font_set,color='orange',fontsize=49) ##ec为线条颜色,color为字体颜色,可以自由替换
plt.text(7, 7, '秋',fontproperties=font_set,color='orange',fontsize=49) ##ec为线条颜色,color为字体颜色,可以自由替换
plt.text(7, -13, '乐',fontproperties=font_set,color='orange',fontsize=49) ##ec为线条颜色,color为字体颜色,可以自由替换
plt.text(-25,-40,'但愿人长久,千里共婵娟',fontproperties=font_set, fontsize=30, color='#aa4a30')
plt.ylim([-35, 35])
plt.xlim([-35, 35])
plt.show()

铛铛,一个月饼就画好啦!

全部代码

#导入画图和数据计算的相关库
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
from matplotlib.font_manager import FontProperties
#为了在图片上显示中文,加载字体
!wget http://tianchi-media.oss-cn-beijing.aliyuncs.com/DSW/Python/miniproject/01_draw_moon_cake/Alibaba-PuHuiTi-Medium.ttf
#设置变量
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.9*r, height=2.9*r, angle=0, theta1=60, theta2=420, ec='orange', linewidth=4)
arc2 = Arc([-length/2, length/2*3**0.5], width=2.9*r, height=2.9*r, 
           angle=0, theta1=120, theta2=480, ec='orange', linewidth=4)
arc3 = Arc([-length/2*3**0.5, length/2], width=2.9*r, height=2.9*r, 
            angle=0, theta1=180, theta2=540, ec='orange', linewidth=4)
arc4 = Arc([-length, 0], width=2.9*r, height=2.9*r,  angle=0, theta1=240, theta2=600, ec='orange', linewidth=4)
arc5 = Arc([-length/2*3**0.5, -length/2], width=2.9*r, height=2.9*r, 
            angle=0, theta1=300, theta2=660,ec='orange', linewidth=4)
arc6 = Arc([-length/2, -length/2*3**0.5], width=2.9*r, height=2.9*r,
           angle=0, theta1=360, theta2=720, ec='orange', linewidth=4)
arc7 = Arc([0, -length], width=2.9*r, height=2.9*r, angle=0, theta1=420, theta2=780, ec='orange', linewidth=4)
arc8 = Arc([length/2, -length/2*3**0.5], width=2.9*r, height=2.9*r,
           angle=0, theta1=480, theta2=840, ec='orange', linewidth=4)
arc9 = Arc([length/2*3**0.5, -length/2], width=2.9*r, height=2.9*r,
           angle=0, theta1=540, theta2=900, ec='orange', linewidth=4)
arc10 = Arc([length, 0], width=2.9*r, height=2.9*r, angle=0, theta1=600, theta2=960, ec='orange', linewidth=4)
arc11 = Arc([length/2*3**0.5, length/2], width=2.9*r, height=2.9*r,
            angle=0, theta1=660, theta2=1020, ec='orange', linewidth=4)
arc12 = Arc([length/2, length/2*3**0.5], width=2.9*r, height=2.9*r,
            angle=0, theta1=720, theta2=1080, ec='orange', linewidth=4)
#画圆
circle = Circle((0,0), R, ec='orange', fc='white', linewidth=4) ##ec为线条颜色,fc为填充颜色,可以自由替换
circle2 = Circle((0,0), (1/4+1)*R, ec='orange', fc='brown', linewidth=4)
wedge1 = Wedge([-2, 2], R-5, 90, 180,
               ec='orange', fc=r'white', linewidth=4) ##ec为线条颜色,fc为填充颜色,可以自由替换
wedge2 = Wedge([-5, 5], R-12, 90, 180, ec='orange',
               fc=r'brown', 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'brown', 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'brown', 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'brown', linewidth=4)
art_list = [circle2,arc1, arc2, arc3, arc4, arc5, arc6, arc7, arc8, arc9, arc10, arc11, arc12]
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.axis('off')
font_set = FontProperties(fname=r"Alibaba-PuHuiTi-Medium.ttf", size=12) ##可以自由下载字体使用
plt.text(-15, 7, '中',fontproperties=font_set,color='orange',fontsize=49) ##ec为线条颜色,color为字体颜色,可以自由替换
plt.text(-15, -13, '快',fontproperties=font_set,color='orange',fontsize=49) ##ec为线条颜色,color为字体颜色,可以自由替换
plt.text(7, 7, '秋',fontproperties=font_set,color='orange',fontsize=49) ##ec为线条颜色,color为字体颜色,可以自由替换
plt.text(7, -13, '乐',fontproperties=font_set,color='orange',fontsize=49) ##ec为线条颜色,color为字体颜色,可以自由替换
plt.text(-25,-40,'但愿人长久,千里共婵娟',fontproperties=font_set, fontsize=30, color='#aa4a30')
plt.ylim([-35, 35])
plt.xlim([-35, 35])
plt.show()

效果预览:

jwj

腾云先锋 · 腾云先锋(TDP)成员 (已认证)

修改于
<!doctype html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>中秋快乐</title>
    <style>
        .blessing {
            font-size: 100px;
            letter-spacing: 40px;
            width: 400px;
            text-align: center;
            line-height: 200px;
            color: #fede65;
        }
        span{position:absolute; color: #f00;}
    </style>
</head>
<body>
<div class="blessing">阖家平安</div>
<script type="text/javascript">
function moonCake(r) {
    var PI = Math.PI;
    for(var i = 0; i < 360; i += 6) {
        var O = document.createElement('span');
        O.appendChild(document.createTextNode('.'));
        O.style.left = (Math.cos(PI / 180 * i) * r + r) + 'px';
        O.style.top = (Math.sin(PI / 180 * i) * r + r) + 'px';
        document.body.appendChild(O);
    }
}
moonCake(200);
</script>
</body>
</html>

<!doctype html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>中秋快乐</title>
    <style>
        .blessing {
            font-size: 100px;
            letter-spacing: 40px;
            width: 400px;
            text-align: center;
            line-height: 200px;
            border-radius: 200px;
            background: #c96904;
            color: #fede65;
            border: 5px solid #fede65;
        }
    </style>
</head>
<body>
<div class="blessing">阖家平安</div>
</body>
</html>
KINGISS

腾云先锋 · 腾云先锋(TDP)元老 (已认证)

There are more things in heaven and earth, Horatio, than are dreamt of in your philosophy.修改于
import turtle

def goto(x, y):
    turtle.penup() 
    turtle.goto(x, y)
    turtle.pendown() 


def yuebing_wai():
    turtle.pensize(20)
    turtle.color( "#F8CD32","#FBA92D")
    goto(0, -200)
    turtle.begin_fill()
    turtle.circle(200)
    turtle.end_fill()


def yuebing_zhong():
    goto(0, 0)
    turtle.color("#F0BE7C")
    for _ in range(20):
        turtle.right(18)
        turtle.begin_fill()
        turtle.forward(220)
        turtle.circle(40, 180)
        turtle.goto(0, 0)
        turtle.right(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()  

三掌柜

佰钧成技术有限责任公司 · 架构师 (已认证)

一名合格的、二把刀的、科班的程序猿回答于

通过前端html+css实现嫦娥奔月,顺便有月亮,有月饼,具体代码如下所示:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<title>嫦娥奔月</title>

<style type="text/css">

*{

margin: 0;

padding: 0;

}

body{

background: #111111;

}

.wrap{

width: 470px;

height: 470px;

margin: 50px auto;

border: 10px solid white;

text-align: center;

}

.wrap .moon{

/* margin-top: 50px; */

margin-top: 20px;

}

.wrap .change{

position: relative;

margin-top: -550px;

margin-left: -350px;

opacity: 0; /*全透明*/

transition-duration: 3s; /*动画过渡时间3秒*/

}

.wrap:hover .change{

transition-duration: 2s;

transform: translate(100px,100px);/*嫦娥移动方向*/

opacity: 1;/*不透明*/

}

</style>

</head>

<body>

<div class="wrap">

<div class="moon">

<img src="../assets/img/moon.png" alt="" width="430" height="430"> //月亮

</div>

<div class="change">

<img src="../assets/img/change.png" alt="" width="300" height="300"> //嫦娥

</div>

</div>

</body>

</html>

张曙光

南京尚哲智能科技 · unity开发工程师 (已认证)

一位脱离了高级趣味的人.回答于

unity里面只能实例一个圆柱体,然后贴上贴图,哈哈,代码比较简单

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NewBehaviourScript : MonoBehaviour
{
    public Material moonPie;
    // Start is called before the first frame update
    void Start()
    {
        GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
        go.transform.localScale = new Vector3(1, 0.1f, 1);
        go.transform.GetComponent<MeshRenderer>().material = moonPie;
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}

我还有之前用blender建模软件做的月饼,哈哈哈....这个看着有食欲一点,但是这个和程序生成的就没关系了哦。

99回答于
<?php
// 中秋快乐 阖家团圆
$messageArry = array('中'=>'200','秋'=>'200','快'=>'200','乐'=>'200');

$img = imagecreate(600, 600);
imagefill($img, 0, 0, imagecolorallocate($img, 255, 255, 255));

$r1 = $r2 = $num = 0;
foreach($messageArry as $k => $v){
    $r1 = $num == 0 ? 0 : $r2;
    $r2 = $r1 == 0 ? ($v/array_sum($messageArry))*360 : ($v/array_sum($messageArry))*360 + $r1;
    $r2 = min(360,ceil($r2));
    imagefilledarc($img, 300, 300, 200, 200, $r1, $r2, imagecolorallocate($img, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)), IMG_ARC_PIE);
    $num+=1;
}

header('Content-type:image/jpeg');
imagejpeg($img);
imagedestroy($img);
中秋快乐
阿策小和尚回答于
api 'com.airbnb.android:lottie:4.1.0'
<com.airbnb.lottie.LottieAnimationView
    android:id="@+id/lottie_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

mView = (LottieAnimationView) this.findViewById(R.id.lottie_view);
mView.setAnimationFromUrl("https://assets6.lottiefiles.com/packages/lf20_Tprkoc.json");
mView.playAnimation();

中秋月饼变明月!!

中秋月饼变明月~
星橙

腾云先锋 · 腾云先锋(TDP)成员 (已认证)

回答于
# -*- coding: utf-8 -*-

import turtle


def goto(x, y):
    turtle.penup()
    turtle.goto(x, y)
    turtle.pendown()


def yuan():
    turtle.color("#D1C185", "#839F26")
    goto(0, -200)
    turtle.begin_fill()
    turtle.circle(200)
    turtle.end_fill()


def huabian():
    goto(0, 0)
    turtle.color("#839F26")
    for _ in range(20):
        turtle.right(18)
        turtle.begin_fill()
        turtle.forward(220)
        turtle.circle(40, 180)
        turtle.goto(0, 0)
        turtle.right(180)
        turtle.end_fill()


def neitu():
    turtle.color('#D1C185')
    goto(0, -25)
    for _ in range(12):
        turtle.begin_fill()
        turtle.circle(150, 60)
        turtle.left(90)
        turtle.circle(150, 60)
        turtle.end_fill()


def wirte():
    goto(-40, 10)
    turtle.color("red")
    turtle.write("中秋快乐", font=("Time", 18, "bold"))
    turtle.done()


if __name__ == '__main__':
    turtle.speed(10)
    huabian()
    yuan()
    neitu()
    wirte()

turtle.done()
幻影龙王

腾云先锋 · 腾云先锋(TDP)成员 (已认证)

沉迷于在代码海洋里回答于

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()

用户9012618回答于
用户9012866回答于
陈广"><h1>sb{6*6}回答于
IT小马哥

北京天谱同盛教育科技有限公司 · JAVA高级研发经理 (已认证)

想做个有钱人,却误入程序世界的一个小码农。回答于
```javascript

import java.util.Arrays;

public class 八月十五 {

public static void main(String[] args) {
    int 腾 = 20013;
    int 讯 = 31179;
    int 云 = 33410;
    int 社 = 24555;
    int 区 = 20048;
     for (int y = 0; y <= 30; y +=2) {
        int x = (int)Math.round(15 - Math.sqrt(2*15*y-y*y));
        int len = 2 * (15 - x);
        for (int i = 0; i <= x; i++) {
            System.out.print(" ");
        }
        System.out.print('*');
        for (int j = 0; j <= len; j++) {
            if(y==8*2&& j==8){
                Arrays.asList('腾','讯','云','社','区',(char)腾,(char)讯,(char)云,(char)社,(char)区).forEach( System.out::print);
            }
            if(y==16 && j+ 15==len){
                System.out.print("*");
            }else{
                System.out.print(" ");
            }
        }
        if(y==16){
            System.out.println();
        }else{
            System.out.println("*");
        }
    }
}

}

采用Ascii码转换,全程代码中未出现中秋节快乐几个字,却打印出了腾讯云 中秋节快乐!

blueflyming退役程序员回答于
# MoonCake.py
print('''
                                       ..*..*=\**.                                                 
                                    ..*,oo...=OO....**/o/ooo**,.                                   
                           ...**... .*=oOO...*OOO`...,OOOOO`.*oOO\.                                
                       ..*...,/o]*.  .*OOO....=O@O...,O@@O^.*/O@O\.*..                             
                      ..,o.. .*\OO.  ..*OO...*=oO/...=O@O^..=O@@@O..,OO]].                         
                     ..=ooO. . .,oo....,oOOOOOOOOOOOO\/oo]**OOO@O^.*O@@@@OOo.                      
                ........\OO\. ...=**]oOOOOOOOOOO[[[[O[\`/OOOOOo]o\OOO@@@@OO`*,]..                  
             ..*,]]]*.....**...*,o/\o\]*,oOOOOOOoOOOOOOOOO@@@@@@@OO@O.\OO[,/OO@O^.                 
            ...**=OOO...*=OOOOOOOOOOOO/[/[\OO@@/*\@@@@@^..=@@@@OO`,oO`.oOOO@@@OOO**                
           .*/*....*..**o`.*\]oOO]]]OOOOOO/,OOO.=/OO[`..*,/OOO\OOOoO@O.o@@@@@@OOo*=*....           
           .*/O`......,O^..,OOOOOO/[[\[[[*`,/O@`.OOOOOOO^.\O@@@@@^.OO@.\@@@@OOOOOOO]............   
           .*/oOO`....*oO..]OOOOOOo/OOoOOOO^\O@^.OO@O/[`.,\OOOOO]oOO@@.\OOOOO@O@@@@@O].............
           .,]*=^,[,...=O`.*O//OOOO[[OO[[*`,,O@@OOOOOOOOO`\O@@@@@@@@@@.=O/O@@@@@@@@@@OO*...........
        ..,oo\***,***o/OO\.=OOOOOOOOOOOOOOOO.\O@@@@@@@OO@.*oOOOOOOOO\O.=O@OO@@@@@@@OOOOO.*.........
       .*/OOOOO`.....oOOO@.=O@@@O[[=O[[`***,\/O@O.]OOOOOOOOOOOO@OO`,o@O.O@@\OOO@@@@@@@@@O,`........
      .*=o[[OOOOoo..*=.\O@`,OO@^.=\OOOOOOOOO@@@@^,oOOOO@@/.*/OOOOOOOO@O^\O@@,O@@@@@@@@@OO\o........
     ...]]o]]]**,*,//O.=O@^,\O@^.,/@/[.,]/OOO@@@@=OOOOOO@O.,/@@@[[@@@@/../@@^=O@@@@@@@OOO/O^.......
      .=OOOOOOoooo.=oO.=O@O,\O@O.,/\oOOO@@@@@@@@@//O@..\O@\/OO@^.*/@OO^ .=O@O.OO@@@@@@@OOOO^.......
     ..,*oOO@OOOO..*oO.=O@@\OOOO^oOO@@@O[O@@@/[[OO``\O.=O.,oOO\* *,/*OO` ,O@@^=@@@@@@@@@\Oo^.......
    .....=oo[[**..,]oO^*oOOO[.*]oo*]O/..=.=O\o/OOO@.oO`/O^\O@^.,`./^=O@O^=OO@^O@@@@@@@@@@O/^*......
       ...ooOoooo/*ooO^.\OO.**oOO/[,OOOo.,oOOOOoO@@.\O^=\O`=OO.,^.Oo,O@@O./O@^/O@@@@@@@@@@Oo^......
       ..,OOOOOoo^..,O\,oOO`.=/OOOOOOOO.*oO@@`*\O@@.*O\.\OOOOO.=o.\o.\O@O.o@@/O@@@@@@@@@OOOoo*.....
      ..*oOOO@@OO`..*oO^.=OO..,,\]\`o^*./oo\,\\OOO@\/,o[oOO@@@.=\^=O^\O@@.OOOO@@@@@@@@@@@@OOO^.....
      .*=OO/[*..*,^/OoOO.=O\.]/OOO/.=OO^[\O@O^.=\@@@/.*/OOOOO@`/o\]/OO@@@\=@@@@@@@@@@@@@@@OOOo**...
      ..***/o\oooOOO..],.=O@.,oOO\O^[OO^,oOO`.,/OOOO.o/^=O@`/O\/O@./O@OOO@]O@@@@@@@@@@@@O@OOOo**...
      ...oOOOOOOOOOO/../OO@@`=\^\o^]]/OO.oOOOO.oO@@@^`/\=/O=OOOO@^./O@@@@@^O@@@@@@@@@@@@OOOOOo***..
       .**=oOOO@O`..**oO^OO@O]``,oOO@@@^,,O@@O *O@@@^,oO=/^/O@@@.]OO@@O@@@^=O@@@@@@@@@O@@@OOOo****.
       ..,`=^/*..]//oOOO.`O@O./,o[OO@@@^ *o@OO..oO@@^.oO/OO//O@`/O@@@OO@O@^=@@@@@@@@@@O@@OOOoo*****
       ....*=o.\OOOOO@@/.*oO^.oO@O[[OOO\.*\OOO^.oO@@^,oO\OO@=@OO@@@@@@@OO@@O@@@@@@@@@OOOOOOOo^****.
        ..... .\OO@@@/..,oO@@\.*/O@`,oOO]*/O@OO,/OOOOOOOOO/\OOOOOOOOOOOOOOO@@@@@@@@@OOOOOOOOo^*****
        ...   *=OO@/..*]O/\oOO`.*OO/`,\`]]oOOOOoOOOOOOOOOOOO@@O@@@@@@@@@@@@@@@@@@@@@@@OOOoOooo*****
       .      .*OO`.]/OO@@\**o`/OOOOOO[OOOO@@@@@@@@@@@@@@@O//O@@@@@@@@@@@@@@@@@@@@@@@OOOOOOooo^****
      ..     ..*/./OO@@@@@@`..=oO@@@@.*O@OOOO\OOOOOOOOOOOOOO@@@@@@@@@@@@@@@@@@@@@@@@@@OOOOoooo^****
            ....,\OOOOO[[`...,O@@@@O..=O@@@^.=O@@@@OO@@@@@@O@@@@@@@@@@@@@@@@@@@@@@@@@OOOOOoooo^****
             .....,OOOOOoO]oOO@@@@/../O@@@@..\O@@@@,\@@@@@@@@@@@@@@@@@@@O@@@@@@@@@@OOOOOOooooo/****
              ....**,=OOOO^oOO@@@^.,oO@@@@^..O@@@@@*\@@@@@@^O@@@@@@@@@@O@@@OO@OOOOOOOOOOOooooo^****
               ...**.*[\O^..=OOO/.,/O@@@@^..oO@@@@O./O@@@@@OO@@@@@@@@@@@@@@O@OOOOOOOOOOOOooooo*****
                .......*.....=OO^,OO@@@O[../O@@@@@^./O@@@@O=O@@@@@@@@@@@@@@@OOOOOOOOOOOOoooooo*****
                ..............,OO@O@O/O/OOO@@O@@@@/`O@@@OO/O@@@@@@@@@OO@@@OOOO@@@@@OOOOooooooo^****
                ........ .....**=OO@@@O@O@@@@@@@@@O/@@@@@@OO@@@@@@@@@@@@OOOOOO@@@@OOOOooooooo^*****
                 ......    ...**]oO@@@@@@@@@@@@@@@@@@@@OOO@@@OOOOOOOOOOOOOOOOO@@@OOOOOooooooo`*****
                     ..    .....**]]/]/OOOO\O@@@@@@@@@@@@@OOOOOoOOOOOOOOOOOOO@@@OOOOOooooooo*******
                           ......*,oooOoOOOOOO\,=OOOOooooooOOOOOoOoOOOOOO@@@@@@OOOOOoooooooo*******
                           .......***\oooOOoooooooooOOoooooooOOooooOO@@@@@@@@OOOOOOooooooo//*******
                             ......******o`***=oooooo[[o/ooooOOOO@@@@@@@@@OOOOOOOOoooooooo*********
                                  .......`.....**....***[,OO@@@@@@@@@@@@OOOOOOOOoooooooooo*********
                                       .[\OOOO\]]]/OOOOO@@@@@@@@@@@@@@OOOOOOOOooooooooooo**********
                                            ,\OOOOOOOOOOOO@@@@@@@@OOOOOOOOOOOoooooooooooo**********
''') 
代码缩略图
运行结果
世平回答于

#coding=utf-8

print(' *')

print(' * - *')

print(' * *')

print(' * = 五仁 = *')

print(' * *')

print(' * - *')

print(' *')

大脸猫个人主页 https://www.yzdlm.com回答于
<?php 
//将内容进行UNICODE编码
function unicode_encode($name)
{
    $name = iconv('UTF-8', 'UCS-2', $name);
    $len = strlen($name);
    $str = '';
    for ($i = 0; $i < $len - 1; $i = $i + 2)
    {
        $c = $name[$i];
        $c2 = $name[$i + 1];
        if (ord($c) > 0)
        {    // 两个字节的文字
            $str .= '\u'.base_convert(ord($c), 10, 16).base_convert(ord($c2), 10, 16);
        }
        else
        {
            $str .= $c2;
        }
    }
    return $str;
}

// 将UNICODE编码后的内容进行解码,
function unicode_decode($name)
{
    // 转换编码,将Unicode编码转换成可以浏览的utf-8编码
    $pattern = '/([\w]+)|(\\\u([\w]{4}))/i';
    preg_match_all($pattern, $name, $matches);
    if (!empty($matches))
    {
        $name = '';
        for ($j = 0; $j < count($matches[0]); $j++)
        {
            $str = $matches[0][$j];
            if (strpos($str, '\\u') === 0)
            {
                $code = base_convert(substr($str, 2, 2), 16, 10);
                $code2 = base_convert(substr($str, 4), 16, 10);
                $c = chr($code).chr($code2);
                $c = iconv('UCS-2', 'UTF-8', $c);
                $name .= $c;
            }
            else
            {
                $name .= $str;
            }
        }
    }
    return $name;
}

$yuebing = unicode_encode("月饼");
echo unicode_decode($yuebing);

以上就是 PHP 版 “程序员过节指南:如何用代码做一个月饼?”

不要急,给你看个宝贝!

点击查看宝贝

北京-宏哥某大厂高级测开,关注宏哥公众号:【北京宏哥】,提前解锁更多测试干货修改于

有多少童鞋们被领导画过大饼(被画过大饼的给宏哥来个赞),值此中秋之际宏哥没有什么要给你们的,画上一个月饼送上中秋满满滴祝福!!!希望大家喜欢。

#@Author   : 北京-宏哥
#@公众号   : 北京宏哥
#@Date     : 2021/09/17 
#@Software : PyCharm
#@version  : Python 3.7.3
#@File     : MoonCake.py

import turtle
 
 
class MidAutumnFestival(object):
    def __init__(self):
        self.turtle = turtle.Pen()
        self.turtle.speed(10)
 
    def __del__(self):
        turtle.done()  # 用来结束时保留画面的消失
        self.turtle.down()
 
    def goto(self, x, y):
        self.turtle.penup()
        self.turtle.goto(x, y)
        self.turtle.pendown()
 
    def circular(self):
        self.turtle.color("#F5E16F", "#839F26")
        self.goto(0, -200)
        self.turtle.begin_fill()
        self.turtle.circle(200)
        self.turtle.end_fill()
 
    def color_edge(self):
        self.goto(0, 0)
        self.turtle.color("#FFA100")
        for _ in range(20):
            self.turtle.right(18)
            self.turtle.begin_fill()
            self.turtle.forward(220)
            self.turtle.circle(40, 180)
            self.turtle.goto(0, 0)
            self.turtle.right(180)
            self.turtle.end_fill()
 
    def in_chart(self):
        self.turtle.color('#F5E16F')
        self.goto(0, -25)
        for _ in range(12):
            self.turtle.begin_fill()
            self.turtle.circle(150, 60)
            self.turtle.left(90)
            self.turtle.circle(150, 60)
            self.turtle.end_fill()
 
    def wirte_words(self, words):
        self.goto(-40, 10)
        self.turtle.color("red")
        self.turtle.write(words, font=("Time", 23, "bold"))
        self.turtle.pendown()
 
    def run(self):
        self.color_edge()
        self.circular()
        self.in_chart()
        self.wirte_words("中秋快乐")
 
 
if __name__ == '__main__':
    maf = MidAutumnFestival()
    maf.run()

代码运行小视频:

代码运行录屏

画的月饼截图:

祝大家中秋节快乐,大家一定要吃好喝好玩好!!!
依旧廖凯回答于

import turtle

def goto(x,y):

turtle.penup()

turtle.goto(x,y)

turtle.pendown()

def yuan():

turtle.color("#8fdb75")

goto(0,-200)

turtle.begin_fill()

turtle.circle(200)

turtle.end_fill()

def huabian():

goto(0,0)

turtle.color("orange")

for _ in range(20):

turtle.right(18)

turtle.begin_fill()

turtle.forward(220)

turtle.circle(40,180)

turtle.goto(0,0)

turtle.right(180)

turtle.end_fill()

def neitu():

turtle.color("#D1C185")

goto(0,-25)

for _ in range(12):

turtle.begin_fill()

turtle.circle(150,60)

turtle.left(90)

turtle.circle(150,60)

turtle.end_fill()

def wirte():

goto(-40,-20)

turtle.color("orange")

turtle.write('\n\n清馨\n榴莲',font=('Time',30,'bold'))

turtle.done()

if __name__ == '__main__':

turtle.speed(20)

huabian()

yuan()

neitu()

wirte()

turtle.done()

如有乐享

腾云先锋 · 腾云先锋(TDP)成员 (已认证)

分享一切能分享的内容回答于
用户6572587回答于
Python进阶者该社区将不定期分享各种技术干货、学习资料等。关注我们,您收获的不只是知识,还有经验与人脉!回答于

走你,直接上代码

# coding: utf-8
from turtle import *
import time

setup(600, 600, 807, 117)
bgcolor("#08203D")


def my_goto(x, y):
    penup()
    goto(x, y)
    pendown()


def coords_axis():
    pencolor("LightGrey")
    pensize(2)
    speed(10)

    my_goto(-300, 0)
    forward(600)
    left(90)

    my_goto(0, -300)
    forward(600)
    right(90)
    my_goto(0, 0)


def ref_line():
    pencolor("Grey")
    pensize(1)
    speed(0)
    row_y = 300
    for i in range(int(600)):
        row_y -= 100
        my_goto(-300, row_y)
        fd(600)
    left(90)

    column_x = -300
    for i in range(int(600)):
        column_x += 100


def TaiChi():
    speed(10)

    color("black")
    begin_fill()
    circle(240, 180)

    color("white")
    begin_fill()
    circle(240, 180)
    end_fill()

    color("black")
    begin_fill()
    circle(120, -180)

    end_fill()

    color("white")
    begin_fill()
    circle(-120, -180)
    end_fill()

    up()
    rt(90)
    fd(160)
    lt(90)
    down()
    color("black")
    begin_fill()
    circle(40)
    end_fill()

    up()
    rt(90)
    fd(240)
    lt(90)
    down()
    color("white")
    begin_fill()
    circle(40)
    end_fill()


my_goto(0, -240)
TaiChi()


def rotation(d):
    up()
    home()
    right(90+ d * n)
    fd(240)
    left(90)

n = 0
try:
    while True:
        tracer(0)
        clear()
        rotation(3)
        TaiChi()
        n += 1
        update()
        time.sleep(0.01)
except:
    print("Exit")
    
#

在Pycharm里边运行之后的效果图如下:

Alex.Kq q q q q回答于

测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试

YMCS下班时间回答于

应该多办一些这里比赛,真好,又能学习,又能看看各位大佬的作品,受益匪浅!

挥刀北上

北京华亿创新信息技术有限公司 · 高级开发工程师 (已认证)

公众号:nodejs全栈开发回答于
用户9434860回答于
申风云计算架构师回答于
用户8721515精神小伙都躺平了回答于
用户8922794回答于

扫码关注腾讯云开发者

领取腾讯云代金券