forked from amiravni/MSGEQ7_ESP8266_WS2812
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
123 lines (123 loc) · 4.44 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
<!-- HTML script is based on a script by Markus Gritsch. Thanks man you are great! -->
<!DOCTYPE html>
<html>
<head>
<title>MSGEQ7 & ESP8266 color pick</title>
<meta charset=utf-8 />
<meta name="viewport" content="width=device-width, initial-scale=1">
<style id="jsbin-css">
.colour-changer {
margin-left: auto;
margin-right: auto;
width: 100%;
}
.colour-off {
height: 20px;
margin-left: auto;
margin-right: auto;
width: 100%;
background-color:black;
}
.colour-on {
height: 20px;
margin-left: auto;
margin-right: auto;
width: 100%;
background-color:white;
border: 1px solid black;
}
</style>
</head>
<body>
<div class="colour-on" onclick="xhr = new XMLHttpRequest(); xhr.open('GET', 'on', true); xhr.send(null);" ontouchstart="xhr = new XMLHttpRequest(); xhr.open('GET', 'on', true); xhr.send(null);"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-changer"></div>
<div class="colour-off" onclick="xhr = new XMLHttpRequest(); xhr.open('GET', 'off', true); xhr.send(null);" ontouchstart="xhr = new XMLHttpRequest(); xhr.open('GET', 'off', true); xhr.send(null);"></div>
<script>
function toArray(arr) {
return Array.prototype.slice.call(arr);
}
function rgb2hex(rgb) {
rgb = rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+))?\)$/);
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
return "~" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}
toArray(document.querySelectorAll('.colour-changer')).forEach(function(div, i, arr) {
var hue = (i / arr.length) * 360;
div.style.background = 'hsl(' + hue + ', 100%, 50%)';
div.style.width = (1 - Math.pow(Math.abs(i - arr.length/2),0.5) / Math.pow(Math.abs(arr.length - arr.length/2),0.5) ) * 100 + '%';
div.style.height = (( Math.pow(Math.abs(arr.length/2 - i),3) ) / (10*screen.height) +10) + 'px';
function click(event) {
xhr = new XMLHttpRequest();
xhr.open('GET', rgb2hex(div.style.backgroundColor), true);
xhr.send(null);
event.preventDefault();
}
div.addEventListener('touchstart', click);
div.addEventListener('click', click);
});
</script>
</body>
</html>