-
Notifications
You must be signed in to change notification settings - Fork 0
/
backgroundColor.js
393 lines (342 loc) · 15.4 KB
/
backgroundColor.js
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
function BackColorTool(){
//set an icon and a name for the object
this.icon = "assets/tools/paint.png";
this.name = "BackColorTool";
var r;
var g;
var b;
var backColorPicker;
// verifiers to display the corresponding sliders for the modes:
//RGB, HSB, HSL
var RGBmode = false;
var HSBmode = false;
var HSLmode = false;
var colorPickermode = false;
var self = this;
//set the background color.
//It supports three different color modes: RGB, HSB, and HSL.
this.draw = function() {
if(RGBmode == true)
{
colorMode(RGB);
// retrieves the current values of the:
// red, green, and blue sliders
r = document.getElementById("redSlider").value;
g = document.getElementById("greenSlider").value;
b = document.getElementById("blueSlider").value;
background(r, g, b);
}
else if (HSBmode == true)
{
colorMode(HSB);
//retrieves the current values of the:
// hue, saturation, and brightness sliders
h = document.getElementById("HSlider").value;
s = document.getElementById("SSlider").value;
b = document.getElementById("BSlider").value;
background(h, s, b);
}
else if(HSLmode == true)
{
colorMode(HSL);
//retrieves the current values of the:
// hue, saturation, and lightness sliders
hh = document.getElementById("3HSlider").value;
ss = document.getElementById("3SSlider").value;
ll = document.getElementById("3LSlider").value;
background(hh, ss, ll);
}
else if(colorPickermode == true)
{
colour = backColorPicker.color();
background(colour);
}
}
this.populateOptions = function () {
// slider for size, returns value to size with getelementbyid.value
select(".options").html("<button class='cssbuttons-io-button' id = 'RGB'> RGB <div class='icon'> <svg height='24' width='24' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path d='M0 0h24v24H0z' fill='none'></path><path d='M16.172 11l-5.364-5.364 1.414-1.414L20 12l-7.778 7.778-1.414-1.414L16.172 13H4v-2z' fill='currentColor'></path></svg> </div> </button> <button class='cssbuttons-io-button' id = 'HSB'> HSV <div class='icon'> <svg height='24' width='24' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path d='M0 0h24v24H0z' fill='none'></path><path d='M16.172 11l-5.364-5.364 1.414-1.414L20 12l-7.778 7.778-1.414-1.414L16.172 13H4v-2z' fill='currentColor'></path></svg> </div> </button> <button class='cssbuttons-io-button' id = 'HSL'> HSL <div class='icon'> <svg height='24' width='24' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path d='M0 0h24v24H0z' fill='none'></path><path d='M16.172 11l-5.364-5.364 1.414-1.414L20 12l-7.778 7.778-1.414-1.414L16.172 13H4v-2z' fill='currentColor'></path></svg> </div> </button> <button class='cssbuttons-io-button' id = 'ColorPickER'> ColorPicker <div class='icon'> <svg height='24' width='24' viewBox='0 0 24 24' xmlns='http://www.w3.org/2000/svg'><path d='M0 0h24v24H0z' fill='none'></path><path d='M16.172 11l-5.364-5.364 1.414-1.414L20 12l-7.778 7.778-1.414-1.414L16.172 13H4v-2z' fill='currentColor'></path></svg> </div> </button>");
this.colorRGB();
this.colorHSV();
this.colorHSL();
//button "BACK"
//(for each function): If the "BACK" button is pressed, the function "this.populateOptions()" is called and respectively the bouleans "RGBmode", "HSBmode", "HSLmode" becomes false so that the displayed sliders are hidden again and are show the main buttons "RGB", "HSB", "HSL" to choose the color mode and color for the background of the canvas.
var backButton = createButton("BACK");
backButton.parent(select(".options"));
backButton.class("button");
backButton.id("backButton");
backButton.hide();
//create div for color picker
var divPick = createDiv("COLOR ");
divPick.parent(select('#otherSpace2'));
divPick.class('divPick');
// create color picker
backColorPicker = createColorPicker('#000000');
backColorPicker.parent(divPick);
backColorPicker.class("backColorPicker");
backColorPicker.id("backColorPicker");
divPick.hide();
backColorPicker.hide();
//It hides elements corresponding to other color modes and shows the appropriate COLOR PICKER for controlling the color.
select("#ColorPickER").mouseClicked(function(){
document.getElementById("RGB").style.display = "none";
document.getElementById("HSB").style.display = "none";
document.getElementById("HSL").style.display = "none";
document.getElementById("ColorPickER").style.display = "none";
if(RGBmode == false && HSBmode == false && HSLmode == false)
{
colorPickermode = true;
divPick.show();
backColorPicker.show();
backButton.show();
backButton.style('margin-top', '10px');
select("#backButton").mouseClicked(function(){
divPick.hide();
backColorPicker.hide();
select(".options").html(" ");
select("#otherSpace2").html(" ");
select("#otherSpace3").html(" ");
RGBmode = false;
HSBmode = false;
HSLmode = false;
colorPickermode = false;
self.populateOptions();
});
}
});
//It hides elements corresponding to other color modes and shows the appropriate sliders and divs for controlling the RGB values.
select("#RGB").mouseClicked(function(){
document.getElementById("RGB").style.display = "none";
document.getElementById("HSB").style.display = "none";
document.getElementById("HSL").style.display = "none";
document.getElementById("ColorPickER").style.display = "none";
if(RGBmode == false && HSBmode == false && colorPickermode == false && HSLmode == false);
{
RGBmode = true
sliderR.show();
sliderG.show();
sliderBl.show();
div1.show();
div2.show();
div3.show();
backButton.show();
select("#backButton").mouseClicked(function(){
select(".options").html(" ");
select("#otherSpace2").html(" ");
select("#otherSpace3").html(" ");
RGBmode = false;
HSBmode = false;
HSLmode = false;
colorPickermode = false;
self.populateOptions();
});
}
})
//It hides elements corresponding to other color modes and shows the appropriate sliders and divs for controlling the HSB values.
select("#HSB").mouseClicked(function(){
document.getElementById("RGB").style.display = "none";
document.getElementById("HSB").style.display = "none";
document.getElementById("HSL").style.display = "none";
document.getElementById("ColorPickER").style.display = "none";
if(HSBmode == false && RGBmode == false && colorPickermode == false)
{
HSBmode = true
sliderH.show();
sliderS.show();
sliderB.show();
divA.show();
divB.show();
divC.show();
backButton.show();
select("#backButton").mouseClicked(function(){
select(".options").html(" ");
select("#otherSpace2").html(" ");
select("#otherSpace3").html(" ");
RGBmode = false;
HSBmode = false;
HSLmode = false;
colorPickermode = false;
self.populateOptions();
});
}
});
//It hides elements corresponding to other color modes and shows the appropriate sliders and divs for controlling the HSL values.
select("#HSL").mouseClicked(function(){
document.getElementById("RGB").style.display = "none";
document.getElementById("HSB").style.display = "none";
document.getElementById("HSL").style.display = "none";
document.getElementById("ColorPickER").style.display = "none";
if(HSBmode == false && RGBmode == false && HSLmode == false && colorPickermode == false)
{
HSLmode = true
slider3H.show();
slider3S.show();
slider3L.show();
divI.show();
divII.show();
divIII.show();
backButton.show();
select("#backButton").mouseClicked(function(){
select(".options").html(" ");
select("#otherSpace2").html(" ");
select("#otherSpace3").html(" ");
RGBmode = false;
HSBmode = false;
HSLmode = false;
colorPickermode = false;
self.populateOptions();
});
}
})
}
//Each function creates three sliders for the RGB color mode, as well as three corresponding labels to display the slider values.
//The sliders are initially hidden and the labels are placed inside their own div elements which are also hidden. They will be displayed when "RGB", "HSB", "HSL" button is pressed respectively.
this.colorRGB = function()
{
//SliderRED
sliderR = createSlider(1,255,255);
sliderR.parent(select('.options'));
sliderR.id('redSlider');
sliderR.class('sliderColors');
sliderR.hide();
//SliderGREEN
sliderG = createSlider(1,255,255);
sliderG.parent(select('.options'));
sliderG.id('greenSlider');
sliderG.class('sliderColors');
sliderG.hide();
//SliderBLUE
sliderBl = createSlider(1,255,255);
sliderBl.parent(select('.options'));
sliderBl.id('blueSlider');
sliderBl.class('sliderColors');
sliderBl.hide();
div1 = createDiv()
div1.id('divLabelR')
div1.parent(select('.otherSpace3'));
div2 = createDiv()
div2.id('divLabelG')
div2.parent(select('.otherSpace3'));
div3 = createDiv()
div3.id('divLabelB')
div3.parent(select('.otherSpace3'));
//label SliderR
red = document.createElement('label');
red.innerHTML = "R";
document.getElementById('divLabelR').appendChild(red);
//label SliderG
green = document.createElement('label');
green.innerHTML = "G";
document.getElementById('divLabelG').appendChild(green);
//label SliderBl
blue = document.createElement('label');
blue.innerHTML = "B";
document.getElementById('divLabelB').appendChild(blue);
div1.hide();
div2.hide();
div3.hide();
}
this.colorHSV = function()
{
//SliderHUE
sliderH = createSlider(0,360,360);
sliderH.parent(select('.options'));
sliderH.id('HSlider');
sliderH.class('sliderColors');
sliderH.hide();
//SliderSATURATION
sliderS = createSlider(0,100,100);
sliderS.parent(select('.options'));
sliderS.id('SSlider');
sliderS.class('sliderColors');
sliderS.hide();
//SliderBRIGHTNESS
sliderB = createSlider(0,100,100);
sliderB.parent(select('.options'));
sliderB.id('BSlider');
sliderB.class('sliderColors');
sliderB.hide();
divA = createDiv()
divA.id('divLabelH')
divA.parent(select('.otherSpace3'));
divB = createDiv()
divB.id('divLabelS')
divB.parent(select('.otherSpace3'));
divC = createDiv()
divC.id('divLabelV')
divC.parent(select('.otherSpace3'));
//label SliderHUE
hue = document.createElement('label');
hue.innerHTML = "H";
document.getElementById('divLabelH').appendChild(hue);
//label SliderSATURATION
saturation = document.createElement('label');
saturation.innerHTML = "S";
document.getElementById('divLabelS').appendChild(saturation);
//label SliderBRIGHTNESS
value = document.createElement('label');
value.innerHTML = "V";
document.getElementById('divLabelV').appendChild(value);
divA.hide();
divB.hide();
divC.hide();
}
//<blockquote>
this.colorHSL = function()
{
//SliderHUE
slider3H = createSlider(0,360,360);
slider3H.parent(select('.options'));
slider3H.id('3HSlider');
slider3H.class('sliderColors');
slider3H.hide();
//SliderSATURATION
slider3S = createSlider(0,100,100);
slider3S.parent(select('.options'));
slider3S.id('3SSlider');
slider3S.class('sliderColors');
slider3S.hide();
//SliderLIGHTNESS
slider3L = createSlider(0,100,50);
slider3L.parent(select('.options'));
slider3L.id('3LSlider');
slider3L.class('sliderColors');
slider3L.hide();
divI = createDiv()
divI.id('divLabel3H')
divI.parent(select('.otherSpace3'));
divII = createDiv()
divII.id('divLabel3S')
divII.parent(select('.otherSpace3'));
divIII = createDiv()
divIII.id('divLabel3L')
divIII.parent(select('.otherSpace3'));
//label SliderHUE
hUe = document.createElement('label');
hUe.innerHTML = "H";
document.getElementById('divLabel3H').appendChild(hUe);
//label SliderSATURATION
sAturation = document.createElement('label');
sAturation.innerHTML = "S";
document.getElementById('divLabel3S').appendChild(sAturation);
//label SliderLIGHTNESS
vAlue = document.createElement('label');
vAlue.innerHTML = "L";
document.getElementById('divLabel3L').appendChild(vAlue);
divI.hide();
divII.hide();
divIII.hide();
}
//clear options button on tool deselect
this.unselectTool = function() {
if(self.name == "BackColorTool")
{
select(".options").html(" ");
select("#otherSpace2").html(" ");
select("#otherSpace3").html(" ");
RGBmode = false;
HSBmode = false;
HSLmode = false;
colorPickermode = false;
}
}
}