Python:V3.10.4 或以上版本
Turtle:V0.0.1
import turtle as t
def Pattern(num,p_color,f_color,distance,radius): # 绘制外层的饼皮
t.speed(0) # 设置画笔速度
t.pensize(1) # 设置画笔粗细
t.pencolor(p_color) # 设置画笔颜色
for _ in range(num):
t.penup() # 抬起画笔,移动时不进行绘制
t.left(360/num) # 向左旋转画笔方向
t.fillcolor(f_color) # 填充图形颜色
t.begin_fill() # 开始填充
t.forward(distance) # 向当前方向前进
t.pendown() # 放下画笔,进行绘制
t.circle(radius, 180) # 绘制一个圆
t.penup()
t.goto(0, 0) # 将画笔移动至(0,0)点
t.left(180)
t.end_fill() # 结束填充def Draw_dot(num,color,distance,diameter): # 绘制装饰的圆点
t.speed(0)
t.setheading(1.5*360/num) # 设置画笔初始角度
for _ in range(num):
t.penup()
t.left(360/num)
t.forward(distance)
t.pendown()
t.dot(diameter,color)
t.penup()
t.goto(0,0)
def Draw_circle(radius,color): # 绘制中心圆
t.speed(0)
t.setheading(0)
t.goto(0, -radius)
t.pendown()
t.fillcolor(color)
t.begin_fill()
t.circle(radius,360)
t.penup()
t.end_fill()def Draw_texture(x,y,angle,color): # 绘制四周的花纹
t.speed(0)
t.pensize(3)
t.penup()
t.goto(x, y)
t.pendown()
t.color(color)
t.setheading(angle)
t.forward(20)
t.right(90)
t.circle(-100, 30)
t.penup()
t.goto(x, y)
t.pendown()
t.setheading(angle)
t.right(90)
t.circle(-100, 40)
t.left(90)
t.forward(45)
t.left(95)
t.circle(190, 70)
t.left(95)
t.forward(45)
t.left(90)
t.circle(-100, 40)
t.setheading(angle)
t.forward(20)
t.left(90)
t.circle(100, 30)
t.penup()
t.home() # 画笔返回原点
滑动查看完整代码
内层饼身与花纹
def Draw_pi(): # 绘制OpenPie Logo图形
t.speed(10)
t.penup()
t.goto(0, 0)
t.dot(260, "#cf2722")
t.goto(-44, 24)
t.pendown()
## 绘制图形π
t.pencolor("white")
t.fillcolor("white")
t.begin_fill()
t.circle(20, -90)
t.setheading(0)
t.forward(100)
t.circle(-20, 90)
t.setheading(-180)
t.forward(20)
t.setheading(-90)
t.forward(50)
t.circle(10, 90)
t.forward(10)
t.setheading(-90)
t.forward(20)
t.setheading(-180)
t.forward(30)
t.circle(-16, 90)
t.forward(64)
t.setheading(-180)
t.forward(22)
t.setheading(-90)
t.forward(48)
t.circle(-32, 90)
t.setheading(90)
t.forward(80)
t.end_fill()
## 绘制π周围的两条白线
t.penup()
t.goto(0, 130)
t.pendown()
t.pensize(3)
t.setheading(-10)
t.circle(-120, 188)
t.penup()
t.goto(0, -130)
t.pendown()
t.setheading(170)
t.circle(-120, 188)
步骤 4:“裱”上文字
def Write(text,x,y,color,font,size): # 绘制文字
t.speed(3)
t.penup()
t.goto(x,y)
t.pendown()
t.pencolor(color)
t.write(text, align="center", font=(font,size,"bold"))
填充馅料与祝福语
if __name__ == "__main__": # 调用定义的函数
## 绘制外层的饼身
Pattern(20,"#dd6d47","#dd6d47",280,46)
Pattern(20,"#dd6d47","white",240,40)
## 绘制装饰的圆点
Draw_dot(20,"#dd6d47",245,10)
## 绘制中心圆
Draw_circle(220,"#dd6d47")
## 绘制四周的花纹
Draw_texture(16,160,90,"white")
Draw_texture(-160,16,180,"white")
Draw_texture(-16,-160,270,"white")
Draw_texture(160,-16,360,"white")
## 绘制图形π
Draw_pi();
## 绘制文字
Write("中",-120,90,"white","Comic Sans MS",50)
Write("秋",120,90,"white","Comic Sans MS",50)
Write("快",-120,-150,"white","Comic Sans MS",50)
Write("乐",120,-150,"white","Comic Sans MS",50)
t.done() # 停止绘制,窗口不关闭