[python]代码库
import turtle
import random
# 右键恒星,左键星星
w = turtle.Screen()
w.tracer(0)
mypen = turtle.Pen()
mypen.speed(0)
mypen.ht()
o = turtle.Screen()
turtle.bgcolor('midnightblue')
# 画月亮
def t(x,y):
mypen.penup()
mypen.goto(x,y)
mypen.pendown()
t(-200,200)
mypen.dot(100, "lightyellow")
mypen.forward(30)
mypen.dot(100, "midnightblue")
# 定义画星星的函数
def div(size,color):
mypen.pencolor(color)
mypen.begin_fill()
mypen.fillcolor(color)
for i in range(5):
mypen.forward(size)
mypen.left(72)
mypen.forward(size)
mypen.right(144)
mypen.end_fill()
# 随机效果
def random_star():
sizes = [5, 7, 6, 9]
size = random.choice(sizes)
colors = ["yellow","red","gold","orange","violet"]
color = random.choice(colors)
return size,color
print(random_star())
# 鼠标绘制
def cj(x,y):
size, color = random_star()
t(x, y)
div(size=size, color=color)
def cj_dot(x, y):
size, color = random_star()
t(x, y)
mypen.pencolor(color)
mypen.dot(size)
o.onclick(cj_dot,btn=3)
o.onclick(cj, btn=1)
turtle.done()
[源代码打包下载]
初级程序员
by: 本仙女36D 发表于:2022-02-12 15:12:10 顶(1) | 踩(1) 回复
抢沙发
回复评论