XMWAI 0.3.1__tar.gz → 0.5.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- xmwai-0.5.8/MANIFEST.in +5 -0
- {xmwai-0.3.1/XMWAI.egg-info → xmwai-0.5.8}/PKG-INFO +4 -1
- xmwai-0.5.8/XMWAI/__init__.py +14 -0
- xmwai-0.5.8/XMWAI/assets/like.png +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/core.py +138 -8
- xmwai-0.5.8/XMWAI/effects_core.py +205 -0
- xmwai-0.5.8/XMWAI/fortune_core.py +527 -0
- xmwai-0.5.8/XMWAI/gif/__init__.py +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/magic_core.py +4 -2
- xmwai-0.5.8/XMWAI/static/images/bg.jpeg +0 -0
- xmwai-0.5.8/XMWAI/templates/nutrition_pie.html +186 -0
- xmwai-0.5.8/XMWAI/templates//345/210/233/346/204/217/350/217/234/350/260/261.html +60 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/trial_class.py +53 -49
- xmwai-0.5.8/XMWAI/web_core.py +288 -0
- {xmwai-0.3.1 → xmwai-0.5.8/XMWAI.egg-info}/PKG-INFO +4 -1
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI.egg-info/SOURCES.txt +8 -2
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI.egg-info/requires.txt +3 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/setup.py +8 -3
- xmwai-0.3.1/MANIFEST.in +0 -4
- xmwai-0.3.1/XMWAI/__init__.py +0 -11
- xmwai-0.3.1/XMWAI/cookbook_core.py +0 -148
- xmwai-0.3.1/XMWAI/web_core.py +0 -69
- {xmwai-0.3.1 → xmwai-0.5.8}/LICENSE.txt +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/README.md +0 -0
- {xmwai-0.3.1/XMWAI/file → xmwai-0.5.8/XMWAI/assets}/__init__.py +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/bomb_core.py +0 -0
- {xmwai-0.3.1/XMWAI/gif → xmwai-0.5.8/XMWAI/file}/__init__.py +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/file/idiom.json +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/0.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/1.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/10.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/11.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/12.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/13.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/14.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/15.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/16.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/17.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/18.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/19.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/2.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/20.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/21.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/22.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/23.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/24.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/25.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/26.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/27.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/28.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/29.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/3.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/30.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/31.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/32.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/33.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/34.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/35.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/36.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/37.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/38.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/39.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/4.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/40.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/41.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/42.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/43.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/44.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/45.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/46.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/47.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/48.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/49.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/5.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/50.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/51.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/52.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/53.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/54.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/55.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/56.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/57.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/58.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/59.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/6.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/60.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/61.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/62.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/63.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/64.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/65.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/66.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/67.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/68.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/69.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/7.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/70.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/71.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/72.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/73.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/74.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/75.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/76.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/77.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/78.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/79.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/8.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/80.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/81.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/82.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/83.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/84.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/85.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/gif/9.gif +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/idiom_core.py +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/static/burger.js +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/static/images/BottomBun.png +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/static/images/TopBun.png +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/static/images/beef.png +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/static/images/bg.png +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/static/images/cheese.png +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/static/images/lettuce.png +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/static/images/sauce.png +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/static/images/tomato.png +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI/templates/burger.html +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI.egg-info/dependency_links.txt +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/XMWAI.egg-info/top_level.txt +0 -0
- {xmwai-0.3.1 → xmwai-0.5.8}/setup.cfg +0 -0
xmwai-0.5.8/MANIFEST.in
ADDED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: XMWAI
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.8
|
|
4
4
|
Summary: Small code King AI related library
|
|
5
5
|
Home-page: https://github.com/Tonykai88/XMWAI.git
|
|
6
6
|
Author: pydevelopment
|
|
@@ -16,6 +16,9 @@ Requires-Dist: Pillow>=11.1.0
|
|
|
16
16
|
Requires-Dist: opencv-python>=3.4.18.65
|
|
17
17
|
Requires-Dist: numpy>=1.26.0
|
|
18
18
|
Requires-Dist: flask>=3.1.0
|
|
19
|
+
Requires-Dist: pyecharts>=2.0.8
|
|
20
|
+
Requires-Dist: cvzone>=1.6.1
|
|
21
|
+
Requires-Dist: beautifulsoup4>=4.13.3
|
|
19
22
|
Dynamic: author
|
|
20
23
|
Dynamic: author-email
|
|
21
24
|
Dynamic: classifier
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from .core import story, photo, reply, poem, crack, show # 从子模块导入函数到顶层
|
|
2
|
+
from .magic_core import birthday # 从子模块导入函数到顶层
|
|
3
|
+
from .bomb_core import bomb # 从子模块导入函数到顶层
|
|
4
|
+
from .idiom_core import idiom, searchIdiom, get_json_path # 从子模块导入函数到顶层
|
|
5
|
+
from .trial_class import make, get_file_content_as_base64, save_pic, detect_scale, open_image, get_file_content_as_base64_2, cartoon # 从子模块导入函数到顶层
|
|
6
|
+
from .web_core import burger, cookbook # 从子模块导入函数到顶层
|
|
7
|
+
from .effects_core import effects # 从子模块导入函数到顶层
|
|
8
|
+
from .fortune_core import fate, extract_number, extract_text, extract_fortune_description, get_default_data, download_image, web, fate_old # 从子模块导入函数到顶层
|
|
9
|
+
|
|
10
|
+
__all__ = ["story", "photo", "reply", "poem", 'birthday', 'bomb',
|
|
11
|
+
"idiom", "searchIdiom", "get_json_path", "crack", "show",
|
|
12
|
+
"make", "get_file_content_as_base64", "save_pic", "detect_scale", "open_image",
|
|
13
|
+
"get_file_content_as_base64_2", "cartoon", "burger", "cookbook",
|
|
14
|
+
"effects", "fate", "extract_number", "extract_text", "extract_fortune_description", "get_default_data", "download_image", "web", "fate_old"] # 可选:明确导出的内容
|
|
Binary file
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import re
|
|
2
|
-
import requests
|
|
3
|
-
import json
|
|
4
1
|
import os
|
|
2
|
+
import turtle
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
5
|
import zipfile
|
|
6
|
+
import requests
|
|
6
7
|
|
|
7
8
|
|
|
8
|
-
# U1-02 Story GPT
|
|
9
|
+
# U1-02 Story GPT----------------------------------科大讯飞(暂时不用)
|
|
10
|
+
'''
|
|
9
11
|
def story(role, time, address, event, key=""):
|
|
10
12
|
content = role+time+address+event
|
|
11
13
|
url = "https://spark-api-open.xf-yun.com/v1/chat/completions"
|
|
12
14
|
data = {
|
|
13
|
-
"max_tokens":
|
|
15
|
+
"max_tokens": 650, # 回复长度限制
|
|
14
16
|
"top_k": 4, # 灵活度
|
|
15
17
|
"temperature": 0.5, # 随机性
|
|
16
18
|
"messages": [
|
|
17
19
|
{
|
|
18
20
|
# 设置对话背景或赋予模型角色,该设定会贯穿整轮对话,对全局的模型生成结果产生影响。对应作为'role'为'system'时,'content'的值
|
|
19
21
|
"role": "system",
|
|
20
|
-
"content": "
|
|
22
|
+
"content": "我是一个非常会写童话的儿童写作作家,根据我写出的关键词,帮我生成一篇童话故事。(注意:故事必须完整,不能中断,语句必须完整,不准出现断句。)"
|
|
21
23
|
},
|
|
22
24
|
{
|
|
23
25
|
# 对大模型发出的具体指令,用于描述需要大模型完成的目标任务和需求说明。会与角色设定中的内容拼接,共同作为'role'为'system'时,'content'的值
|
|
@@ -35,7 +37,7 @@ def story(role, time, address, event, key=""):
|
|
|
35
37
|
print("秘钥错误!请重新输入!")
|
|
36
38
|
return "秘钥错误!请重新输入!"
|
|
37
39
|
header = {
|
|
38
|
-
"Authorization": "Bearer
|
|
40
|
+
"Authorization": "Bearer HcRhgbaQtGJfoaZTIvEB:MPWLZAgQnKWHKUypRYRQ"
|
|
39
41
|
}
|
|
40
42
|
response = requests.post(url, headers=header, json=data, stream=True)
|
|
41
43
|
|
|
@@ -56,6 +58,49 @@ def story(role, time, address, event, key=""):
|
|
|
56
58
|
s = s.replace('\\', "")
|
|
57
59
|
s = s.replace("n", "")
|
|
58
60
|
return s
|
|
61
|
+
'''
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def story(role, time, address, event, key=""):
|
|
65
|
+
if key == "":
|
|
66
|
+
print("没有秘钥!请提供秘钥!")
|
|
67
|
+
return "没有秘钥!请提供秘钥!"
|
|
68
|
+
elif key != "CaJQ":
|
|
69
|
+
print("秘钥错误!请重新输入!")
|
|
70
|
+
return "秘钥错误!请重新输入!"
|
|
71
|
+
content = role+time+address+event
|
|
72
|
+
url = "https://qianfan.baidubce.com/v2/chat/completions"
|
|
73
|
+
payload = json.dumps({
|
|
74
|
+
"model": "ernie-5.0-thinking-preview",
|
|
75
|
+
"messages": [
|
|
76
|
+
{
|
|
77
|
+
"role": "system",
|
|
78
|
+
"content": "我是一个非常会写童话的儿童写作作家,根据我写出的关键词,帮我生成一篇童话故事。(注意:故事必须完整,不能中断,语句必须完整,不准出现断句,字数在600字以内。)"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
# 对大模型发出的具体指令,用于描述需要大模型完成的目标任务和需求说明。会与角色设定中的内容拼接,共同作为'role'为'system'时,'content'的值
|
|
82
|
+
"role": "user",
|
|
83
|
+
"content": content
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"fps": 8,
|
|
87
|
+
"web_search": {
|
|
88
|
+
"enable": False
|
|
89
|
+
}
|
|
90
|
+
}, ensure_ascii=False)
|
|
91
|
+
headers = {
|
|
92
|
+
'Content-Type': 'application/json',
|
|
93
|
+
'Authorization': 'Bearer bce-v3/ALTAK-cGbxpVA5AbSz6h8nbLaFh/b539762075d55c76d93dc78bcf0a91beeaf0490a'
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
response = requests.request("POST", url, headers=headers, data=payload.encode("utf-8"))
|
|
97
|
+
response.encoding = "utf-8"
|
|
98
|
+
response_data = json.loads(response.text)
|
|
99
|
+
con = response_data["choices"][0]["message"]["content"]
|
|
100
|
+
con = con.replace("\n", "")
|
|
101
|
+
while " " in content:
|
|
102
|
+
con = content.replace(" ", "")
|
|
103
|
+
return con
|
|
59
104
|
# -------------------------------------------------
|
|
60
105
|
|
|
61
106
|
|
|
@@ -134,7 +179,7 @@ def reply(role, content, key=""):
|
|
|
134
179
|
print("秘钥错误!请重新输入!")
|
|
135
180
|
return "秘钥错误!请重新输入!"
|
|
136
181
|
header = {
|
|
137
|
-
"Authorization": "Bearer
|
|
182
|
+
"Authorization": "Bearer HcRhgbaQtGJfoaZTIvEB:MPWLZAgQnKWHKUypRYRQ"
|
|
138
183
|
}
|
|
139
184
|
response = requests.post(url, headers=header, json=data, stream=True)
|
|
140
185
|
|
|
@@ -216,3 +261,88 @@ def crack(name, pwd):
|
|
|
216
261
|
except:
|
|
217
262
|
print("密码错误")
|
|
218
263
|
# ------------------------------------------------
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
# U3-06 码怪图鉴----------------------------------
|
|
267
|
+
# 全局变量,用于保存 turtle 对象
|
|
268
|
+
t = None
|
|
269
|
+
t1 = None
|
|
270
|
+
sc = None
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def init_screen():
|
|
274
|
+
global sc, t, t1
|
|
275
|
+
try:
|
|
276
|
+
# 初始化屏幕
|
|
277
|
+
sc = turtle.Screen()
|
|
278
|
+
sc.setup(618, 795)
|
|
279
|
+
turtle.tracer(0)
|
|
280
|
+
turtle.colormode(255)
|
|
281
|
+
# 初始化 turtle 对象
|
|
282
|
+
t = turtle.Turtle()
|
|
283
|
+
t.penup()
|
|
284
|
+
t1 = turtle.Turtle()
|
|
285
|
+
t1.color("white")
|
|
286
|
+
t1.penup()
|
|
287
|
+
t1.hideturtle()
|
|
288
|
+
except Exception as e:
|
|
289
|
+
print(f"初始化屏幕失败: {e}")
|
|
290
|
+
raise
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def show(name, zd):
|
|
294
|
+
global sc, t, t1
|
|
295
|
+
try:
|
|
296
|
+
if sc is None:
|
|
297
|
+
init_screen()
|
|
298
|
+
# 隐藏之前的元素
|
|
299
|
+
t.hideturtle()
|
|
300
|
+
t1.clear()
|
|
301
|
+
# 设置新的图片和文字
|
|
302
|
+
pic = name + ".gif"
|
|
303
|
+
sc.bgpic("背景.png")
|
|
304
|
+
turtle.addshape(pic)
|
|
305
|
+
t.goto(0, 100)
|
|
306
|
+
t.shape(pic)
|
|
307
|
+
t.showturtle()
|
|
308
|
+
t1.goto(0, -260)
|
|
309
|
+
t1.write(name, font=("STCaiyun", 30, "bold"), align="center")
|
|
310
|
+
t1.goto(0, -320)
|
|
311
|
+
t1.write("战力:" + str(zd), font=("STCaiyun", 30), align="center")
|
|
312
|
+
sc.update()
|
|
313
|
+
except turtle.Terminator:
|
|
314
|
+
print("Turtle 环境已关闭,尝试重新初始化...")
|
|
315
|
+
# 重置全局变量并重新初始化
|
|
316
|
+
reset_environment()
|
|
317
|
+
show(name, zd)
|
|
318
|
+
except FileNotFoundError:
|
|
319
|
+
print(f"找不到图片文件: {pic}")
|
|
320
|
+
except Exception as e:
|
|
321
|
+
print(f"展示码怪失败: {e}")
|
|
322
|
+
except:
|
|
323
|
+
print("图片加载失败")
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def reset_environment():
|
|
327
|
+
"""重置 turtle 环境"""
|
|
328
|
+
global sc, t, t1
|
|
329
|
+
try:
|
|
330
|
+
if sc:
|
|
331
|
+
sc.bye()
|
|
332
|
+
except:
|
|
333
|
+
pass
|
|
334
|
+
sc = None
|
|
335
|
+
t = None
|
|
336
|
+
t1 = None
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def close_environment():
|
|
340
|
+
"""安全关闭 turtle 环境"""
|
|
341
|
+
global sc
|
|
342
|
+
try:
|
|
343
|
+
if sc:
|
|
344
|
+
sc.bye()
|
|
345
|
+
sc = None
|
|
346
|
+
except Exception as e:
|
|
347
|
+
print(f"关闭环境失败: {e}")
|
|
348
|
+
# ------------------------------------------------
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import turtle
|
|
2
|
+
import random
|
|
3
|
+
import time
|
|
4
|
+
import math
|
|
5
|
+
import tkinter as tk
|
|
6
|
+
from importlib.resources import files
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
# ---------------------------
|
|
10
|
+
# 高亮色彩库
|
|
11
|
+
# ---------------------------
|
|
12
|
+
_ALL_VIBRANT_COLORS = [
|
|
13
|
+
"#FF0000", "#FF4500", "#FF8C00", "#FFD700", "#ADFF2F", "#00FF7F",
|
|
14
|
+
"#00FA9A", "#00FFFF", "#1E90FF", "#7B68EE", "#9932CC", "#FF69B4",
|
|
15
|
+
"#FF1493", "#FF00FF", "#FF7F50", "#FFA500", "#40E0D0", "#7FFF00",
|
|
16
|
+
"#FF5733", "#FFC300", "#DAF7A6", "#C70039", "#900C3F", "#581845"
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
# ---------------------------
|
|
20
|
+
# 资源文件获取函数
|
|
21
|
+
# ---------------------------
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_resource_path(filename: str) -> str:
|
|
25
|
+
"""返回包内资源的绝对路径"""
|
|
26
|
+
return str(files("XMWAI.assets").joinpath(filename))
|
|
27
|
+
|
|
28
|
+
# ---------------------------
|
|
29
|
+
# 特效函数
|
|
30
|
+
# ---------------------------
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _effect_stars(screen):
|
|
34
|
+
"""炫彩星星闪烁"""
|
|
35
|
+
t = turtle.Turtle(visible=False)
|
|
36
|
+
t.speed(0)
|
|
37
|
+
t.hideturtle()
|
|
38
|
+
screen.tracer(False)
|
|
39
|
+
|
|
40
|
+
stars = [(random.randint(-250, 250), random.randint(-180, 200),
|
|
41
|
+
random.randint(10, 30)) for _ in range(30)]
|
|
42
|
+
|
|
43
|
+
for _ in range(12): # 闪烁次数
|
|
44
|
+
t.clear()
|
|
45
|
+
for x, y, size in stars:
|
|
46
|
+
t.penup()
|
|
47
|
+
t.goto(x, y)
|
|
48
|
+
t.pendown()
|
|
49
|
+
t.color(random.choice(_ALL_VIBRANT_COLORS))
|
|
50
|
+
t.begin_fill()
|
|
51
|
+
for _ in range(5):
|
|
52
|
+
t.forward(size)
|
|
53
|
+
t.right(144)
|
|
54
|
+
t.end_fill()
|
|
55
|
+
screen.update()
|
|
56
|
+
time.sleep(0.07)
|
|
57
|
+
|
|
58
|
+
t.clear()
|
|
59
|
+
screen.update()
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _effect_like(screen, img_path=None, flash_times=1, flash_interval=0.2):
|
|
63
|
+
"""点赞动画"""
|
|
64
|
+
screen.tracer(False)
|
|
65
|
+
canvas = screen.getcanvas()
|
|
66
|
+
img_path = img_path or get_resource_path("like.png")
|
|
67
|
+
|
|
68
|
+
tk_img = tk.PhotoImage(file=img_path)
|
|
69
|
+
screen._tk_img_ref = tk_img # 保持引用
|
|
70
|
+
|
|
71
|
+
w = screen.window_width()
|
|
72
|
+
h = screen.window_height()
|
|
73
|
+
img_id = canvas.create_image(w//4, h//4, image=tk_img)
|
|
74
|
+
|
|
75
|
+
for _ in range(flash_times * 2):
|
|
76
|
+
canvas.itemconfigure(img_id, state='normal')
|
|
77
|
+
screen.update()
|
|
78
|
+
time.sleep(flash_interval)
|
|
79
|
+
canvas.itemconfigure(img_id, state='hidden')
|
|
80
|
+
screen.update()
|
|
81
|
+
time.sleep(flash_interval)
|
|
82
|
+
|
|
83
|
+
canvas.delete(img_id)
|
|
84
|
+
screen.update()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _effect_fireworks(screen):
|
|
88
|
+
"""极速瞬爆烟花"""
|
|
89
|
+
t = turtle.Turtle(visible=False)
|
|
90
|
+
t.speed(0)
|
|
91
|
+
t.hideturtle()
|
|
92
|
+
screen.tracer(False)
|
|
93
|
+
|
|
94
|
+
fireworks = []
|
|
95
|
+
for _ in range(random.randint(3, 6)):
|
|
96
|
+
start_x = random.randint(-300, 300)
|
|
97
|
+
peak_y = random.randint(150, 280)
|
|
98
|
+
fireworks.append({
|
|
99
|
+
"x": start_x,
|
|
100
|
+
"y": peak_y,
|
|
101
|
+
"particles": [
|
|
102
|
+
(random.uniform(0, 360), random.uniform(
|
|
103
|
+
80, 220), random.choice(_ALL_VIBRANT_COLORS))
|
|
104
|
+
for _ in range(random.randint(100, 180))
|
|
105
|
+
],
|
|
106
|
+
"color": random.choice(["white", "gold", "yellow"])
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
for y in range(-250, 0, 80):
|
|
110
|
+
t.clear()
|
|
111
|
+
for fw in fireworks:
|
|
112
|
+
t.penup()
|
|
113
|
+
t.goto(fw["x"], y)
|
|
114
|
+
t.dot(8, "white")
|
|
115
|
+
screen.update()
|
|
116
|
+
time.sleep(0.01)
|
|
117
|
+
|
|
118
|
+
steps = 12
|
|
119
|
+
for step in range(1, steps + 1):
|
|
120
|
+
t.clear()
|
|
121
|
+
scale = step / steps
|
|
122
|
+
fade = 1 - scale * 0.7
|
|
123
|
+
for fw in fireworks:
|
|
124
|
+
for angle, dist, color in fw["particles"]:
|
|
125
|
+
r, g, b = screen.cv.winfo_rgb(color)
|
|
126
|
+
r, g, b = int((r / 256) * fade), int((g / 256)
|
|
127
|
+
* fade), int((b / 256) * fade)
|
|
128
|
+
fade_color = f"#{r:02x}{g:02x}{b:02x}"
|
|
129
|
+
x = fw["x"] + math.cos(math.radians(angle)) * \
|
|
130
|
+
(dist * scale ** 1.5)
|
|
131
|
+
y = fw["y"] + math.sin(math.radians(angle)) * \
|
|
132
|
+
(dist * scale ** 1.5)
|
|
133
|
+
t.penup()
|
|
134
|
+
t.goto(x, y)
|
|
135
|
+
if random.random() > 0.1:
|
|
136
|
+
t.dot(max(2, 10 - step * 0.3), fade_color)
|
|
137
|
+
if step < 4:
|
|
138
|
+
t.penup()
|
|
139
|
+
t.goto(fw["x"], fw["y"])
|
|
140
|
+
t.dot(40 - step * 4, fw["color"])
|
|
141
|
+
screen.update()
|
|
142
|
+
time.sleep(0.03)
|
|
143
|
+
|
|
144
|
+
for i in range(3):
|
|
145
|
+
t.clear()
|
|
146
|
+
for fw in fireworks:
|
|
147
|
+
t.penup()
|
|
148
|
+
t.goto(fw["x"], fw["y"])
|
|
149
|
+
if i % 2 == 0:
|
|
150
|
+
t.dot(25, "white")
|
|
151
|
+
else:
|
|
152
|
+
t.dot(18, "gold")
|
|
153
|
+
screen.update()
|
|
154
|
+
time.sleep(0.05)
|
|
155
|
+
|
|
156
|
+
t.clear()
|
|
157
|
+
screen.update()
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _effect_heart(screen):
|
|
161
|
+
"""快速跳动的爱心效果"""
|
|
162
|
+
t = turtle.Turtle(visible=False)
|
|
163
|
+
t.speed(0)
|
|
164
|
+
screen.tracer(False)
|
|
165
|
+
t.color("red", "red")
|
|
166
|
+
|
|
167
|
+
for s in [0.5, 0.7, 0.9, 1.1, 0.9, 1.1, 0.9, 0.7, 0.5]:
|
|
168
|
+
t.clear()
|
|
169
|
+
t.begin_fill()
|
|
170
|
+
t.setheading(140)
|
|
171
|
+
t.forward(120 * s)
|
|
172
|
+
t.circle(-60 * s, 200)
|
|
173
|
+
t.left(120)
|
|
174
|
+
t.circle(-60 * s, 200)
|
|
175
|
+
t.forward(120 * s)
|
|
176
|
+
t.end_fill()
|
|
177
|
+
screen.update()
|
|
178
|
+
time.sleep(0.05)
|
|
179
|
+
|
|
180
|
+
t.clear()
|
|
181
|
+
t.penup()
|
|
182
|
+
t.goto(0, -100)
|
|
183
|
+
t.pendown()
|
|
184
|
+
t.color("black")
|
|
185
|
+
t.write("点赞!", align="center", font=("Arial", 24, "bold"))
|
|
186
|
+
screen.update()
|
|
187
|
+
time.sleep(0.5)
|
|
188
|
+
t.clear()
|
|
189
|
+
screen.update()
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
# ---------------------------
|
|
193
|
+
# 统一接口
|
|
194
|
+
# ---------------------------
|
|
195
|
+
def effects(screen, effect_name: str):
|
|
196
|
+
if effect_name == "stars":
|
|
197
|
+
_effect_stars(screen)
|
|
198
|
+
elif effect_name == "like":
|
|
199
|
+
_effect_like(screen)
|
|
200
|
+
elif effect_name == "fireworks":
|
|
201
|
+
_effect_fireworks(screen)
|
|
202
|
+
elif effect_name == "heart":
|
|
203
|
+
_effect_heart(screen)
|
|
204
|
+
else:
|
|
205
|
+
print(f"未知特效: {effect_name}")
|