用python turtle绘制“李”字,一笔一划绘制,居中,蓝色字体
from turtle import *
def run(angle, lenth):
seth(angle)
fd(lenth)
def change(x, y):
penup()
goto(x, y)
pendown()
def writeli():
# change(30, 200)
# run(30, -100)
change(-100,90)
run(0, 200)
change(0, 160)
run(-90, 150)
change(-10, 80)
run(40, -130)
change(10, 80)
run(140, -130)
change(-50, -30)
run(0, 100)
run(40, -80)
run(90, -80)
run(-30, -30)
change(-50, -90)
run(0, 100)
def main():
pensize(10)
pencolor("purple")
setup(400, 800, 200, 200)
writeli()
mainloop()
if __name__ == '__main__':
main()
import turtle
def draw_line(t, pos, length,flag='h'):
t.up()
if flag == 'h':
t.seth(0)
elif flag == 's':
t.seth(-90)
elif flag == 'l':
t.seth(-135)
elif flag == 'r':
t.seth(-45)
elif flag == 'll':
t.seth(-160)
elif flag == 't':# 提
t.seth(135)
t.setpos(pos)
t.pd()
t.fd(length)
t.up()
return t.xcor(), t.ycor(), length
turtle.setup(800,600)
T = turtle.Turtle()
T.pensize("13")
T.pencolor("blue")
curx, cury , le = draw_line(T, (-50, 50), 100, 'h') # '横'
cx,cy , le = curx - le // 2, cury + 20, le - 20
ccx, ccy , le = draw_line(T, (cx, cy), le, 's') # 竖
cccx, cccy, le = draw_line(T, (cx, cury),70,'l' ) # 撇
ccccx, ccccy, le = draw_line(T, (cx, cury),70,'r' ) # 捺
cccccx, cccccy, le = draw_line(T, (ccx - 40, ccy - 20),80,'h' ) # 横
ccccccx, ccccccy, le = draw_line(T, (cccccx, cccccy),40,'ll' ) # 折
cccccccx, cccccccy, le = draw_line(T, (ccccccx, ccccccy),60,'s' ) # 竖
ccccccccx, ccccccccy, le = draw_line(T, (cccccccx, cccccccy),30,'t' ) # 提
ccccccccx, ccccccccy, le = draw_line(T, (ccccccx - 50, ccccccy - 20),100,'h' ) # 横
turtle.done()