-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.html
149 lines (121 loc) · 4.21 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
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> RLColorMixer </title>
<script type="text/javascript" charset="utf-8" src="rlcolormixer-0.5.0.js"> </script>
<script type="text/javascript">
var acceptableColors = [
'#de00ff',
'#2e2439',
'#214ba9',
'#2aaeac',
'#28ac6f',
'#31af37',
'#5ed416',
'#e8ff24',
'#e28f19',
'#ff3c00',
'#9146ac',
'#81a284'
];
function renderBoxesWithColors(colors) {
var container = document.createElement("div");
container.setAttribute('class', 'box');
var mixed = document.createElement('div');
mixed.setAttribute('class', 'mix');
var accepted = document.createElement('div');
accepted.setAttribute('class', 'mix');
// THIS IS WHAT IT IS ALL ABOUT
var mixedColor = RLColorMixer.mixColors(colors);
var acceptedColor = RLColorMixer.findNearest(mixedColor, acceptableColors);
mixed.style.backgroundColor = mixedColor;
accepted.style.backgroundColor = acceptedColor;
container.appendChild(mixed);
container.appendChild(accepted);
document.body.appendChild(container);
// count for parts
var parts = 0;
for(var i = 0, ii = colors.length; i < ii; i++){
if (typeof colors[i] == 'object') {
parts += colors[i].parts;
}
else {
parts += 1;
}
}
for(var i = 0, ii = colors.length; i < ii; i++){
var colorObject = {};
if (typeof colors[i] == 'object') {
colorObject = colors[i];
}
else {
colorObject.color = colors[i];
colorObject.parts = 1;
}
for(var j = 0, jj = colorObject.parts; j < jj; j++){
var colorDiv = document.createElement('div');
colorDiv.setAttribute('class', 'color');
container.appendChild(colorDiv);
colorDiv.style.backgroundColor = colorObject.color;
colorDiv.style.width = Math.floor((210 - (parts - 1) * 10) / parts) + "px";
}
}
}
document.addEventListener("DOMContentLoaded", function() {
document.removeEventListener("DOMContentLoaded", arguments.callee, false);
renderBoxesWithColors(["#0000ff", "#fff000"]);
renderBoxesWithColors([{color: "#0000ff", parts: 3}, "#fff000"]);
renderBoxesWithColors(["#ff0000", "#fbd335"]);
renderBoxesWithColors(["#fbd335", "#ff0000", "#ff0000", "#ff0000"]);
renderBoxesWithColors(["#ff0000", "#ff0000", "#ff0000", "#fbd335"]);
renderBoxesWithColors(["#3c07a7", "#fbd335", "#f300f0"]);
renderBoxesWithColors(["#3c07a7", "#fbd335", "#f300f0", "#faf333"]);
renderBoxesWithColors(["#ec8121", "#f15757"]);
renderBoxesWithColors(["#ff0000", "#ff0000", "#ff0000", "#ff0000", "#ff0000", "#ff0000", "#fbd335"]);
}, false);
</script>
<style>
body {
margin: 50px;
font-family: sans-serif;
color: #666;
}
.color {
width: 100px;
height: 50px;
margin-right: 10px;
margin-bottom: 10px;
float: left;
}
.box {
width: 220px;
padding: 10px 0 0 10px;
border: 1px solid #bababa;
margin-right: 20px;
margin-bottom: 20px;
float: left;
}
.mix {
width: 100px;
height: 200px;
margin-right: 10px;
margin-bottom: 10px;
float: left;
background-color: #fafafa;
}
.mix:nth-child(2n) {
margin-right: 0px;
}
.warning {
font-size: .8em;
color: #aaa;
}
</style>
</head>
<body>
<h1>Mixing colors as in real life (substractive)</h1>
<p>The bottom colors are the original parts. The big left side color is the mixed color and the one on the right is a snapped color choosen from a list</p>
<p class="warning">This example has only been run in chrome...</p>
</body>
</html>