-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolourPalette.js
executable file
·153 lines (80 loc) · 2.95 KB
/
colourPalette.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
//Displays and handles the colour palette.
function ColourPalette() {
//a list of web colour strings
this.colours = ["black", "silver", "gray", "white", "maroon", "red", "purple",
"orange", "pink", "fuchsia", "green", "lime", "olive", "yellow", "navy",
"blue", "teal", "aqua"
];
//make the start colour be black
this.selectedColour = "black";
var self = this;
var colourClick = function() {
//remove the old border
var current = select("#" + self.selectedColour + "Swatch");
current.style("border", "0");
//get the new colour from the id of the clicked element
var c = this.id().split("Swatch")[0];
//set the selected colour and fill and stroke
self.selectedColour = c;
fill(c);
stroke(c);
//add a new border to the selected colour
this.style("border", "2px solid blue");
}
//load in the colours
this.loadColours = function() {
//set the fill and stroke properties to be black at the start of the programme
//running
fill(this.colours[0]);
stroke(this.colours[0]);
//for each colour create a new div in the html for the colourSwatches
for (var i = 0; i < this.colours.length; i++) {
var colourID = this.colours[i] + "Swatch";
//using JQuery add the swatch to the palette and set its background colour
//to be the colour value.
var colourSwatch = createDiv()
colourSwatch.class('colourSwatches');
colourSwatch.id(colourID);
select(".colourPalette").child(colourSwatch);
select("#" + colourID).style("background-color", this.colours[i]);
colourSwatch.mouseClicked(colourClick)
}
select(".colourSwatches").style("border", "2px solid blue");
};
//call the loadColours function now it is declared
this.loadColours();
}
// colourClick = function(self) {
// var current = select('#' + self.selectedColour + "Swatch");
// console.log(current)
// current.style("border","0");
// // get the coloud from the id of the clicked element. Not sure what this means
// var c = this.id().split("Swatch")[0];
// self.selectedColour = c;
// fill(c);
// stroke(c);
// this.style = ("border","2px solid blue");
// }
// class ColourPalette{
// constructor(){
// this.colours = ["black", "silver", "gray", "white", "maroon", "red", "purple",
// "orange", "pink", "fuchsia", "green", "lime", "olive", "yellow", "navy",
// "blue", "teal", "aqua"];
// this.selectedColour = "black";
// this.loadColours();
// }
// loadColours(){
// fill(this.colours[0]);
// stroke(this.colours[0]);
// for (var i = 0; i < this.colours.length; i++) {
// var colourID = this.colours[i] + "Swatch";
// var colourSwatch = createDiv()
// colourSwatch.class('colourSwatches');
// colourSwatch.id(colourID);
// select(".colourPalette").child(colourSwatch);
// select("#" + colourID).style("background-color", this.colours[i]);
// colourSwatch.mouseClicked(colourClick(this))
// }
// select(".colourSwatches").style("border", "2px solid blue");
// }
// }