forked from starve-l/starve-l.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgradient-text.html
188 lines (174 loc) · 7.62 KB
/
gradient-text.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
<!DOCTYPE html>
<html>
<head>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
:root {
--primary-color: #9A97F3;
--secondary-color: #818cab;
--font-color: #e1e1ff;
--bg-color: #161625;
--heading-color: #818cab;
}
body {
background-color: var(--bg-color);
color: var(--font-color);
transition: 0.3s all ease-in;
padding: 25px;
}
* {
font-family: 'Poppins', Helvetica, arial, sans-serif;
}
.light-mode {
background-color: white;
color: black;
transition: 0.3s all ease-in;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
background-color: #dddddd;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
transition: 0.3s all ease-in;
}
li a:hover {
background-color: #111;
transition: 0.3s all ease-in;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/canvasjs/1.7.0/canvasjs.min.js" integrity="sha512-FJ2OYvUIXUqCcPf1stu+oTBlhn54W0UisZB/TNrZaVMHHhYvLBV9jMbvJYtvDe5x/WVaoXZ6KB+Uqe5hT2vlyA==" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/chroma-js/2.1.0/chroma.min.js"></script>
<script>
function toggleLightMode() {
var element = document.body;
element.classList.toggle("light-mode");
}
function trim(s) { return (s.charAt(0) == '#') ? s.substring(1, 7) : s }
function convertToHex(rgb) {
return hex(rgb[0]) + hex(rgb[1]) + hex(rgb[2]);
}
function convertToRGB(hex) {
var color = [];
color[0] = parseInt ((trim(hex)).substring (0, 2), 16);
color[1] = parseInt ((trim(hex)).substring (2, 4), 16);
color[2] = parseInt ((trim(hex)).substring (4, 6), 16);
return color;
}
function resolveNick() {
const applyText = (canvas, text) => {
const ctx = canvas.getContext('2d');
let fontSize = 70;
do {
ctx.font = `${fontSize -= 10}px Minecraft`;
} while (ctx.measureText(text).width > canvas.width);
return ctx.font;
};
let text = document.getElementById("text").value || "Text";
const from = document.getElementById("color1").value || "#771177";
const to = document.getElementById("color2").value || "#7a0000";
const bold = document.getElementById("bold").checked || false;
const italic = document.getElementById("italic").checked || false;
const underlined = document.getElementById("underlined").checked || false;
const strikethrough = document.getElementById("strikethrough").checked || false;
const obfuscated = document.getElementById("obfuscated").checked || false;
let join = "";
if (bold) join = "&l" + join;
if (italic) join = "&o" + join;
if (underlined) join = "&n" + join;
if (strikethrough) join = "&m" + join;
if (obfuscated) join = "&k" + join;
let join1 = "";
if (bold) join1 = "<bold>" + join1;
if (italic) join1 = "<italic>" + join1;
if (underlined) join1 = "<underlined>" + join1;
if (strikethrough) join1 = "<strikethrough>" + join1;
if (obfuscated) join1 = "<obfuscated>" + join1;
const canvas = document.getElementById("nick");
const ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height)
ctx.strokeStyle = '#771177';
ctx.strokeRect(0, 0, canvas.width - 1, canvas.height - 1);
ctx.font = applyText(canvas, text);
let gradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
gradient.addColorStop(0, from);
gradient.addColorStop(1, to);
ctx.fillStyle = gradient;
ctx.textAlign = "center";
ctx.shadowColor = "black";
ctx.shadowBlur = 0;
ctx.shadowOffsetX = 7;
ctx.shadowOffsetY = 7;
ctx.fillText(text, canvas.width / 2, canvas.height / 1.7);
let scale = chroma.scale([from, to]);
let length = parseInt(text.split("").length);
let obj = [];
for (let i = 1; i < length + 1; i++) {
let ts = 1 / length * i;
obj.push(scale(ts).hex());
}
let nickCmd = [];
let nickCmd1 = [];
let nickCmd2 = [];
for (let x = 0; x < length; x++) { nickCmd.push("&" + obj[x] + join + text.charAt(x)); }
document.getElementById("cmd").innerHTML = nickCmd.join("");
for (let y = 0; y < length; y++) { nickCmd1.push("{" + obj[y] + "}" + join + text.charAt(y)); }
document.getElementById("cmd1").innerHTML = nickCmd1.join("");
for (let z = 0; z < 1; z++) { nickCmd2.push("<gradient:"+from+":"+to+">"+join1+text); }
nickCmd2.push("</gradient>")
document.getElementById("cmd2").innerHTML = nickCmd2.join("")
}
</script>
</head>
<body>
<ul>
<li><a href="./">Home</a></li>
<li><a href="./tab-animation">Tab Animated Gradient Generator</a></li>
<li><a href="./gradient-text">Gradient Text Generator</a></li>
<li><a href="./cosmonaut">Cosmonaut</a></li>
<li><a href="./projects">Projects</a></li>
<li><a onclick="toggleLightMode()">Toggle light mode</a></li>
</ul>
<center>
<p>Credit to Steve-l for literally everything but the bottom of this page xD {}</p>
<label for="text">Text</label><br>
<input id="text" type="text" placeholder="Text"><br><br>
<label for="color1">First color</label><br>
<input id="color1" type="color" value="#771177"><br><br>
<label for="color2">Second color</label><br>
<input id="color2" type="color" value="#710000"><br><br>
<input type="checkbox" id="bold">
<label for="bold"><b>bold</b></label><br>
<input type="checkbox" id="italic">
<label for="italic"><i>italic</i></label><br>
<input type="checkbox" id="underlined">
<label for="underlined"><u>underlined</u></label><br>
<input type="checkbox" id="strikethrough">
<label for="strikethrough"><s>strikethrough</s></label><br>
<input type="checkbox" id="obfuscated">
<label for="obfuscated">obfuscated</label><br><br>
<button onclick="resolveNick()">Generate Gradient</button>
<p>Tip: You can use this code in essentials nicknames!</p><br>
<p id="cmd"></p>
<p id="cmd1"></p>
<p id="cmd2"></p>
<canvas id="nick"></canvas>
</center>
</body>
</html>