import turtle

t = turtle.Turtle()
t.speed(0)
t.pensize(3)
t.color("blue")

w = 30   # digit width
h = 50   # digit height

def move_to(x, y):
    t.penup()
    t.goto(x, y)
    t.pendown()

# ── digit drawing ─────────────────────────────────────────────────────────────

def draw_0(x, y):
    move_to(x, y)
    t.setheading(0);   t.forward(w)
    t.setheading(270); t.forward(h)
    t.setheading(180); t.forward(w)
    t.setheading(90);  t.forward(h)

def draw_1(x, y):
    move_to(x + w // 2, y)
    t.setheading(270); t.forward(h)

def draw_2(x, y):
    move_to(x, y)
    t.setheading(0);   t.forward(w)
    t.setheading(270); t.forward(h // 2)
    t.setheading(180); t.forward(w)
    t.setheading(270); t.forward(h // 2)
    t.setheading(0);   t.forward(w)

def draw_3(x, y):
    move_to(x, y)
    t.setheading(0);   t.forward(w)
    t.setheading(270); t.forward(h // 2)
    t.setheading(180); t.forward(w)
    move_to(x + w, y - h // 2)
    t.setheading(270); t.forward(h // 2)
    t.setheading(180); t.forward(w)

def draw_4(x, y):
    move_to(x, y)
    t.setheading(270); t.forward(h // 2)
    t.setheading(0);   t.forward(w)
    move_to(x + w, y)
    t.setheading(270); t.forward(h)

def draw_5(x, y):
    move_to(x + w, y)
    t.setheading(180); t.forward(w)
    t.setheading(270); t.forward(h // 2)
    t.setheading(0);   t.forward(w)
    t.setheading(270); t.forward(h // 2)
    t.setheading(180); t.forward(w)

def draw_6(x, y):
    move_to(x + w, y)
    t.setheading(180); t.forward(w)
    t.setheading(270); t.forward(h)
    t.setheading(0);   t.forward(w)
    t.setheading(90);  t.forward(h // 2)
    t.setheading(180); t.forward(w)

digit_map = {
    '0': draw_0, '1': draw_1, '2': draw_2, '3': draw_3,
    '4': draw_4, '5': draw_5, '6': draw_6,
}

# ── 汉字绘制（用 goto 连拐点）────────────────────────────────────────────────
def draw_char(strokes, ox, oy):
    """
    strokes: [ [(x1,y1),(x2,y2),...], [(x1,y1),...], ... ]  每个子列表是一笔
    ox, oy : 平移偏移量（字的左上角基准位置）
    """
    for stroke in strokes:
        if not stroke:
            continue
        t.penup()
        t.goto(stroke[0][0] + ox, stroke[0][1] + oy)
        t.pendown()
        for (x, y) in stroke[1:]:
            t.goto(x + ox, y + oy)
    t.penup()


# ── 「孙」的拐点坐标（9笔 → 6笔）────────────────────────────────────────
SUN_STROKES = [
    [(-42, 66), (-9, 66), (-28, 44)],   # 横折
    [(-30, 43), (-30, -11), (-39, -7)], # 竖弯钩
    [(-43, 19), (-14, 30)],             # 横
    [(1, 42), (-9, 8)],                 # 撇
    [(19, 69), (19, -11), (4, -11)],    # 竖横
    [(34, 42), (44, 8)],                # 捺
]

# ── 「婧」的拐点坐标（11笔 → 10笔）──────────────────────────────────────
JING_STROKES = [
    [(-31, 70), (-35, 19), (-13, -1)],  # 撇
    [(-42, 48), (-12, 43), (-42, -10)], # 横撇
    [(-5, 61), (44, 61)],               # 横
    [(-5, 46), (39, 46)],               # 横
    [(-8, 31), (44, 31)],               # 横
    [(16, 65), (16, 36)],               # 竖
    [(2, 16), (-2, -16)],               # 撇
    [(4, 19), (35, 19), (35, -17)],     # 横竖
    [(6, 8), (36, 8)],                  # 横
    [(6, -3), (34, -3)],                # 横
]

# ── 「晖」的拐点坐标（11笔 → 10笔）──────────────────────────────────────
HUI_STROKES = [
    [(-41, 58), (-41, -4)],             # 竖
    [(-43, 61), (-21, 61), (-21, 5)],   # 横折竖
    [(-33, 31), (-21, 31)],             # 横
    [(-36, 3), (-18, 3)],               # 横
    [(-6, 62), (-6, 55)],               # 竖
    [(-5, 62), (42, 62), (42, 57)],     # 横折
    [(17, 54), (-5, 21), (43, 21)],     # 撇+横
    [(-9, 46), (43, 46)],               # 横
    [(-9, 2), (39, 2)],                 # 横
    [(20, 32), (20, -14)],              # 竖
]

CHAR_DATA = [SUN_STROKES, JING_STROKES, HUI_STROKES]

# ── 学号 ──────────────────────────────────────────────────────────────────
number  = "6203125066"
gap     = w + 15
start_x = -(len(number) * gap) // 2
start_y = 100

for i, c in enumerate(number):
    digit_map[c](start_x + i * gap, start_y)

# ── 姓名 ──────────────────────────────────────────────────────────────────
char_gap   = 120          # 字间距
name_start = -(len(CHAR_DATA) * char_gap) // 2
name_y     = -20          # 名字行 y 基准

for i, strokes in enumerate(CHAR_DATA):
    draw_char(strokes, name_start + i * char_gap, name_y)

t.hideturtle()
turtle.done()
