forked from lupine-dev/bitlisten
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloatable.js
More file actions
116 lines (100 loc) · 3.14 KB
/
floatable.js
File metadata and controls
116 lines (100 loc) · 3.14 KB
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
function Floatable() {
this.velocity = {
x : 0,
y : -1
};
this.div = document.createElement("div");
this.div.className = "floatableDiv";
document.getElementById(pageDivId).appendChild(this.div);
this.innerDiv = document.createElement("div");
this.div.appendChild(this.innerDiv);
this.innerDiv.className = "innerDiv";
// Add this object to the update array
updateTargets.push(this);
}
Floatable.prototype.update = function() {
this.x += this.velocity.x;
this.y += this.velocity.y;
this.velocity.x += Math.random() * 0.1 - 0.05;
if (this.velocity.x > 2)
this.velocity.x = 2;
if (this.velocity.x < -2)
this.velocity.x = -2;
if (this.x < 0)
this.velocity.x += 0.02;
if (this.x > window.innerWidth - this.width)
this.velocity.x -= 0.02;
this.updateDiv();
if (this.y < -this.height)
this.removeSelf();
}
Floatable.prototype.updateDiv = function() {
this.div.style.top = this.y + "px";
this.div.style.left = this.x + "px";
}
Floatable.prototype.removeSelf = function() {
document.getElementById(pageDivId).removeChild(this.div);
// Remove self from update array
updateTargets.splice(updateTargets.indexOf(this), 1);
}
Floatable.prototype.addImage = function(image, width, height) {
this.canvas = document.createElement('canvas');
this.image = image;
this.canvas.height = height;
this.canvas.width = width;
this.canvas.style.position = "absolute";
this.canvas.style.top = "0px";
this.canvas.style.left = "0px";
var ctx = this.canvas.getContext("2d");
ctx.drawImage(this.image, 0, 0, width - 1, height - 1);
this.div.appendChild(this.canvas);
}
Floatable.prototype.addText = function(text) {
this.innerDiv.innerHTML += text;
}
Floatable.prototype.initPosition = function() {
this.x = Math.random() * (window.innerWidth - this.width);
this.y = window.innerHeight;
this.updateDiv();
this.div.style.width = this.width + "px";
this.div.style.height = this.height + "px";
this.innerDiv.style.top = (this.height / 2 - this.innerDiv.offsetHeight / 2) + 'px';
// Centers the text within the bubble
}
// Thanks to Myself-Remastered for the image used in this easter egg
// http://myself-remastered.deviantart.com/art/Derpy-Delivery-251264643
var easterSuccess = function() {
var derpy = new Floatable();
derpy.width = 53;
derpy.height = 48;
derpy.image = document.createElement('img');
derpy.image.src = "images/easteregg.gif";
derpy.image.height = derpy.height;
derpy.image.width = derpy.width;
derpy.image.style.position = "absolute";
derpy.image.style.top = "0px";
derpy.image.style.left = "0px";
derpy.div.appendChild(derpy.image);
derpy.initPosition();
derpy.update = function() {
Floatable.prototype.update.call(this);
this.velocity.x += Math.random() * 0.3 - 0.15;
if (derpy.velocity.x > 0.1) {
$(this.div).css({
"-moz-transform": "scaleX(-1)",
"-o-transform": "scaleX(-1)",
"-webkit-transform": "scaleX(-1)",
"transform": "scaleX(-1)"
});
}
if (derpy.velocity.x < -0.1) {
$(this.div).css({
"-moz-transform": "scaleX(1)",
"-o-transform": "scaleX(1)",
"-webkit-transform": "scaleX(1)",
"transform": "scaleX(1)"
});
}
}
}
new Konami(easterSuccess);