-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.html
90 lines (79 loc) · 1.71 KB
/
test2.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
<html>
<head>
<title>Test</title>
</head>
<body>
<p>Test Paragraph</p>
<div id="target_div"> </div>
<script type="text/javascript">
function upOrDown (range) {
return (range / 2) - Math.round((Math.random() * range));
}
function newColor(val) {
var myRange = 6;
var gewichtung = Math.round(( (128 - val) / 128 ) );
var newColorVal = val + gewichtung + upOrDown(myRange);
if ( newColorVal >= 0 && newColorVal <= 255) {
return newColorVal;
}
else
{
if (newColorVal > 255) {
return newColorVal - myRange;
}
else
{
return newColorVal + myRange;
}
}
}
function makeHexColor(colVal) {
var newString = colVal.toString(16);
if ( newString.length == 1 ) {
return "0" + newString;
}
else
{
return newString;
}
}
var rainbow = {
red: 255 ,
green: 255 ,
blue: 255 ,
delay: 25 ,
iterateColors: function () {
this.iterateRed();
this.iterateGreen();
this.iterateBlue();
this.updateColors();
} ,
iterateRed: function () {
this.red = newColor(this.red);
} ,
iterateGreen: function () {
this.green = newColor(this.green);
} ,
iterateBlue: function () {
this.blue = newColor(this.blue);
} ,
updateColors: function () {
colorString = "#" + makeHexColor(this.red) + makeHexColor(this.green) + makeHexColor(this.blue);
console.log("r: " + this.red + "g: " + this.green + "b: " + this.blue + "string: " + colorString);
document.bgColor = colorString;
} ,
start: function () {
this.iterateColors();
setTimeout("rainbow.start()", this.delay) ;
} ,
init: function () {
this.red = Math.round((Math.random() * 255));
this.green = Math.round((Math.random() * 255));
this.blue = Math.round((Math.random() * 255));
}
}
rainbow.init();
rainbow.start();
</script>
</body>
</html>