-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolorsgenerator.html
82 lines (71 loc) · 1.68 KB
/
colorsgenerator.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
<html>
<head>
<script type="text/javascript">
function c255ToHex(n)
{
var hexString = "0123456789ABCDEF";
firstpos = (n & 0xF0) >> 4;
secondpos = (n & 0x0F);
return hexString[firstpos] + hexString[secondpos];
}
function rgb2color(r,g,b)
{
return '#' + c255ToHex(r) + c255ToHex(g) + c255ToHex(b);
}
var i,r,g,b = g = r = i = 0;
var frequency = 0.001;
var amp = 90;
var center = 90;
var rmax = Math.floor(0.1*Math.PI / frequency);
var decalage = 1.5*Math.PI / frequency;
state = 1;
i = decalage;
function incrfreq(c)
{
if (c < decalage)
{
state = -state;
}
if (c > rmax + decalage)
{
state = -state;
}
c = c + state;
return c;
}
function incrementColor(c)
{
/* add a counter to slow down printing without changing rate */
if (c < rmax)
return c + 1;
else
return 0;
}
function colorchange()
{
i = incrfreq(i);
v = Math.sin(frequency*i) * amp + center;
r = Math.sin(frequency*i + 0) * amp + center;
g = Math.sin(frequency*i + 2) * amp + center;
b = Math.sin(frequency*i + 4) * amp + center;
color = rgb2color(r,g,b);
document.getElementById("test").style.color = 'black';
document.getElementById("test").innerHTML = color;
document.getElementById("lol").style.color = 'black';
document.getElementById("lol").innerHTML = rmax.toString();
document.body.style.background = color;
}
function load()
{
/* 40ms is 25hz :) 1000/25*/
window.setInterval(colorchange, 30);
}
</script>
</head>
<body onload="load();">
<div id="lol">
</div>
<div id="test">
</div>
</body>
</html>