自定義彈幕
文章目錄
- 自定義彈幕
- 程式講解
-
- 初始
- 加入彈幕和字型
- 執行
- 程式
- 可改進的地方
- 其他
程式講解
初始
前四行是分别導入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改一下或下載下傳一個。
其他
這是本人第一篇文章,歡迎讨論。
未經作者授權禁止轉載!!!