-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.html
214 lines (154 loc) · 6.31 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="apple-moblie-web-app-capable" content="yes">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<title>DYText Tool</title>
<link rel="stylesheet" href="./css/main.css">
<script src="https://cdn.bootcss.com/gif.js/0.2.0/gif.js"></script>
<script src="./js/dytext.js"></script>
</head>
<body>
<header>
<h2>抖音风格的文字生成器v1.2</h2>
<details class="menu" close>
<summary class="title">提示</summary>
<p>由于是国外的服务器,GIF功能有可能因为网速原因失灵,请刷新重试</p>
<p>欢迎微信扫码关注二维码</p>
</details>
</header>
<div id="main">
<div id="preview"></div>
<div id="edit">
<div class="option" style="width:100%;">
<div class="title">更改内容</div>
<input type="text" maxlength="24" class="shadow" value="HELLO WORLD" id="word">
</div>
<div class="option" style="display: none">
<div class="title">字体大小</div>
<input type="range" step="1" min="10" onchange="changeFontSize()" id="fontSize" value="44">
</div>
<div class="option" style="display: none">
<div class="title">抖动幅度</div>
<input type="range" step="2" min="1" onchange="changeSeed()" id="seed" value="1.8">
</div>
<div class="option" style="display: none">
<div class="title">切割线</div>
<div class="rowDisplay">
<input id="isdev" type="checkbox" onchange="changeDev()">
<label for="isdev" id="isdev_label">显示</lable>
</div>
</div>
<div class="option" style="display: none">
<div class="title">图片格式</div>
<div class="radioGroup">
<div class="rowDisplay">
<input id="type_png" type="radio" name="type" onchange="changeType()" checked>
<label for="type_png">PNG</lable>
</div>
<div class="rowDisplay">
<input id="type_gif" type="radio" name="type" onchange="changeType()">
<label for="type_gif">GIF</lable>
</div>
</div>
</div>
</div>
</div>
<footer>
<img src="./img/logo_text_long.png" class="logo">
<p>MIT License by shadow</p>
</footer>
<script>
var dytext;
var type_png = false;
var previewElement = document.querySelector('#preview');
var wordElement = document.querySelector('#word');
var fontSizeElement = document.querySelector('#fontSize');
var seedElement = document.querySelector('#seed');
var typeGifElement = document.querySelector('#type_gif');
var typePngElement = document.querySelector('#type_png');
var idDevElement = document.querySelector('#isdev');
setTimeout(function(){
init();
},1000);
wordElement.addEventListener('change', function (e) {
var _w = this.value;
dytext.word = _w;
updatePreview();
});
function init() {
var _ws=["家,是我们一辈子的馋。","所有的精打细算,都是在为爱打算。","人生不过七万六千多顿饭","团圆的每一刻,你都可以留住","让我脸红的,究竟是你,还是酒呢?","我们家不爱花钱,除了为爱花钱。","世界上最远的距离是我看着你,而你看着路。","思念把我变回了小孩","明天有明天的烦恼,今天有今天的刚好。","不冒泡,没机会。","从小的好奇,到大的世界。","记录美好生活","每个人都是一本奇书"];
var _i= ~~(Math.random() * _ws.length);
wordElement.value=_ws[_i];
var _w = wordElement.value,
_fs = fontSizeElement.value,
_s = seedElement.value * 0.03,
_dev = idDevElement.checked;
dytext = new DYText({
word: _w,
color: 'white',
colorBg: '#1F0D1C',
colorLeft: '#00F5EB',
colorRight: '#FF0050',
dev: _dev,
seed: _s,
fontSize: _fs,
divideNum:20
});
updatePreview();
};
function createImg() {
var canvasTarget = document.createElement('canvas'),
ctxTarget = canvasTarget.getContext('2d');
canvasTarget.width = window.innerWidth;
dytext.start();
dytext.toCanvas(ctxTarget);
previewElement.innerHTML = '';
previewElement.appendChild(canvasTarget);
};
function createGif() {
dytext.createGif(function (gif) {
var img = document.createElement('img');
img.src = gif;
previewElement.innerHTML = '';
previewElement.appendChild(img);
})
};
function changeSeed() {
var _s = seedElement.value;
var _seed = 0.03 * _s;
console.log(_seed);
dytext.seed = _seed;
updatePreview();
};
function changeFontSize() {
var _fs = fontSizeElement.value;
var _fontSize = Math.round(0.01 * _fs * 200);
dytext.setFontSize(_fontSize);
updatePreview();
console.log(_fontSize);
};
function changeType() {
var png = typePngElement.checked;
type_png = png;
updatePreview();
// console.log(png)
};
function changeDev() {
var _d = idDevElement.checked;
console.log(_d)
dytext.dev = _d;
updatePreview();
};
function updatePreview() {
if (type_png) {
createImg();
} else {
createGif();
};
};
</script>
</body>
</html>