/
colors2.js
38 lines (30 loc) · 1.21 KB
/
colors2.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
function decimalToHex(d) {
var hex = Number(d).toString(16);
hex = "00".substr(0, 2 - hex.length) + hex;
console.log('converting ' + d + ' to ' + hex);
return hex;
}
function makeColorSorter(frequency1, frequency2, frequency3,
phase1, phase2, phase3,
center, width, len) {
for (var i = 0; i < len; ++i)
{
var red = Math.floor(Math.sin(frequency1*i + phase1) * width + center);
var green = Math.floor(Math.sin(frequency2*i + phase2) * width + center);
var blue = Math.floor(Math.sin(frequency3*i + phase3) * width + center);
console.log('red: ' + decimalToHex(red));
console.log('green: ' + decimalToHex(green));
console.log('blue: ' + decimalToHex(blue));
var div = $('<div class="colorBlock"></div>');
div.css('background-color', '#' + decimalToHex(red) + decimalToHex(green) + decimalToHex(blue));
$('#colors').append(div);
}
}
function makeSortable() {
$('#colors').sortable();
$('#colors').disableSelection();
}
function testColorSorter() {
makeColorSorter(.05,.05,.05,0,2,4, 128,127, 121);
makeSortable();
}