精武会徽turtle实现

python
# -*- coding: utf-8 -*-
"""
"精武"体育会盾牌标志 ------ turtle 绘制版(轮廓按原图逐像素提取,比例 1:1 还原)
组成:红色盾形轮廓(顶部双峰夹一谷)+ 红/黄/蓝三颗五角星 + 竖排"精武"
兼容本地 Python 与 python123 在线 turtle 练习场。
"""
import turtle
# ---------------- 可调参数 ----------------
RED = "#D0202E" # 盾牌轮廓 / 红星 / 文字
YELLOW = "#FFD400" # 黄星
BLUE = "#1E88D8" # 蓝星
FONT_NAME = "SimHei" # 在线环境若无此字体,可改 "Microsoft YaHei" 或 "Noto Sans CJK SC"
FONT_SIZE = 42 # 文字大小(上一版 68 太大,已按原图比例缩小)
FAST = True # True=瞬间画完;若在线环境白屏,改为 False
# ------------------------------------------
# 盾牌外轮廓(从原图红色边框外缘逐像素提取并平滑,52 个点)
OUTER = [
(-54.5, 179.4), (-51.1, 179.2), (-40.3, 171.3), (-28.3, 165.8),
(-11.1, 162.3), (18.2, 163.4), (26.0, 165.8), (48.2, 179.2),
(51.6, 179.2), (60.8, 164.2), (73.6, 151.5), (88.6, 141.4),
(101.1, 135.8), (115.3, 132.4), (140.9, 131.8), (146.1, 110.9),
(149.3, 86.5), (149.3, 44.4), (149.0, 46.9), (147.8, 46.2),
(146.1, 20.1), (135.6, -20.1), (119.9, -57.3), (94.6, -96.8),
(66.6, -128.5), (37.1, -154.3), (0.0, -179.4), (-5.5, -178.1),
(-15.8, -171.6), (-47.4, -148.0), (-49.8, -144.2), (-52.2, -144.1),
(-82.1, -114.9), (-102.5, -89.7), (-105.4, -82.6), (-109.5, -79.4),
(-122.3, -57.3), (-131.6, -36.7), (-141.9, -7.5), (-149.2, 25.7),
(-148.6, 30.4), (-151.7, 44.6), (-151.7, 86.5), (-150.1, 88.9),
(-148.5, 110.9), (-143.5, 131.2), (-140.6, 132.8), (-126.4, 131.5),
(-113.8, 133.2), (-88.5, 142.4), (-66.6, 160.0), (-54.6, 179.4),
]
# 盾牌内轮廓(红色边框内缘,35 个点)------ 用于在红色底上抠出白色内部
INNER = [
(-49.5, 165.4), (-31.6, 156.3), (-9.5, 151.3), (20.5, 153.4),
(47.6, 164.9), (64.8, 145.8), (83.7, 132.1), (106.7, 123.7),
(131.9, 121.0), (136.6, 102.3), (139.0, 55.7), (134.3, 17.0),
(126.2, -14.6), (108.4, -55.6), (87.7, -88.1), (65.6, -114.2),
(33.9, -143.1), (0.0, -166.6), (-7.9, -163.7), (-21.3, -154.4),
(-22.2, -151.6), (-29.2, -148.7), (-57.7, -124.4), (-71.8, -110.2),
(-95.3, -81.0), (-109.5, -58.1), (-122.2, -32.0), (-132.5, -2.0),
(-139.8, 35.9), (-141.4, 77.8), (-135.3, 120.4), (-109.8, 123.1),
(-86.1, 132.1), (-64.0, 148.4), (-50.0, 165.3),
]
def setup_screen():
"""初始化画布与画笔"""
screen = turtle.Screen()
try:
screen.setup(width=640, height=660)
screen.title("精武盾牌")
except Exception:
pass # 部分在线环境不支持窗口参数,忽略即可
screen.bgcolor("white")
if FAST:
try:
screen.tracer(0) # 关闭动画,一次成图
except Exception:
pass
pen = turtle.Turtle(visible=False)
pen.speed(0)
return screen, pen
def fill_poly(pen, pts, color):
"""按点集绘制实心多边形"""
pen.penup()
pen.goto(pts[0])
pen.pendown()
pen.pencolor(color)
pen.fillcolor(color)
pen.begin_fill()
for pt in pts[1:]:
pen.goto(pt)
pen.goto(pts[0])
pen.end_fill()
pen.penup()
def draw_star(pen, cx, cy, radius, color, tilt=0):
"""实心五角星:cx/cy 为中心,radius 为外接圆半径,tilt 为旋转角"""
import math
pts = []
for k in range(10):
r = radius if k % 2 == 0 else radius * 0.4 # 外点/内点交替
a = math.radians(tilt + k * 36) # 每步旋转 36 度
pts.append((cx + r * math.sin(a), cy + r * math.cos(a)))
fill_poly(pen, pts, color)
def draw_text(pen):
"""竖排书写红色'精武'二字(write 的锚点在文字底部)"""
pen.penup()
pen.pencolor(RED)
pen.goto(0, -72)
pen.write("精", align="center", font=(FONT_NAME, FONT_SIZE, "bold"))
pen.goto(0, -130)
pen.write("武", align="center", font=(FONT_NAME, FONT_SIZE, "bold"))
def main():
screen, pen = setup_screen()
# 1. 红色实心盾牌底 2. 白色内部 -> 形成红色描边
fill_poly(pen, OUTER, RED)
fill_poly(pen, INNER, "white")
# 3. 三颗五角星(按原图位置与大小)
draw_star(pen, 0, 101, 30, RED) # 顶部红星
draw_star(pen, -58, 39, 31, YELLOW) # 左侧黄星
draw_star(pen, 55, 38, 31, BLUE) # 右侧蓝星
# 4. 文字
draw_text(pen)
if FAST:
try:
screen.update()
except Exception:
pass
turtle.done() # 在线环境若程序不结束,可注释掉本行
main()
声明:著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。