-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
118 lines (111 loc) · 3.74 KB
/
index.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
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>Демо pixel-gradient-worklet</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap"
rel="stylesheet">
<script>
CSS.paintWorklet.addModule("pixel-gradient-worklet.js")
</script>
</head>
<body>
<h1>Демо pixel-gradient-worklet</h1>
<h2>Кастом</h2>
<p>Попробуйте сами все параметры</p>
<div style="display: flex;">
<div id="testBox" class="box"></div>
<div class="controls" style="display: flex; flex-direction: column;">
<label>
<input type="range" value="90" min="0" max="360" id="rangeAngel"> Угол <span class="code">--gradient-angle</span>
</label>
<label>
<input type="color" id="firstColor"> Первый цвет <span class="code">--gradient-start</span>
</label>
<label>
<input type="color" id="secondColor"> Второй цвет <span class="code">--gradient-end</span>
</label>
<label>
<input type="range" value="10" min="1" max="50" id="rangeSize"> Размер пикселей <span
class="code">--square-size</span>
</label>
<label>
<input type="range" min="0.01" value="20" max="300" id="rangeNoice"> Сила шума <span
class="code">--noise-intensity</span>
</label>
<label>
<button id="updateSeed">Сменить сид</button>
</label>
</div>
</div>
<h2>Менять размер за правый нижний угол</h2>
<p>Подходит для динамических элементов</p>
<textarea resizable disabled class="box"></textarea>
<style>
html,
body {
margin: 0px;
font-family: "Montserrat", sans-serif;
font-optical-sizing: auto;
font-style: normal;
color-scheme: dark;
}
body {
padding-bottom: 5rem;
background-color: #160f0f;
color: #e2d3dc;
}
input[type="range"]{
width: 20rem;
}
.box {
background-image: paint(pixelGradient);
--gradient-start:var(--gradient-startG, #ff3600);
--gradient-end:var(--gradient-endG, #7900ff);
--gradient-angle:var(--gradient-angleG, 105);
--square-size:var(--square-sizeG, 7);
--noise-intensity:var(--noise-intensityG, 21);
--seed:var(--seedG, 12345);
width: 30rem;
height: 30rem;
border-radius: 1rem;
border: 2px solid #680e0e;
}
.code {
font-family: monospace;
background: #ff000029;
padding: 0.1rem 0.3rem;
border-radius: 0.5rem;
}
</style>
<script>
let testBox = document.getElementsByTagName('html')[0]
document.getElementById('rangeAngel').addEventListener('input', (ev) => {
let angle = ev.target.value
testBox.style.setProperty('--gradient-angleG', angle)
})
document.getElementById('firstColor').addEventListener('input', (ev) => {
let firstColor = ev.target.value
testBox.style.setProperty('--gradient-startG', firstColor)
})
document.getElementById('secondColor').addEventListener('input', (ev) => {
let secondColor = ev.target.value
testBox.style.setProperty('--gradient-endG', secondColor)
})
document.getElementById('rangeSize').addEventListener('input', (ev) => {
let rangeSize = ev.target.value
testBox.style.setProperty('--square-sizeG', rangeSize)
})
document.getElementById('rangeNoice').addEventListener('input', (ev) => {
let rangeNoice = ev.target.value
testBox.style.setProperty('--noise-intensityG', rangeNoice)
})
document.getElementById('updateSeed').addEventListener('click', (ev) => {
testBox.style.setProperty('--seedG', Math.random() * 100000000000000000)
})
</script>
</body>
</html>