本帖最后由 吴侯辰 于 2022-6-12 14:53 编辑
[Python] 纯文本查看 复制代码 import turtle
turtle.setup(1000,600)
tutu = turtle.Turtle()
tutu.speed(0)
tutu.goto(-400,200)
tutu.write('给个提示,按1画芯片;按2画眼睛;按3画头;按4画天线;按5画嘴;按6画脖子;按7画肚子', font=("宋体", 15))
def draw_circle(radius, color):
tutu.pendown()
tutu.color(color)
tutu.begin_fill()
tutu.circle(radius)
tutu.end_fill()
tutu.penup()
tutu.seth(0)
def draw_rectangle(width, height, color):
tutu.pendown()
tutu.color(color)
tutu.begin_fill()
for i in range(2):
tutu.forward(width)
tutu.left(90)
tutu.forward(height)
tutu.left(90)
tutu.end_fill()
tutu.forward(width/2)
tutu.pencolor('black')
tutu.seth(270)
tutu.forward(10)
tutu.penup()
tutu.seth(0)
def draw_triangle(length, color):
tutu.pendown()
tutu.color(color)
tutu.begin_fill()
for i in range(3):
tutu.forward(length)
tutu.left(120)
tutu.end_fill()
tutu.penup()
tutu.seth(0)
def draw_xxx(color):
tutu.pendown()
tutu.color(color)
tutu.begin_fill()
for i in range(2):
tutu.forward(60)
tutu.left(90)
tutu.forward(5)
tutu.left(90)
tutu.end_fill()
tutu.left(90)
tutu.forward(5)
tutu.right(90)
tutu.forward(25)
tutu.left(90)
tutu.fillcolor(color)
tutu.begin_fill()
for i in range(2):
tutu.forward(20)
tutu.left(90)
tutu.forward(5)
tutu.left(90)
tutu.end_fill()
tutu.seth(0)
tutu.forward(25)
tutu.seth(90)
tutu.begin_fill()
for i in range(2):
tutu.forward(40)
tutu.left(90)
tutu.forward(5)
tutu.left(90)
tutu.end_fill()
tutu.penup()
tutu.seth(0)
def draw_triangleww(length, color):
tutu.pendown()
tutu.color(color)
tutu.begin_fill()
for i in range(3):
tutu.forward(length)
tutu.left(120)
tutu.end_fill()
tutu.penup()
tutu.seth(0)
def draw_rectangleqq(width,height, color):
tutu.pendown()
for i in range(3):
tutu.color(color)
tutu.begin_fill()
for i in range(2):
tutu.forward(width)
tutu.right(90)
tutu.forward(height)
tutu.right(90)
tutu.end_fill()
tutu.forward(width/2)
tutu.right(90)
tutu.forward(height*2)
tutu.right(90)
tutu.forward(width/2)
tutu.seth(0)
tutu.forward(width/2)
tutu.right(90)
tutu.forward(200)
tutu.seth(0)
tutu.penup()
def draw_circlexx(radius, color):
tutu.pendown()
tutu.color(color)
tutu.begin_fill()
tutu.circle(radius)
tutu.end_fill()
tutu.penup()
tutu.seth(0)
turtle.onscreenclick(tutu.goto, 1)
def draw_face():
draw_triangle(100, "blue")
def draw_eye():
draw_circle(10, "red")
def draw_body():
draw_rectangle(150, 100, "yellow")
def draw_bodytwo():
draw_xxx("red")
def draw_mouth():
draw_triangleww(20, "pink")
def draw_脖子():
draw_rectangleqq(50,10,"brown")
def draw_肚子():
draw_circlexx(100, "green")
turtle.onkeypress(draw_face, "1")
turtle.onkeypress(draw_eye, "2")
turtle.onkeypress(draw_body, "3")
turtle.onkeypress(draw_bodytwo, "4")
turtle.onkeypress(draw_mouth, "5")
turtle.onkeypress(draw_脖子,"6")
turtle.onkeypress(draw_肚子,"7")
turtle.listen()
turtle.done()
|