2024年5月23日第五十四篇

今天看了一下kotlin感觉在短时间内还是难以学完,于是打算继续用java开发android,然后用tkinter绘制了一个画像玩。

 # 脸部(方形)
    canvas.create_rectangle(x0, y0, x1, y1, fill='peachpuff', outline='black')

    # 头发
    hair_height = face_height // 5
    canvas.create_rectangle(x0, y0, x1, y0 + hair_height, fill='brown', outline='black')

    # 眼睛
    eye_width = face_width // 6
    eye_height = face_height // 8
    eye_y_offset = hair_height + face_height // 4
    eye_x_spacing = face_width // 4

    canvas.create_oval(x0 + eye_x_spacing, y0 + eye_y_offset, x0 + eye_x_spacing + eye_width, y0 + eye_y_offset + eye_height, fill='white', outline='black')
    canvas.create_oval(x1 - eye_x_spacing - eye_width, y0 + eye_y_offset, x1 - eye_x_spacing, y0 + eye_y_offset + eye_height, fill='white', outline='black')
    canvas.create_oval(x0 + eye_x_spacing + eye_width // 3, y0 + eye_y_offset + eye_height // 3, x0 + eye_x_spacing + 2 * eye_width // 3, y0 + eye_y_offset + 2 * eye_height // 3, fill='black')
    canvas.create_oval(x1 - eye_x_spacing - 2 * eye_width // 3, y0 + eye_y_offset + eye_height // 3, x1 - eye_x_spacing - eye_width // 3, y0 + eye_y_offset + 2 * eye_height // 3, fill='black')

    # 鼻子
    nose_width = face_width // 10
    nose_height = face_height // 6
    nose_x = x0 + (x1 - x0) // 2
    nose_y = y0 + face_height // 2

    canvas.create_polygon(nose_x, nose_y, nose_x - nose_width // 2, nose_y + nose_height, nose_x + nose_width // 2, nose_y + nose_height, fill='peachpuff', outline='black')

    # 嘴巴
    mouth_width = face_width // 2
    mouth_height = face_height // 8
    mouth_x0 = x0 + (face_width - mouth_width) // 2
    mouth_y0 = y1 - face_height // 4
    mouth_x1 = mouth_x0 + mouth_width
    mouth_y1 = mouth_y0 + mouth_height

    canvas.create_arc(mouth_x0, mouth_y0, mouth_x1, mouth_y1, start=0, extent=-180, style=ARC, outline='red', width=2)

    # 眼镜框
    glass_width = face_width // 6
    glass_height = face_height // 8
    glass_y_offset = hair_height + face_height // 4
    glass_x_spacing = face_width // 4

    # 左眼镜框
    canvas.create_rectangle(x0 + glass_x_spacing, y0 + glass_y_offset, x0 + glass_x_spacing + glass_width, y0 + glass_y_offset + glass_height, outline='black', width=2)
    # 右眼镜框
    canvas.create_rectangle(x1 - glass_x_spacing - glass_width, y0 + glass_y_offset, x1 - glass_x_spacing, y0 + glass_y_offset + glass_height, outline='black', width=2)

    # 眼镜支架
    bridge_width = face_width // 10
    bridge_height = face_height // 30
    bridge_x1 = x0 + (x1 - x0 - bridge_width) // 2
    bridge_y1 = y0 + eye_y_offset + eye_height // 2
    bridge_x2 = x1 - (x1 - x0 - bridge_width) // 2
    bridge_y2 = bridge_y1

    canvas.create_line(bridge_x1, bridge_y1, bridge_x2, bridge_y2, fill='black', width=2)

 

posted @ 2024-05-23 22:05  石铁生  阅读(3)  评论(0编辑  收藏  举报