自定义弹幕
文章目录
- 自定义弹幕
- 程序讲解
-
- 初始
- 加入弹幕和字体
- 执行
- 程序
- 可改进的地方
- 其他
程序讲解
初始
前四行是分别导入easygui,turtle,time,random四个库。
t.colormode (255)为切换颜色模式(模式切换:参数填1.0或255)
t.setup(700,700)是将画布调为边长是700的正方形。
words =[],font=[]创建两个空列表,为以后加入弹幕和字体做准备
s=[“normal”,“bold”,“italic”]创建列表
加入弹幕和字体
a=g.integerbox(“请输入您需要弹幕的个数(1–100)”,title=“自定义弹幕”,default="",lowerbound=1,upperbound=100)
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLiAzNfRHLGZkRGZkRfJ3bs92YsYTMfVmepNHL3VEVNhXRE9keVpHW3BjMMBjVtJWd0ckW65UbM5WOHJWa5kHT20ESjBjUIF2X0hXZ0xCMx81dvRWYoNHLrdEZwZ1Rh5WNXp1bwNjW1ZUba9VZwlHdssmch1mclRXY39CXldWYtlWPzNXZj9mcw1ycz9WL49zZuBnL5YTN3IjMxcTM5ITMwEjMwIzLc52YucWbp5GZzNmLn9Gbi1yZtl2Lc9CX6MHc0RHaiojIsJye.png)
for k in range (a):
b=g.enterbox(“请输入您的弹幕(最好10字以内)”,title=“自定义弹幕”,default="")
words.append(b)
以上是添加弹幕的程序
c=g.integerbox(“请输入您需要字体的个数(1–100)”,title=“自定义弹幕”,default="",lowerbound=1,upperbound=100)
for l in range ©:
d=g.enterbox(“请输入您的字体的名称”,title=“自定义弹幕”,default="")
font.append(d)
以上是添加字体的程序
g.msgbox(“字形为电脑定义”)
g.msgbox(“字体大小为电脑定义(30—40)”)
g.msgbox(“弹幕范围为电脑定义(-200—200随机)”)
执行
cishu=g.integerbox(“请输入您循环的次数(1–100000000000)”,title=“自定义弹幕”,default="",lowerbound=1,upperbound=100)
z=g.buttonbox(“请选择”,title=“自定义弹幕”,choices=(“按顺序跳出弹幕”,“随机跳出弹幕”))
if z==“随机跳出弹幕”:
w=g.buttonbox(“请选择”,title=“自定义弹幕”,choices=(“跳出弹幕1次清理一次”,“最后清除”))
if w==“跳出弹幕1次清理一次”:
for i in range (cishu):
t.penup()
t.goto(r.randint(-120,120),r.randint(-120,120))
t.pendown()
t.color(r.randint(0,255),r.randint(0,255),r.randint(0,255))
t.write(r.choice(words),align=“center”,font = (r.choice(font),r.randint(30,40),r.choice(s)))
time.sleep(0.25)
t.clear()
elif w==“最后清除”:
for i in range (cishu):
xx=cishu % a
t.penup()
t.goto(r.randint(-200,200),r.randint(-200,200))
t.pendown()
t.color(r.randint(0,255),r.randint(0,255),r.randint(0,255))
t.write(words[xx],align=“center”,font =(r.choice(font),r.randint(30,40),r.choice(s)))
time.sleep(0.25)
t.clear()
if z==“按顺序跳出弹幕”:
w=g.buttonbox(“请选择”,title=“自定义弹幕”,choices=(“跳出弹幕1次清理一次”,“最后清除”))
if w==“跳出弹幕1次清理一次”:
for i in range (cishu):
t.penup()
t.goto(r.randint(-120,120),r.randint(-120,120))
t.pendown()
t.color(r.randint(0,255),r.randint(0,255),r.randint(0,255))
t.write(r.choice(words),align=“center”,font = (r.choice(font),r.randint(30,40),r.choice(s)))
time.sleep(0.25)
t.clear()
elif w==“最后清除”:
for i in range (cishu):
xx=cishu % a
t.penup()
t.goto(r.randint(-200,200),r.randint(-200,200))
t.pendown()
t.color(r.randint(0,255),r.randint(0,255),r.randint(0,255))
t.write(words[xx],align=“center”,font = (r.choice(font),r.randint(30,40),r.choice(s)))
time.sleep(0.25)
t.clear()
以上就把具体解释了,懂的都懂。(手动狗头)
程序
import easygui as g
import turtle as t
import time
import random as r
t.colormode (255)
t.setup(700,700)
words =[]
font=[]
s=["normal","bold","italic"]
a=g.integerbox("请输入您需要弹幕的个数(1--100)",title="自定义弹幕",default="",lowerbound=1,upperbound=100)
for k in range (a):
b=g.enterbox("请输入您的弹幕(最好10字以内)",title="自定义弹幕",default="")
words.append(b)
c=g.integerbox("请输入您需要字体的个数(1--100)",title="自定义弹幕",default="",lowerbound=1,upperbound=100)
for l in range (c):
d=g.enterbox("请输入您的字体的名称",title="自定义弹幕",default="")
font.append(d)
g.msgbox("字形为电脑定义")
g.msgbox("字体大小为电脑定义(30—40)")
g.msgbox("弹幕范围为电脑定义(-200—200随机)")
t.hideturtle()
cishu=g.integerbox("请输入您循环的次数(1--100000000000)",title="自定义弹幕",default="",lowerbound=1,upperbound=100)
z=g.buttonbox("请选择",title="自定义弹幕",choices=("按顺序跳出弹幕","随机跳出弹幕"))
if z=="随机跳出弹幕":
w=g.buttonbox("请选择",title="自定义弹幕",choices=("跳出弹幕1次清理一次","最后清除"))
if w=="跳出弹幕1次清理一次":
for i in range (cishu):
t.penup()
t.goto(r.randint(-120,120),r.randint(-120,120))
t.pendown()
t.color(r.randint(0,255),r.randint(0,255),r.randint(0,255))
t.write(r.choice(words),align="center",font = (r.choice(font),r.randint(30,40),r.choice(s)))
time.sleep(0.25)
t.clear()
elif w=="最后清除":
for i in range (cishu):
xx=cishu % a
t.penup()
t.goto(r.randint(-200,200),r.randint(-200,200))
t.pendown()
t.color(r.randint(0,255),r.randint(0,255),r.randint(0,255))
t.write(words[xx],align="center",font =(r.choice(font),r.randint(30,40),r.choice(s)))
time.sleep(0.25)
t.clear()
if z=="按顺序跳出弹幕":
w=g.buttonbox("请选择",title="自定义弹幕",choices=("跳出弹幕1次清理一次","最后清除"))
if w=="跳出弹幕1次清理一次":
for i in range (cishu):
t.penup()
t.goto(r.randint(-120,120),r.randint(-120,120))
t.pendown()
t.color(r.randint(0,255),r.randint(0,255),r.randint(0,255))
t.write(r.choice(words),align="center",font = (r.choice(font),r.randint(30,40),r.choice(s)))
time.sleep(0.25)
t.clear()
elif w=="最后清除":
for i in range (cishu):
xx=cishu % a
t.penup()
t.goto(r.randint(-200,200),r.randint(-200,200))
t.pendown()
t.color(r.randint(0,255),r.randint(0,255),r.randint(0,255))
t.write(words[xx],align="center",font = (r.choice(font),r.randint(30,40),r.choice(s)))
time.sleep(0.25)
t.clear()
可改进的地方
在这个程序里,背景是白色的,可以用turtle.bgcolor()(括号里加颜色的英文单词)或用turtle.bgpic(r"图片位置")。
如果没有easegui的话,可以用input改一下或下载一个。
其他
这是本人第一篇文章,欢迎讨论。
未经作者授权禁止转载!!!