猫史档案馆


【Python作品分享】【奇遇之旅】长隆动物园------“国宝”熊猫【作品秀】

用户:OzerOzer查看:0 回复:1 评论:0 创建时间:2021-07-12T10:24:32


【作品展示】

center_image

 

【作品介绍】

动物园动物介绍,让大家了解熊猫等动物

 

【作品源代码】

#大黄鸡开头
import turtle
import time

#import pyttsx


#engine=pyttsx.init()
t = turtle.Pen()
s = turtle.Screen()

t.hideturtle()#隐藏画笔
t.speed(0)
s.tracer(0)

def head(color=None):
    is_wounded = False
    if not color:
        color = "yellow"
        is_wounded = True

    t.penup()
    t.goto(0, -100)
    t.pendown()
    t.begin_fill()
    t.color(color)
    t.circle(100)
    t.end_fill()

    if is_wounded:
        # 伤痕
        t.penup()
        t.goto(-60, -50)
        t.setheading(45)
        t.pensize(8)
        t.pencolor("gray")
        t.pendown()
        t.forward(20)
        t.penup()
        t.goto(-40, -50)
        t.pendown()
        t.forward(16)

def face(eye=("up", "black"), nose="darkred", mouth="coral"):
    # 设置画眼睛
    t.pencolor(eye[1])
    t.pensize(5)

    def draw_eye(eye):
        if eye[0] == "down":
            # 左眼睛
            t.penup()
            t.goto(-55, 25)
            t.pendown()
            t.setheading(-70)
            t.circle(20, 140)
            # 右眼睛
            t.penup()
            t.goto(55, 25)
            t.pendown()
            t.setheading(-110)
            t.circle(-20, 140)
        elif eye[0] == "open":
            # 左眼睛
            t.penup()
            t.goto(-55, 25)
            t.pendown()
            t.setheading(-70)
            t.dot(16)
            # 右眼睛
            t.penup()
            t.goto(55, 25)
            t.pendown()
            t.setheading(-110)
            t.dot(16)
        else:
            # 左眼睛
            t.penup()
            t.goto(-55, 15)
            t.pendown()
            t.setheading(70)
            t.circle(-20, 140)
            # 右眼睛
            t.penup()
            t.goto(55, 15)
            t.pendown()
            t.setheading(110)
            t.circle(20, 140)

    def draw_nose(nose):
        t.penup()
        t.goto(-15, -10)
        t.pensize(1)
        t.color(nose)
        t.setheading(-90)
        t.pendown()
        t.begin_fill()
        t.circle(15, 180)
        for i in range(10):
            t.forward(3)
            t.left(7)
        t.left(20)
        t.backward(2)
        t.left(20)
        for i in range(10):
            t.forward(3)
            t.left(7)
        t.end_fill()

    def draw_mouth(mouth):
        # 嘴巴(外)
        t.penup()
        t.goto(12, -10)
        t.setheading(120)
        t.color(mouth)
        t.begin_fill()
        t.circle(14, 120)
        t.setheading(-60)
        t.circle(14, 120)
        t.end_fill()

    draw_eye(eye)
    draw_nose(nose)
    draw_mouth(mouth)

def hands(color="yellow"):
    # 左手
    t.pensize(1)
    t.penup()
    t.goto(-100, 0)
    t.setheading(190)
    t.pendown()
    t.color(color)
    t.begin_fill()
    for i in range(7):
        t.forward(9)
        t.left(6)
    for i in range(19):
        t.forward(1)
        t.left(6)
    for i in range(7):
        t.forward(9)
        t.left(5)
    t.end_fill()
    # 右手
    t.penup()
    t.goto(100, 0)
    t.setheading(-10)
    t.pendown()
    t.fillcolor(color)
    t.begin_fill()
    for i in range(7):
        t.forward(9)
        t.right(6)
    for i in range(19):
        t.forward(1)
        t.right(6)
    for i in range(7):
        t.forward(9)
        t.right(5)
    t.end_fill()

# 引擎
def engines(size=10):
    def engine(x, y):
        t.pensize(1)
        t.setheading(0)
        # 外圆位置
        t.penup()
        t.goto(x, y)
        t.pendown()
        # 画外圆
        t.color("black", "yellow")
        t.begin_fill()
        t.circle(-size)
        t.end_fill()
        # 内圆位置
        t.penup()
        t.goto(x, y - 4)
        t.pendown()
        # 画内圆
        t.setheading(0)
        t.color("black", "brown")
        t.begin_fill()
        t.circle(-size + 4)
        t.end_fill()

    # 左引擎
    engine(-100, -40)
    engine(-130, -40)
    # 右引擎
    engine(100, -40)
    engine(130, -40)

def seat(chair_color="brown"):
    # 护栏
    t.penup()
    t.goto(50, 96)
    t.color("deepskyblue")
    t.pensize(1)
    t.pendown()
    t.begin_fill()
    t.setheading(90)
    t.circle(10, 90)
    t.forward(10)
    t.setheading(90)
    t.forward(10)
    t.circle(5, 90)
    t.forward(50)
    t.circle(5, 90)
    t.forward(10)
    t.setheading(180)
    t.forward(10)
    t.circle(10, 90)
    t.setheading(0)
    t.forward(100)
    t.end_fill()
    # 坐椅
    t.penup()
    t.goto(20, 122)
    t.color(chair_color)
    t.setheading(90)
    t.pendown()
    t.begin_fill()
    t.forward(15)
    t.circle(5, 90)
    t.forward(30)
    t.circle(5, 90)
    t.forward(15)
    t.end_fill()

def glasses(color="skyblue"):
    # 左镜框
    t.penup()
    t.goto(20, 50)
    t.pencolor("brown")
    t.pensize(10)
    t.setheading(0)
    t.pendown()
    t.fillcolor(color)
    t.begin_fill()
    for i in range(2):
        t.forward(60)
        t.circle(8, 90)
        t.forward(30)
        t.circle(8, 90)
    t.end_fill()
    # 右镜框
    t.penup()
    t.goto(-20, 50)
    t.setheading(180)
    t.pendown()
    t.begin_fill()
    for i in range(2):
        t.forward(60)
        t.circle(-8, 90)
        t.forward(30)
        t.circle(-8, 90)
    t.end_fill()
    # 眼镜连接
    t.penup()
    t.goto(-6, 70)
    t.setheading(0)
    t.pensize(20)
    t.pendown()
    t.forward(13)
    # 左镜片光泽
    t.penup()
    t.goto(50, 65)
    t.setheading(45)
    t.pensize(8)
    t.pencolor("white")
    t.pendown()
    t.forward(25)
    t.penup()
    t.goto(70, 65)
    t.pendown()
    t.forward(12)
    # 右镜片光泽
    t.penup()
    t.goto(-50, 65)
    t.setheading(45)
    t.pensize(8)
    t.pencolor("white")
    t.pendown()
    t.forward(25)
    t.penup()
    t.goto(-30, 65)
    t.pendown()
    t.forward(12)


# 开始绘制
head("yellow")     # 绘制头部,可以改变颜色
hands()          # 绘制手,可以改变颜色
seat()           # 绘制座椅,可以改变颜色
glasses("black")    # 绘制护目镜,可以改变颜色
engines(15)      # 绘制引擎,可以改变大小
face(eye=("up", "black"), nose="darkred", mouth="coral")     # 绘制脸部
#文字

t.goto(-300,200)
t.write("出发,去长隆动物园!", font=("文泉驿正黑", 50))
time.sleep(1)#等待1秒
t.clear()


#engine.say('熊猫')
t.rt(-120)
t.up()
t.pensize(6)
t.goto(180, 150)



t.color('black')
t.circle(190, 100)
t.fd(20)
for i in range(260):
    t.fd(1)
    t.lt(0.5)
for i in range(8):
    t.fd(19)
    t.lt(1)
for i in range(260):
    t.fd(1)
    t.lt(0.5)
t.up()
t.goto(-70, -16)
t.setheading(245)
t.down()
for i in range(35):
    t.fd(1.5)
    t.lt(0.5)
for i in range(5):
    t.fd(1.5)
    t.lt(0.0125)
for i in range(9):
    t.fd(0.75)
    t.lt(1.5)
for i in range(22):
    t.fd(1)
    t.lt(0.3)
for i in range(20):
    t.fd(1)
    t.lt(3)
for i in range(180):
    t.fd(1)
    t.lt(0.20)
for i in range(20):
    t.fd(1)
    t.lt(3)
for i in range(22):
    t.fd(1)
    t.lt(0.3)
for i in range(9):
    t.fd(0.75)
    t.lt(1.5)
for i in range(5):
    t.fd(1.5)
    t.lt(0.0125)
for i in range(25):
    t.fd(1.5)
    t.lt(0.5)
t.up()
t.goto(-65, -119)
t.down()
t.begin_fill()
t.color('black')
t.setheading(280)
t.circle(30, 135)
t.end_fill()
t.up()
t.goto(50, -129)
t.down()
t.begin_fill()
t.color('black')
t.setheading(305)
t.circle(30, 135)
t.end_fill()
t.up()
t.goto(200, 118)
t.down()
t.begin_fill()
t.color('black')
t.setheading(20)
t.circle(50, 210)
t.end_fill()
t.up()
t.goto(-70, 227)
t.down()
t.begin_fill()
t.color('black')
t.setheading(103)
t.circle(50, 230)
t.end_fill()
t.up()
t.goto(117, -40)
t.setheading(25)
t.down()
t.begin_fill()
t.color('black')
for i in range(70):
    t.fd(1)
    t.lt(-0.5)
for i in range(160):
    t.fd(0.25)
    t.lt(-0.9)
for i in range(70):
    t.fd(1)
    t.lt(-0.65)
t.end_fill()
t.up()
t.goto(-75, -25)
t.setheading(155)
t.down()
t.begin_fill()
t.color('black')
for i in range(70):
    t.fd(1)
    t.lt(0.5)
for i in range(160):
    t.fd(0.25)
    t.lt(0.85)
for i in range(70):
    t.fd(1)
    t.lt(0.65)
t.end_fill()
t.up()
t.goto(-45, 80)
t.begin_fill()
t.color('black')
t.down()
t.circle(25.25)
t.end_fill()
t.up()
t.goto(-50.5, 74.5)
t.begin_fill()
t.color('black')
t.down()
t.circle(26.25)
t.end_fill()
t.up()
t.goto(-43, 100)
t.begin_fill()
t.color('white')
t.down()
t.circle(5.5)
t.end_fill()
t.up()
t.goto(100, 67)
t.begin_fill()
t.color('black')
t.down()
t.circle(25.25)
t.end_fill()
t.up()
t.goto(105.5, 63.5)
t.begin_fill()
t.color('black')
t.down()
t.circle(25.25)
t.end_fill()
t.up()
t.goto(96, 92)
t.begin_fill()
t.color('white')
t.down()
t.circle(5.5)
t.end_fill()
t.up()
t.goto(105, 40)
t.begin_fill()
t.color('tomato')
a = 0.45
t.down()
t.setheading(270)
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a+0.045
        t.lt(3)
        t.fd(a)
    else:
        a = a-0.045
        t.lt(3)
        t.fd(a)
t.end_fill()
t.up()
t.goto(-60, 50)
t.begin_fill()
t.color('tomato')
a = 0.4
t.down()
t.setheading(90)
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a+0.04
        t.lt(3)
        t.fd(a)
    else:
        a = a-0.04
        t.lt(3)
        t.fd(a)
t.end_fill()
t.up()
t.goto(20, 75)
t.begin_fill()
t.color('black')
t.setheading(125)
t.down()
for i in range(25):
    t.fd(0.75)
    t.lt(-1)
for i in range(20):
    t.fd(0.25)
    t.lt(-4.5)
for i in range(30):
    t.fd(0.75)
    t.lt(-1)
for i in range(20):
    t.fd(0.25)
    t.lt(-4.5)
for i in range(25):
    t.fd(0.75)
    t.lt(-1)
for i in range(20):
    t.fd(0.25)
    t.lt(-4.5)
t.end_fill()
t.up()
t.setheading(260)
t.goto(23, 75)
t.down()
for i in range(45):
    t.fd(1)
    t.lt(3)
t.up()
t.setheading(260)
t.goto(23, 75)
t.down()
for i in range(45):
    t.fd(1)
    t.lt(-3)
t.color('red')

t.up()
t.goto(-380, -200)
t.pencolor("black")
t.down()
t.write("大熊猫(学名:Ailuropoda melanoleuca)",font=("文泉驿正黑",20))            
time.sleep(0.5)
t.goto(-380, -230) 
t.write("属于食肉目、熊科、大熊猫亚科",font=("文泉驿正黑",20)) 
time.sleep(0.5)
t.goto(-380, -260) 
time.sleep(0.5)
t.write("大熊猫已在地球上生存了至少800万年",font=("文泉驿正黑",20)) 
t.goto(-380, -290) 
time.sleep(0.5)
t.write("被誉为“活化石”和“中国国宝”",font=("文泉驿正黑",20)) 


turtle.done()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
Vincent_xiaoboVincent_xiaobo

这......这是怎么回事?

center_image

点赞0


评论