forked from xdl/rgb-colour-slider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
239 lines (211 loc) · 6.59 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
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
<html>
<head>
<title>RGB Colour Slider Tool</title>
<style type="text/css">
#drawing {
border: 2px solid black;
background-color: black;
}
table {
margin: 0 auto;
}
#color {
font-family: monospace;
font-size: 12pt;
margin: 4ex 0ex;
}
#controls {
padding: 10px;
margin: 0 auto;
display: inline-block;
text-align: left;
}
#logo {
position: absolute;
top: 10px;
left: 10px;
width: 80px; /* Adjust the width as needed */
}
.notes {
margin: 0 auto;
display: inline-block;
text-align: left;
}
.slider {
width: 300px;
margin: 0px 0px 10px 0px;
}
.slider_label {
margin: 8px 5px 8px 0px;
text-align:right;
}
body {
font-family: "DIN 2014", sans-serif;
text-align: center;
}
p {
max-width:650px;
}
button {
background: white;
border: 2px black solid;
cursor: pointer;
height: 36px;
font-size: 16px;
padding: 0.5rem 0.75rem;
font-weight: 700;
color: black;
font-family: "DIN 2014", sans-serif;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://use.typekit.net/nmg5yzh.css">
<script type="text/javascript">
function hex(k) {
var s = k.toString(16);
if (k < 16) { s = '0' + s; }
return s;
}
function colorChange() {
var r = parseInt(document.getElementById('red').value)
var g = parseInt(document.getElementById('green').value)
var b = parseInt(document.getElementById('blue').value)
$("#color").text("red: " + r + ", green: " + g + ", blue: " + b);
doDraw(hex(r), hex(g), hex(b));
}
function initSlider(id) {
$(id).slider({max: 255, slide: colorChange, change: colorChange});
}
function doDraw(r, g, b) {
var dc = document.getElementById('drawing');
if(dc && dc.getContext) {
var cxt = dc.getContext('2d');
cxt.clearRect(0, 0, dc.width, dc.height);
cxt.globalCompositeOperation = 'lighter';
cxt.strokeStyle = "#000000";
// red
cxt.fillStyle = "#"+r+"0000";
cxt.fillRect(0, 0, dc.width*7/8, dc.height*7/8); // xywh
// green
cxt.fillStyle = "#00"+g+"00";
cxt.fillRect(dc.width/8, 0, dc.width*6/8, dc.height); // xywh
// blue
cxt.fillStyle = "#0000"+b;
cxt.fillRect(dc.width/8, 0, dc.width*7/8, dc.height*7/8); // xywh
}
}
function updateSliders(red, green, blue) {
document.getElementById('red').value = red;
document.getElementById('green').value = green;
document.getElementById('blue').value = blue;
colorChange(); // Trigger the color change event
}
function handleButtonClick(event) {
const preset = event.target.dataset.preset;
switch (preset) {
case 'preset-yellow':
updateSliders(255, 255, 0);
break;
case 'preset-cyan':
updateSliders(0, 255, 255);
break;
case 'preset-magenta':
updateSliders(255, 0, 255);
break;
case 'preset-white':
updateSliders(255, 255, 255);
break;
case 'preset-purple':
updateSliders(100, 0, 150);
break;
case 'preset-pink':
updateSliders(232, 163, 213);
break;
case 'preset-turquoise':
updateSliders(0, 150, 150);
break;
case 'preset-orange':
updateSliders(255, 150, 0);
break;
default:
break;
}
}
$(document).ready(function() {
document.getElementById("red").oninput = colorChange
document.getElementById("green").oninput = colorChange
document.getElementById("blue").oninput = colorChange
const buttons = document.querySelectorAll('#colour-configs button');
buttons.forEach(button => {
button.addEventListener('click', handleButtonClick);
});
})
</script>
</head>
<body>
<img id="logo" src="assets/logo_no_colours.svg" alt="Logo">
<h1>RGB Colour Slider Tool</h1>
<br/>
<br/>
<table>
<tr>
<td> </td>
<td><small>No Color → Dark → Brighter → Full Saturation</small></td>
<td colspan="2"> </td>
</tr>
<tr>
<td valign="top">
<div class="slider_label">Red:</div>
<div class="slider_label">Green:</div>
<div class="slider_label">Blue:</div>
</td>
<td valign="top">
<div id="controls">
<div class="slidecontainer">
<input type="range" min="0" max="255" value="0" class="slider" id="red">
</div>
<div class="slidecontainer">
<input type="range" min="0" max="255" value="0" class="slider" id="green">
</div>
<div class="slidecontainer">
<input type="range" min="0" max="255" value="0" class="slider" id="blue">
</div>
<div id="color">red:0 green:0 blue:0</div>
</div>
</td>
<td>
</td>
<td>
<canvas id="drawing" width="400" height="400">
Sorry, this page requires HTML5 canvas support
</canvas>
</td>
</tr>
</table>
<div class="notes">
<p>
This tool lets you combine red, green, and blue light to make any RGB colour.
</p>
<p>
The sliders control the saturation levels of each colour component, ranging from 0 (none) to 255 (full saturation).
</p>
<p>
The centre shows the resulting RGB colour - the combination of the red, green, and blue light.
</p>
<p>
Try clicking on the colours below to find out what combination of red, blue and green light they are composed of:
</p>
<div id="colour-configs">
<button data-preset="preset-yellow">Yellow</button>
<button data-preset="preset-cyan">Cyan</button>
<button data-preset="preset-magenta">Magenta</button>
<button data-preset="preset-white">White</button>
<button data-preset="preset-purple">Purple</button>
<button data-preset="preset-pink">Pink</button>
<button data-preset="preset-turquoise">Turquoise</button>
<button data-preset="preset-orange">Orange</button>
</div>
</div>
</body>
</html>