-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.htm
103 lines (94 loc) · 2.71 KB
/
index.htm
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
<!DOCTYPE html>
<html>
<head>
<title>rgb</title>
<style>
body{
margin: 0;
padding: 0;
background-color: #000;
}
#container{
width: 100%;
position: relative;
margin: 0 auto;
overflow: hidden;
}
.column {
float: left;
width: 16.6666666%;
}
#r {
background-color: hsl(0, 100%, 50%);
}
#g {
background-color: hsl(120, 100%, 25%);
}
#b {
background-color: hsl(240, 100%, 50%);
}
#c{
background-color: hsl(180, 100%, 50%);
}
#m{
background-color: hsl(300, 100%, 50%);
}
#y{
background-color: hsl(60, 100%, 50%)
}
</style>
</head>
<div id="container">
<div class="column" id="r"></div>
<div class="column" id="g"></div>
<div class="column" id="b"></div>
<div class="column" id="c"></div>
<div class="column" id="m"></div>
<div class="column" id="y"></div>
</div>
<body>
<script>
window.onmousemove = mouse;
window.onresize = resize;
document.addEventListener('touchmove', touch);
var winHeight = document.documentElement.clientHeight;
var winWidth = window.screen.width;
var saturation, lightness;
var colors = [
[document.getElementById('r'), 0],
[document.getElementById('g'), 120],
[document.getElementById('b'), 240],
[document.getElementById('c'), 180],
[document.getElementById('m'), 300],
[document.getElementById('y'), 60]
];
window.onload = function(){
resize();
};
function resize(){
colors.forEach(function(val){
val[0].style.height = winHeight + 'px';
});
}
function mouse(event){
saturation = Math.floor(mapN(event.x, 0, winHeight, 0, 100));
lightness = Math.floor(mapN(event.y, 0, winWidth, 0, 100));
updateColor(saturation, lightness);
}
function touch(event){
event.preventDefault();
saturation = Math.floor(mapN(event.targetTouches[0].pageX, 0, winHeight, 0, 100));
lightness = Math.floor(mapN(event.targetTouches[0].pageY, 0, winWidth, 0, 100));
updateColor(saturation, lightness);
}
function updateColor(saturation, lightness){
colors.forEach(function(val){
val[0].style.backgroundColor = 'hsl('+ val[1] +','+ saturation +'%, '+ lightness +'%)';
});
}
function mapN(x, in_min, in_max, out_min, out_max){
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
</script>
</body>
</html>