-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSampleSlider-001.html
305 lines (252 loc) · 10.9 KB
/
SampleSlider-001.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Variable Font Example</title>
<style>
@font-face {
font-family: 'TYPETR-Bitcount-VF';
src: url('fonts/ttf/variable/BitcountInk[CRSV,ELSH,ELXP,SZP1,SZP2,XPN1,XPN2,YPN1,YPN2,slnt,wght].ttf') format('truetype');
/* Add other font properties if needed */
}
#text-container {
width: 80%;
margin: 50px auto;
}
#sample-text {
font-family: 'TYPETR-Bitcount-VF', sans-serif;
font-size: 300px;
}
.slider-container {
margin-bottom: 0px;
}
.slider-container label {
display: block;
}
</style>
</head>
<body>
<div id="text-container">
<div id="sample-text"><span style="font-size: 500px;">/canvasa</span><br/>Bitcount-VF</div>
<div>
<button id="randomButton">Randomize</button>
<button id="randomPixelShapeButton">Randomize Pixel Shape</button>
<button id="randomForegroundButton">Randomize Color Foreground</button>
<button id="randomBackgroundButton">Randomize Color Background</button>
</div>
<div class="slider-container">
<label for="size-slider">Font Size</label>
<input type="range" min="10" max="300" value="180" class="slider" id="size-slider">
</div>
<div class="slider-container">
<label for="weight-slider">Font Weight [wght]</label>
<input type="range" min="100" max="900" value="400" class="slider" id="weight-slider">
</div>
<div class="slider-container">
<label for="ELXP-slider">Pixel Open - Element expansion [ELXP]</label>
<input type="checkbox" id="fixELXP" value="1" checked/>
<input type="range" min="0" max="100" value="0" class="slider" id="ELXP-slider">
</div>
<div class="slider-container">
<label for="ELSH-slider">Element Shape [ELSH]</label>
<input type="checkbox" id="fixELSH" value="1" checked/>
<input type="range" min="0" max="100" value="0" class="slider" id="ELSH-slider">
</div>
<div class="slider-container">
<label for="slant-slider">Slant [slnt]</label>
<input type="range" min="0" max="100" value="1" class="slider" id="slant-slider">
</div>
<div class="slider-container">
<label for="slant-slider">Cursive [CRSV]</label>
<input type="range" min="0" max="1" value="0" class="slider" id="CRSV-slider">
</div>
<h2>COLRv1 axes</h2>
<div class="slider-container">
<label for="SZP2-slider">Foreground Size - Size of Paint 2 [SZP2]</label>
<input type="checkbox" id="fixSZP2" value="1" checked/>
<input type="range" min="0" max="100" value="30" class="slider" id="SZP2-slider">
</div>
<div class="slider-container">
<label for="XPN2-slider">Foreground X [XPN2]</label>
<input type="checkbox" id="fixXPN2" value="1" checked/>
<input type="range" min="0" max="100" value="50" class="slider" id="XPN2-slider">
</div>
<div class="slider-container">
<label for="YPN2-slider">Foreground Y [YPN2]</label>
<input type="checkbox" id="fixYPN2" value="1" checked/>
<input type="range" min="0" max="100" value="50" class="slider" id="YPN2-slider">
</div>
<div class="slider-container">
<label for="SZP1-slider">Background Size - Size of Paint 1 [SZP1]</label>
<input type="checkbox" id="fixSZP1" value="1" checked/>
<input type="range" min="0" max="100" value="30" class="slider" id="SZP1-slider">
</div>
<div class="slider-container">
<label for="XPN1-slider">Background X [XPN1]</label>
<input type="checkbox" id="fixXPN1" value="1" checked/>
<input type="range" min="0" max="100" value="50" class="slider" id="XPN1-slider">
</div>
<div class="slider-container">
<label for="YPN1-slider">Background Y [YPN1]</label>
<input type="checkbox" id="fixYPN1" value="1" checked/>
<input type="range" min="0" max="100" value="50" class="slider" id="YPN1-slider">
</div>
</div>
<script>
// Check if the browser is Chrome
var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
// Function to update the sample text style
function updateTextStyle() {
const weight = document.getElementById('weight-slider').value;
const elementOpen = document.getElementById('ELXP-slider').value;
const elementShape = document.getElementById('ELSH-slider').value;
const slant = document.getElementById('slant-slider').value;
const size = document.getElementById('size-slider').value;
// COLRv1
const fgSize = document.getElementById('SZP2-slider').value;
const fgX = document.getElementById('XPN2-slider').value;
const fgY = document.getElementById('YPN2-slider').value;
const bgSize = document.getElementById('SZP1-slider').value;
const bgX = document.getElementById('XPN1-slider').value;
const bgY = document.getElementById('YPN1-slider').value;
const sampleText = document.getElementById('sample-text');
sampleText.style.fontVariationSettings = `'wght' ${weight}, 'ELXP' ${elementOpen}, 'ELSH' ${elementShape}, 'slnt' ${slant},
'SZP1' ${bgSize}, 'XPN1' ${bgX}, 'YPN1' ${bgY},
'SZP2' ${fgSize}, 'XPN2' ${fgX}, 'YPN2' ${fgY}`;
sampleText.style.fontSize = `${size}px`;
}
// Event listeners for sliders
const sliders = document.querySelectorAll('.slider');
sliders.forEach(slider => {
slider.addEventListener('input', updateTextStyle);
});
// Initial call to set the sample text style
updateTextStyle();
if (isChrome) {
document.write("<p>This page is running on Chrome browser.</p>");
} else {
document.write("<p>This page is not running on Chrome browser.</p>");
}
// Get the sample text element
const sampleText = document.getElementById('sample-text');
angleELSH = 0; // Shaping the pixel
angleELXP = 0; // Open pixel in quadrants
angleSZP1 = 0;
angleXPN1 = 0;
angleYPN1 = 0;
angleSZP2 = 0;
angleXPN2 = 0;
angleYPN2 = 0;
const stepELSH = 4; // Increment of the cycle angles
const stepELXP = 2;
const stepSZP1 = 2.2;
const stepXPN1 = 3.2;
const stepYPN1 = 3;
const stepSZP2 = 2.1;
const stepXPN2 = 4.2;
const stepYPN2 = 4;
stepFactor = 0.5 // Overall speed factor for steps
const minELSH = 0;
const minELXP = 0;
const minSZP1 = 10;
const minXPN1 = 25;
const minYPN1 = 25;
const minSZP2 = 10;
const minXPN2 = 0;
const minYPN2 = 0;
const maxELSH = 100;
const maxELXP = 80; // Not too open in this animation
const maxSZP1 = 90;
const maxXPN1 = 80;
const maxYPN1 = 80;
const maxSZP2 = 60;
const maxXPN2 = 80;
const maxYPN2 = 80;
function normalizeAngle(angle) {
return (angle % 360 + 360) % 360;
}
function updateValues() {
if (document.getElementById('fixELSH').checked) {
valELSH = (Math.sin((angleELSH * Math.PI/180))/2 + 0.5) * (maxELSH - minELSH) + minELSH;
document.getElementById('ELSH-slider').value = valELSH;
}
valELXP = (Math.sin((angleELXP * Math.PI/180))/2 + 0.5) * (maxELXP - minELXP) + minELXP;
document.getElementById('ELXP-slider').value = valELXP;
valSZP1 = (Math.sin((angleSZP1 * Math.PI/180))/2 + 0.5) * (maxSZP1 - minSZP1) + minSZP1;
document.getElementById('SZP1-slider').value = valSZP1;
valXPN1 = (Math.sin((angleXPN1 * Math.PI/180))/2 + 0.5) * (maxXPN1 - minXPN1) + minXPN1;
document.getElementById('XPN1-slider').value = valXPN1;
valYPN1 = (Math.sin((angleYPN1 * Math.PI/180))/2 + 0.5) * (maxYPN1 - minYPN1) + minYPN1;
document.getElementById('YPN1-slider').value = valYPN1;
valSZP2 = (Math.sin((angleSZP2 * Math.PI/180))/2 + 0.5) * (maxSZP2 - minSZP2) + minSZP2;
document.getElementById('SZP2-slider').value = valSZP2;
valXPN2 = (Math.sin((angleXPN2 * Math.PI/180))/2 + 0.5) * (maxXPN2 - minXPN2) + minXPN2;
document.getElementById('XPN2-slider').value = valXPN2;
valYPN2 = (Math.sin((angleYPN2 * Math.PI/180))/2 + 0.5) * (maxYPN2 - minYPN2) + minYPN2;
document.getElementById('YPN2-slider').value = valYPN2;
}
// Function to animate through all axes smoothly
function animateVariableFont() {
updateValues();
if (document.getElementById('fixELSH').checked)
angleELSH = normalizeAngle(angleELSH + stepELSH * stepFactor);
angleELXP = normalizeAngle(angleELXP + stepELXP * stepFactor);
angleSZP1 = normalizeAngle(angleSZP1 + stepSZP1 * stepFactor);
angleXPN1 = normalizeAngle(angleXPN1 + stepXPN1 * stepFactor);
angleYPN1 = normalizeAngle(angleYPN1 + stepYPN1 * stepFactor);
angleSZP2 = normalizeAngle(angleSZP2 + stepSZP2 * stepFactor);
angleXPN2 = normalizeAngle(angleXPN2 + stepXPN2 * stepFactor);
angleYPN2 = normalizeAngle(angleYPN2 + stepYPN2 * stepFactor);
updateTextStyle();
//sampleText.style.fontVariationSettings = "'SZP1' ${valSZP1}, 'XPN1' ${valXPN1}, 'XPN1' ${valXPN1}, 'SZP2' ${valSZP2}, 'XPN2' ${valXPN2}, 'XPN2' ${valXPN2}, ";
}
// Periodically call the function
setInterval(animateVariableFont, 100);
function handleClick() {
alert("Button clicked!");
// Add your JavaScript code here
}
function setRandomValue(slider) {
// Generate a random value between min and max
var randomValue = Math.floor(Math.random() * (parseFloat(slider.max) - parseFloat(slider.min) + 1)) + parseFloat(slider.min);
// Set the slider value to the random value
slider.value = randomValue;
}
function randomize() {
randomizeShape();
randomizeForegroundColor();
randomizeBackgroundColor();
}
function randomizeShape() {
// Set the animation angles to random values, instead of the sliders.
// They get updated anyway.
angleELSH = Math.floor(Math.random() * (maxELSH - minELSH) + minELSH);
updateValues();
}
// COLRv1
function randomizeBackgroundColor() {
angleSZP1 = Math.floor(Math.random() * (maxSZP1 - minSZP1) + minSZP1);
angleXPN1 = Math.floor(Math.random() * (maxXPN1 - minXPN1) + minXPN1);
angleYPN1 = Math.floor(Math.random() * (maxYPN1 - minYPN1) + minYPN1);
updateValues();
}
function randomizeForegroundColor() {
angleSZP2 = Math.floor(Math.random() * (maxSZP2 - minSZP2) + minSZP2);
angleXPN2 = Math.floor(Math.random() * (maxXPN2 - minXPN2) + minXPN2);
angleYPN2 = Math.floor(Math.random() * (maxYPN2 - minYPN2) + minYPN2);
updateValues();
}
// Get the button element
const randomButton = document.getElementById('randomButton');
const randomPixelShapeButton = document.getElementById('randomPixelShapeButton');
const randomForegroundButton = document.getElementById('randomForegroundButton');
const randomBackgroundButton = document.getElementById('randomBackgroundButton');
// Add a click event listener to the button, which calls the handleClick function when clicked
randomButton.addEventListener('click', randomize);
randomPixelShapeButton.addEventListener('click', randomizeShape);
randomForegroundButton.addEventListener('click', randomizeForegroundColor);
randomBackgroundButton.addEventListener('click', randomizeBackgroundColor);
</script>
</body>
</html>