-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
158 lines (132 loc) · 4.39 KB
/
script.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
let nextDVDcolor = '';
let dvdPosLeft = 0;
let dvdPosTop = 0;
let Screen = {
width : document.documentElement.clientWidth,
height : document.documentElement.clientHeight
}
let middleX = Screen.width / 2;
let middleY = Screen.width / 2;
let downUp = true; //down = true, up = false
let rightLeft = true; //right = true, left = false
let beforeDownUp = downUp;
let beforeRightLeft = rightLeft;
let hitY = false;
let hitX = false;
setInterval(move,15)
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
function colorRandomizer(){
return 'rgb('+getRandomInt(66,255)+','+getRandomInt(66,255)+','+getRandomInt(66,255)+')';
}
function borderGlow(pos){
let dvd = document.getElementById("dvd-logo");
let windowDiv = document.getElementById("window");
windowDiv.style.transition = 'all .2s'
switch (pos) {
case 'top':
windowDiv.style.boxShadow = 'inset 0px 20px 10px -10px ' + dvd.style.backgroundColor;
setTimeout(function(){
windowDiv.style.transition = 'all 1s'
windowDiv.style.boxShadow = 'none'
setTimeout(function(){
windowDiv.style.transition = 'all .2s'
}, 1000);
}, 200);
break;
case 'bottom':
windowDiv.style.boxShadow = 'inset 0px -20px 10px -10px ' + dvd.style.backgroundColor;
setTimeout(function(){
windowDiv.style.transition = 'all 1s'
windowDiv.style.boxShadow = 'none'
setTimeout(function(){
windowDiv.style.transition = 'all .2s'
}, 1000);
}, 200);
break;
case 'left':
windowDiv.style.boxShadow = 'inset 20px 0px 10px -10px ' + dvd.style.backgroundColor;
setTimeout(function(){
windowDiv.style.transition = 'all 1s'
windowDiv.style.boxShadow = 'none'
setTimeout(function(){
windowDiv.style.transition = 'all .2s'
}, 1000);
}, 200);
break;
case 'right':
windowDiv.style.boxShadow = 'inset -20px 0px 10px -10px ' + dvd.style.backgroundColor;
setTimeout(function(){
windowDiv.style.transition = 'all 1s'
windowDiv.style.boxShadow = 'none'
setTimeout(function(){
windowDiv.style.transition = 'all .2s'
}, 1000);
}, 200);
break;
}
}
function move(){
let dvd = document.getElementById("dvd-logo");
let windowDiv = document.getElementById("window");
middleX = Screen.width / 2;
middleY = Screen.height / 2;
Screen.width = window.innerWidth,
Screen.height = window.innerHeight
windowDiv.style.height = Screen.height+'px';
windowDiv.style.width = Screen.width+'px';
if(dvdPosTop >= (Screen.height-108)){
downUp = false;
}else if(dvdPosTop <= 0){
downUp = true;
}
if(dvdPosLeft >= (Screen.width-108)){
rightLeft = false;
}else if(dvdPosLeft <= 0){
rightLeft = true;
}
if(downUp == true){
dvdPosTop += 1;
dvd.style.top = dvdPosTop+'px';
}else if(downUp == false){
dvdPosTop -= 1;
dvd.style.top = dvdPosTop+'px';
}
if(rightLeft == true){
dvdPosLeft += 1;
dvd.style.left = dvdPosLeft+'px';
}else if(rightLeft == false){
dvdPosLeft -= 1;
dvd.style.left = dvdPosLeft+'px';
}
if(downUp !== beforeDownUp){ //top & bottom hit
hitX = true;
dvd.style.backgroundColor = colorRandomizer();
if(dvdPosTop <= (middleY)){
borderGlow('top')
}else if(dvdPosTop > (middleY)){
borderGlow('bottom')
}
}
if(rightLeft !== beforeRightLeft){ //right & left hit
hitY = true;
dvd.style.backgroundColor = colorRandomizer();
if(dvdPosLeft <= (middleX)){
borderGlow('left')
}else if(dvdPosLeft > (middleX)){
borderGlow('right')
}
}
if(hitX == true && hitY == true){ //Corner Hit
console.log('the dvd hit the CORNER');
}
if(downUp == beforeDownUp){
hitX = false;
}
if(rightLeft == beforeRightLeft){
hitY = false;
}
beforeDownUp = downUp;
beforeRightLeft = rightLeft;
}