用户:
Herabine查看:1 回复:2 评论:1 创建时间:2022-12-07T19:48:45
当你想画哆啦A梦时:
import turtle
# -*- coding: UTF-8 -*-
# 哆啦A梦
def flyTo(x, y):
turtle.penup()
turtle.goto(x, y)
turtle.pendown()
def drawEye():
turtle.tracer(False)
a = 2.5
for i in range(120):
if (0 <= i < 30 or 60 <= i < 90):
a -= 0.05
else:
a += 0.05
turtle.left(3)
turtle.forward(a)
turtle.tracer(True)
def beard():
""" 画胡子, 一共六根
"""
# 左边第一根胡子
flyTo((-37), 135)
turtle.setheading(165)
turtle.forward(60)
# 左边第二根胡子
flyTo((-37), 125)
turtle.setheading(180)
turtle.forward(60)
# 左边第三根胡子
flyTo((-37), 115)
turtle.setheading(193)
turtle.forward(60)
# 右边第一根胡子
flyTo(37, 135)
turtle.setheading(15)
turtle.forward(60)
# 右边第二根胡子
flyTo(37, 125)
turtle.setheading(0)
turtle.forward(60)
# 右边第三根胡子
flyTo(37, 115)
turtle.setheading((-13))
turtle.forward(60)
def drawRedScarf():
""" 画围巾
"""
# 填充颜色
turtle.fillcolor('red')
turtle.begin_fill()
# 朝向右
turtle.setheading(0)
# 前进10个单位
turtle.forward(200)
turtle.circle((-5), 90)
turtle.forward(10)
turtle.circle((-5), 90)
turtle.forward(207)
turtle.circle((-5), 90)
turtle.forward(10)
turtle.circle((-5), 90)
turtle.end_fill()
def drawMouse():
flyTo(5, 148)
turtle.setheading(270)
turtle.forward(100)
turtle.setheading(0)
turtle.circle(120, 50)
turtle.setheading(230)
turtle.circle((-120), 100)
def drawRedNose():
flyTo((-10), 158)
# 填充颜色
turtle.fillcolor('red')
turtle.begin_fill()
turtle.circle(20)
turtle.end_fill()
def drawBlackdrawEye():
turtle.setheading(0)
flyTo((-20), 195)
# 填充颜色
turtle.fillcolor("#000000")
turtle.begin_fill()
turtle.circle(13)
turtle.end_fill()
turtle.pensize(6)
flyTo(20, 205)
turtle.setheading(75)
turtle.circle((-10), 150)
turtle.pensize(3)
flyTo((-17), 200)
turtle.setheading(0)
turtle.fillcolor("#ffffff")
turtle.begin_fill()
turtle.circle(5)
turtle.end_fill()
flyTo(0, 0)
def drawFace():
"""
"""
# 前行183个单位
turtle.forward(183)
# 填充颜色为白色
turtle.fillcolor('white')
# 开始填充
turtle.begin_fill()
# 左转45度
turtle.left(45)
# 右边那半边脸
turtle.circle(120, 100)
# 朝向向上
turtle.setheading(90)
# 画右眼睛
drawEye()
# 朝向左
turtle.setheading(180)
# 抬笔
turtle.penup()
# 前行60
turtle.forward(60)
# 落笔
turtle.pendown()
# 朝向上
turtle.setheading(90)
# 画左眼睛
drawEye()
# 抬笔
turtle.penup()
# 朝向左
turtle.setheading(180)
# 前进喵
turtle.forward(喵)
# 落笔
turtle.pendown()
# 修改朝向
turtle.setheading(215)
# 左边那半边脸
turtle.circle(120, 100)
turtle.end_fill()
def drawHead():
""" 画了一个被切掉下半部分的圆
"""
# 抬笔
turtle.penup()
# 画圆, 半径150,圆周角40
turtle.circle(150, 40)
# 落笔
turtle.pendown()
# 填充色
turtle.fillcolor("#00a0de")
# 开始填充
turtle.begin_fill()
# 画圆,半径150, 圆周角280
turtle.circle(150, 280)
turtle.end_fill()
def drawAll():
drawHead()
drawRedScarf()
drawFace()
drawRedNose()
drawMouse()
beard()
flyTo(0, 0)
turtle.setheading(0)
turtle.penup()
turtle.circle(150, 50)
turtle.pendown()
turtle.setheading(30)
turtle.forward(40)
turtle.setheading(70)
turtle.circle((-30), 270)
turtle.fillcolor("#00a0de")
turtle.begin_fill()
turtle.setheading(230)
turtle.forward(80)
turtle.setheading(90)
turtle.circle(1000, 1)
turtle.setheading((-89))
turtle.circle((-1000), 10)
turtle.setheading(180)
turtle.forward(70)
turtle.setheading(90)
turtle.circle(30, 180)
turtle.setheading(180)
turtle.forward(70)
turtle.setheading(100)
turtle.circle((-1000), 9)
turtle.setheading((-86))
turtle.circle(1000, 2)
turtle.setheading(230)
turtle.forward(40)
turtle.circle((-30), 230)
turtle.setheading(45)
turtle.forward(81)
turtle.setheading(0)
turtle.forward(203)
turtle.circle(5, 90)
turtle.forward(10)
turtle.circle(5, 90)
turtle.forward(7)
turtle.setheading(40)
turtle.circle(150, 10)
turtle.setheading(30)
turtle.forward(40)
turtle.end_fill()
# 左手
turtle.setheading(70)
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.circle((-30))
turtle.end_fill()
# 脚
flyTo(103.74, (-182.59))
turtle.setheading(0)
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.forward(15)
turtle.circle((-15), 180)
turtle.forward(90)
turtle.circle((-15), 180)
turtle.forward(10)
turtle.end_fill()
flyTo((-96.26), (-182.59))
turtle.setheading(180)
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.forward(15)
turtle.circle(15, 180)
turtle.forward(90)
turtle.circle(15, 180)
turtle.forward(10)
turtle.end_fill()
# 右手
flyTo((-133.97), (-91.81))
turtle.setheading(50)
turtle.fillcolor("#FFFFFF")
turtle.begin_fill()
turtle.circle(30)
turtle.end_fill()
# 口袋
flyTo((-103.42), 15.09)
turtle.setheading(0)
turtle.forward(38)
turtle.setheading(230)
turtle.begin_fill()
turtle.circle(90, 260)
turtle.end_fill()
flyTo(5, (-40))
turtle.setheading(0)
turtle.forward(70)
turtle.setheading((-90))
turtle.circle((-70), 180)
turtle.setheading(0)
turtle.forward(70)
# 铃铛
flyTo((-103.42), 15.09)
turtle.forward(90)
turtle.setheading(70)
turtle.fillcolor("#ffd200")
turtle.begin_fill()
turtle.circle((-20))
turtle.end_fill()
turtle.setheading(170)
turtle.fillcolor("#ffd200")
turtle.begin_fill()
turtle.circle((-2), 180)
turtle.setheading(10)
turtle.circle((-100), 22)
turtle.circle((-2), 180)
turtle.setheading((180 - 10))
turtle.circle(100, 22)
turtle.end_fill()
flyTo((-13.42), 15.09)
turtle.setheading(250)
turtle.circle(20, 110)
turtle.setheading(90)
turtle.forward(15)
turtle.dot(10)
flyTo(0, (-150))
drawBlackdrawEye()
def main():
turtle.screensize(800, 6000, "#F0F0F0")
turtle.pensize(3)
turtle.speed(9)
drawAll()
if (__name__ == '__main__'):
main()
turtle.done()
画完了![]()