-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfoogle.js
128 lines (119 loc) · 3.31 KB
/
foogle.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
//string command input check
var val;
addEventListener('load', function() {
canvasResize()
});
addEventListener('load', function() {
getValue("search_button")
});
addEventListener('load', function() {
addConstCheck("search_button")
});
window.addEventListener('resize', canvasResize, false);
function addConstCheck(elem) {
var elem2 = document.getElementById(elem);
elem2.addEventListener("click", condition);
addEventListener("keypress", function(e) {
var key = e.which;
if (key === 13) {
condition();
}
});
}
function getValue(elem) {
var elem2 = document.getElementById(elem);
elem2.addEventListener("click", function() {
keyValue()
});
addEventListener("keypress", function(e) {
var key = e.which;
if (key === 13) {
keyValue();
}
});
}
function keyValue() {
var elem1 = document.getElementById('main_input');
val = elem1.value;
elem1.value = '';
}
function condition() {
if (document.getElementById("googleLogo")) {
document.getElementById("googleLogo").src = "./Foogle.png";
document.getElementById("googleLogo").id = "foogleLogo";
}
if (val == "raining") {
rain.startRaining();
} else if (val == "stop raining") {
rain.stopRaining();
} else {
location.href = "https://www.google.co.kr/#q=" + val;
}
}
function canvasResize() {
var canvas = document.getElementById('canvas');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
}
var rain = new Rain();
function Rain() {
this.canvasWidth = window.innerWidth;
this.canvasHeight = window.innerHeight;
this.rain = [];
this.fillRainArray = function() {
for (var i = 0; i < 30; i++) {
this.rain.push({
x: (Math.floor(Math.random() * (this.canvasWidth - 10))) + 10,
y: Math.floor(Math.random() * this.canvasHeight),
time: 0,
intrinsicValue: Math.floor(Math.random())
});
}
};
this.drawRain = function() {
var elem = document.getElementById('canvas');
var canvas = elem.getContext('2d');
for (var i = 0; i < this.rain.length; i++) {
canvas.beginPath();
canvas.moveTo(this.rain[i].x, this.rain[i].y);
canvas.quadraticCurveTo(this.rain[i].x - 10, this.rain[i].y + 10, this.rain[i].x, this.rain[i].y + 10);
canvas.moveTo(this.rain[i].x, this.rain[i].y);
canvas.quadraticCurveTo(this.rain[i].x + 10, this.rain[i].y + 10, this.rain[i].x, this.rain[i].y + 10);
canvas.fillStyle = "#0032A0";
canvas.fill();
canvas.stroke();
}
};
this.eraseRain = function() {
var elem = document.getElementById('canvas');
var canvas = elem.getContext('2d');
canvas.clearRect(0, 0, this.canvasWidth, this.canvasHeight);
};
this.gravity = function() {
for (var i = 0; i < this.rain.length; i++) {
if (this.rain[i].y > this.canvasHeight) {
this.rain[i].x = Math.floor(Math.random() * this.canvasWidth);
this.rain[i].y = 1;
this.rain[i].time = 0;
} else {
this.rain[i].y += (this.rain[i].intrinsicValue * 0.98 + this.rain[i].time);
this.rain[i].time++;
}
}
};
this.startRaining = function() {
this.fillRainArray();
this.interval = setInterval(this.updateRain, 20);
};
this.stopRaining = function() {
clearInterval(this.interval);
var elem = document.getElementById('canvas');
var canvas = elem.getContext('2d');
canvas.clearRect(0, 0, this.canvasWidth, this.canvasHeight);
}
this.updateRain = function() {
rain.eraseRain();
rain.drawRain();
rain.gravity();
}
}