用户:
果敢的超能鸭CNOW查看:0 回复:0 评论:0 创建时间:2024-06-14T19:08:27
【作品展示】

【作品介绍】
把大黄鸡颜色顺序颠倒,是种什么样的体验?这里,有8种不同颜色的大黄鸡,一起去看看吧!
【作品源代码】
import random
import turtle
n = random.randint(0, 7)
t = turtle.Pen()
t.speed(0)
colors = ['black', 'gold', 'brown', 'skyblue', 'white',
'coral', 'darkred', 'deepskyblue']
t.pencolor(colors[((0 + n) % 8)])
def head():
t.penup()
t.goto(0, (-100))
t.pendown()
t.begin_fill()
t.fillcolor(colors[((1 + n) % 8)])
t.circle(100)
t.end_fill()
t.penup()
def glasses():
# 左镜框
t.penup()
t.goto(20, 50)
t.pencolor(colors[((2 + n) % 8)])
t.pensize(10)
t.setheading(0)
t.pendown()
t.fillcolor(colors[((3 + n) % 8)])
t.begin_fill()
t.forward(60)
t.circle(8, 90)
t.forward(30)
t.circle(8, 90)
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()
t.forward(60)
t.circle((-8), 90)
t.forward(30)
t.circle((-8), 90)
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(colors[((4 + n) % 8)])
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(colors[((4 + n) % 8)])
t.pendown()
t.forward(25)
t.penup()
t.goto((-30), 65)
t.pendown()
t.forward(12)
def face():
# 右眼睛
t.pencolor(colors[((0 + n) % 8)])
t.pensize(5)
t.penup()
t.goto(55, 15)
t.pendown()
t.setheading(110)
t.circle(20, 140)
t.penup()
# 左眼睛
t.goto((-55), 15)
t.pendown()
t.setheading(70)
t.circle((-20), 140)
t.penup()
# 嘴巴(外)
t.goto((-15), (-10))
t.pensize(1)
t.pencolor(colors[((5 + n) % 8)])
t.fillcolor(colors[((5 + n) % 8)])
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()
# 嘴巴(里)
t.penup()
t.goto(12, (-10))
t.setheading(120)
t.pencolor(colors[((6 + n) % 8)])
t.fillcolor(colors[((6 + n) % 8)])
t.begin_fill()
t.circle(14, 120)
t.setheading((-60))
t.circle(14, 120)
t.end_fill()
colors[((6 + n) % 8)]
def hands():
# 左手
t.penup()
t.goto(100, 0)
t.pensize(1)
t.pencolor(colors[((0 + n) % 8)])
t.setheading((-10))
t.pendown()
t.fillcolor(colors[((1 + n) % 8)])
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()
# 右手
t.penup()
t.goto((-100), 0)
t.setheading(190)
t.pendown()
t.fillcolor(colors[((1 + n) % 8)])
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()
def hat():
# 蓝色部分
t.penup()
t.goto(50, 96)
t.pencolor(colors[((7 + n) % 8)])
t.fillcolor(colors[((7 + n) % 8)])
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.pencolor(colors[((2 + n) % 8)])
t.fillcolor(colors[((2 + n) % 8)])
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 draw():
head()
face()
hat()
glasses()
hands()
turtle.done()
#开始进入Python的世界
draw()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn