用户:钢铁龘齾查看:0 回复:0 评论:0 创建时间:2019-12-06T17:41:43
【作品展示】

【作品介绍】
自己试吧,图片随便发的
【作品源代码】
import turtle
import random
import time
t = turtle.Pen()
t.speed(0)
def first(color):
t.penup()
t.right(90)
t.forward(100)
t.setheading(0)
t.backward(50)
t.pendown()
t.fillcolor(color)
t.begin_fill()
t.pencolor(color)
for x in range(2):
t.forward(100)
t.left(90)
t.forward(5)
t.left(90)
t.end_fill()
def second(color_b):
t.penup()
t.forward(50)
t.left(90)
t.forward(5)
t.left(90)
t.forward(2)
t.pendown()
t.fillcolor(color_b)
t.begin_fill()
t.setheading(90)
t.pencolor(color_b)
t.forward(100)
for c in range(45):
t.forward(2)
t.left(2)
t.right(90)
t.forward(4)
t.right(90)
for v in range(45):
t.forward(2)
t.right(2)
t.forward(106)
t.right(90)
t.forward(4)
t.end_fill()
def third(color_c):
t.penup()
t.right(90)
t.forward(100)
for b in range(44):
t.forward(2)
t.left(2)
t.pendown()
t.pencolor(color_c)
t.fillcolor(color_c)
t.begin_fill()
t.right(90)
for n in range(30):
t.forward(2)
t.left(3)
t.left(90)
t.forward(60)
t.left(90)
for n in range(25):
t.forward(2)
t.left(3)
t.end_fill()
def fourth():
t.penup()
t.left(90)
t.forward(39)
t.right(90)
t.forward(3)
t.left(110)
t.pendown()
t.fillcolor('white')
t.begin_fill()
t.pencolor('white')
for m in range(90):
t.forward(0.3)
t.left(2)
t.end_fill()
def draw():
for x in range(20):
colors = ['red', 'yellow', 'blue', 'green', 'orange', 'purple', 'pink', 'brown', 'magenta', 'cyan']
q = random.choice(colors)
w = random.choice(colors)
r = random.choice(colors)
e = random.choice(colors)
while (q == r or w == r or e == r or q == w or w == e or q == e):
print("画笔颜色{},{},{},背景颜色{}中有重复,现在重新挑选。".format(q,w,e,r))
q = random.choice(colors)
w = random.choice(colors)
e = random.choice(colors)
r = random.choice(colors)
print('-----------------------------------挑选成功------------------------------------------')
print("颜色:{},{},{},背景颜色:{}".format(q, w, e, r))
turtle.bgcolor(r)
first(q)
second(w)
third(e)
fourth()
print('-----------------------------------------------------------------------------------------------')
print('第', (x + 1), '个台灯已画完')
print('')
print('')
print('')
time.sleep(3)
t.goto(0, 0)
t.clear()
draw()
turtle.done()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn