如何使用turtle绘制珍珠耳钉

如何使用turtle绘制耳钉

|





这个都是连在一起的,因为图片发不了,就要用turtle库绘制这个耳钉


import turtle as t

def draw_rec(tt, pos, length, head='h'):
    tt.up()
    tt.setpos(pos[0], pos[1])
    tt.seth(0)
         
    if head =='h':
        angle = 30
        height =length
    else:
        angle = 60
        height =length * 3 ** 0.5
    tt.pd()
    
    tt.rt(angle)
    tt.fd(length)
    tt.rt(180 - 2 *angle)
    tt.fd(length)
    tt.rt(2 *angle)
    tt.fd(length)
    tt.rt(180 - 2 *angle)
    tt.fd(length)

    tt.up()
    return tt.xcor(), tt.ycor() - height

T = t.Turtle()
T.hideturtle()
W = 8   # 点大
L = 10  # 菱形长

T.dot(W)
T.seth(-90)
T.fd(W // 2)
T.pd()
T.fd(10)
T.dot(W)
T.fd(W // 2)
xx, yy = draw_rec(T,[T.xcor(), T.ycor()],L,'s' )
T.seth(-90)
T.setpos(xx, yy - W // 2)
T.dot(W)
T.fd(W // 2)
xxx, yyy = draw_rec(T, [T.xcor(), T.ycor()], L, 'h')
T.seth(-90)
T.setpos(xxx, yyy - W // 2)
T.dot(W)

t.done()