-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalette-dropdown.js
93 lines (87 loc) · 2.02 KB
/
palette-dropdown.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
class PaletteDropdown {
constructor(posx, posy, defaultChoice, label) {
// Create the dropdown element
this.dropdown = createSelect();
this.dropdown.position(posx, posy);
this.dropdown.addClass("dropdown");
this.selected = defaultChoice;
this.optionsArray = [
"white",
"black",
"gray",
"rose",
"red",
"orange",
"yellow",
"green",
"aqua",
"teal",
"blue",
"purple",
"raspberry",
];
this.color = null;
// Add options to the dropdown
this.optionsArray.forEach((option) => this.dropdown.option(option));
// Create label
this.label = createP(label);
this.label.position(posx, posy - 40);
this.label.style("color", "white");
// Set the default selected option
if (defaultChoice) {
this.dropdown.selected(defaultChoice);
}
}
// Handle the dropdown selection change
getColor(choice) {
// Get the selected value
this.selected = choice; //this.dropdown.value();
// Convert the URL to a palette array
this.color = this.setColor(this.selected);
}
// Get the URL for the selected palette
setColor(col) {
switch (this.selected) {
case "white":
col = [255, 255, 255];
break;
case "black":
col = [0, 0, 0];
break;
case "gray":
col = [73, 73, 73];
break;
case "rose":
col = [201, 156, 196];
break;
case "red":
col = [250, 0, 0];
break;
case "orange":
col = [255, 169, 31];
break;
case "yellow":
col = [255, 218, 31];
break;
case "green":
col = [17, 136, 35];
break;
case "aqua":
col = [31, 248, 255];
break;
case "teal":
col = [52, 138, 167];
break;
case "blue":
col = [42, 31, 255];
break;
case "purple":
col = [139, 31, 255];
break;
case "raspberry":
col = [255, 31, 233];
break;
}
return col;
}
}