The code behind the animation is in home.js
. Other code in the file seems irrelevant.
! function() {
function e() {
return Date.now() / 1e3
}
function t(e, t, a, n, r) {
var i = e[a] - t[a],
s = e[n] - t[n];
e[a] = i * W(r) - s * Y(r) + t[a], e[n] = i * Y(r) + s * W(r) + t[n]
}
function a() {
this.legs = [{
"hip_angle": 0,
"knee_angle": 0
}, {
"hip_angle": 0,
"knee_angle": 0
}], this.arms = [{
"shoulder_angle": 0,
"elbow_angle": 0
}, {
"shoulder_angle": 0,
"elbow_angle": 0
}], this.direction_angle = 0, this.lean_angle = 0, this.animators = [], this.X = this.Y = this.VX = this.VY = 0, this.Z = this.VZ = 0, this.size = 1
}
function n(e, t, a, n, r, i, s, o) {
return function(l) {
if (!(a >= l)) {
var h = l >= n;
h && (l = n);
var u = (l - a) / (n - a);
switch (s) {
case "smooth":
u = -W(Math.PI * u) / 2 + .5;
break;
case "andback":
u = -W(Math.PI * u * 2) / 2 + .5
}
var c;
c = "function" == typeof i ? i(u, r) : r * (1 - u) + i * u, e[t] = c, h && o && o()
}
}
}
function r(e) {
return 11 + 1.5 * Y(e / 10) + e / 25
}
function i(e) {
var t = "feet.0",
a = e.feet[0].y;
return e.feet[1].y > a && (t = "feet.1", a = e.feet[1].y), e.hands[0].y > a && (t = "hands.0", a = e.hands[0].y), e.hands[1].y > a && (t = "hands.1", a = e.hands[1].y), e.hip.y > a && (t = "hip"), t
}
function s(e, t) {
for (var a = t.split(/\./), n = 0; n < a.length; n++) e = e[a[n]];
return e
}
function o(e) {
for (var a = {
"x": 0,
"y": 0,
"z": 0
}, n = {
"x": 0,
"y": -.5 * e.size,
"z": 0
}, r = {
"x": 0,
"y": -.6 * e.size,
"z": 0
}, i = {
"x": 0,
"y": -.7 * e.size,
"z": 0
}, s = [], o = [], l = [], h = [], u = 0; 2 > u; u++) {
var c = u ? -1 : 1;
s[u] = {
"x": .05 * c * e.size,
"y": .4 * e.size,
"z": 0
}, o[u] = {
"x": .1 * c * e.size,
"y": .8 * e.size,
"z": 0
}, l[u] = {
"x": .05 * c * e.size,
"y": n.y + .3 * e.size,
"z": 0
}, h[u] = {
"x": .1 * c * e.size,
"y": n.y + .6 * e.size,
"z": 0
}
}
for (var u = 0; 2 > u; u++) t(s[u], a, "y", "z", e.legs[u].hip_angle), t(o[u], a, "y", "z", e.legs[u].hip_angle), t(o[u], s[u], "y", "z", -e.legs[u].knee_angle), t(l[u], n, "y", "z", e.arms[u].shoulder_angle), t(h[u], n, "y", "z", e.arms[u].shoulder_angle), t(h[u], l[u], "y", "z", e.arms[u].elbow_angle);
t(n, a, "y", "z", -e.lean_angle), t(r, a, "y", "z", -e.lean_angle), t(i, a, "y", "z", -e.lean_angle);
for (var u = 0; 2 > u; u++) t(l[u], a, "y", "z", -e.lean_angle), t(h[u], a, "y", "z", -e.lean_angle);
for (var u = 0; 2 > u; u++) t(s[u], a, "x", "z", e.direction_angle), t(o[u], a, "x", "z", e.direction_angle), t(l[u], a, "x", "z", e.direction_angle), t(h[u], a, "x", "z", e.direction_angle);
return t(n, a, "x", "z", e.direction_angle), t(r, a, "x", "z", e.direction_angle), t(i, a, "x", "z", e.direction_angle), {
"hip": a,
"shoulder": n,
"knees": s,
"feet": o,
"neck": r,
"hands": h,
"elbows": l,
"head": i
}
}
function l(e, t, a, n, r, i, s) {
t.save();
var o = (1 - (200 - r) / 400) / .6;
t.scale(i, i), t.translate(25, 0), t.scale(o, o), t.translate(-25, 0), t.translate(a, n), t.lineWidth = 1 / i, t.fillStyle = t.strokeStyle = s || "white", t.beginPath(), t.moveTo(e.neck.x, e.neck.y), t.lineTo(e.hip.x, e.hip.y), t.lineTo(e.knees[0].x, e.knees[0].y), t.lineTo(e.feet[0].x, e.feet[0].y), t.moveTo(e.hip.x, e.hip.y), t.lineTo(e.knees[1].x, e.knees[1].y), t.lineTo(e.feet[1].x, e.feet[1].y), t.moveTo(e.shoulder.x, e.shoulder.y), t.lineTo(e.elbows[0].x, e.elbows[0].y), t.lineTo(e.hands[0].x, e.hands[0].y), t.moveTo(e.shoulder.x, e.shoulder.y), t.lineTo(e.elbows[1].x, e.elbows[1].y), t.lineTo(e.hands[1].x, e.hands[1].y), t.stroke(), t.beginPath(), t.arc(e.head.x, e.head.y, .1, 0, 2 * Math.PI), t.save(), t.fill(), t.restore(), t.stroke(), t.restore()
}
function h(e, t) {
return function(a, n) {
return .5 >= a ? (a = 2 * a, a * e + (1 - a) * n) : (a = 2 * a - 1, a * t + (1 - a) * e)
}
}
function u(e, t) {
var a;
return "number" == typeof t ? (a = (t - e.direction_angle) % Q, a > Math.PI && (a -= Q), a < -Math.PI && (a += Q), a > Math.PI || -40 * T > a ? a = -40 * T : (a < -Math.PI || a > 40 * T) && (a = 40 * T)) : a = 0, a
}
function c(e) {
var t = u(this, e);
return this.animate(.2, {
"legs": {
"rear_leg": {
"hip_angle": [10 * T, "smooth"],
"knee_angle": [20 * T, "smooth"]
},
"front_leg": {
"hip_angle": [0 * T, "smooth"],
"knee_angle": [0 * T, "smooth"]
}
},
"direction_angle": "" + t
}, "linear")
}
function d(e, t) {
var a = u(this, e);
return this.animate(t || .6, {
"legs": {
"rear_leg": {
"hip_angle": [30 * T, "smooth"],
"knee_angle": h(70 * T, 0 * T)
},
"front_leg": {
"hip_angle": -20 * T,
"knee_angle": h(10 * T, 10 * T)
}
},
"arms": {
"rear_leg": {
"shoulder_angle": h(0, -40 * T),
"elbow_angle": h(0, 20 * T)
},
"front_leg": {
"shoulder_angle": h(0, 15 * T),
"elbow_angle": h(0, 25 * T)
}
},
"lean_angle": h(-5 * T, 2 * T),
"direction_angle": "" + a
}, "linear")
}
function p(e, t) {
var a = u(this, e);
return this.animate(t || .3, {
"legs": {
"rear_leg": {
"hip_angle": [60 * T, "linear"],
"knee_angle": h(120 * T, 0 * T)
},
"front_leg": {
"hip_angle": -40 * T,
"knee_angle": h(10 * T, 10 * T)
}
},
"arms": {
"rear_leg": {
"shoulder_angle": h(0, -80 * T),
"elbow_angle": h(0, 80 * T)
},
"front_leg": {
"shoulder_angle": h(0, 40 * T),
"elbow_angle": h(0, 60 * T)
}
},
"lean_angle": h(25 * T, 15 * T),
"direction_angle": "" + a
}, "linear")
}
function g(e) {
return this.animate(e || .6, {
"legs": {
"front_leg": {
"hip_angle": 5 * T,
"knee_angle": 0
},
"rear_leg": {
"hip_angle": -5 * T,
"knee_angle": h(45 * T, 0)
}
},
"arms": [{
"shoulder_angle": 0,
"elbow_angle": 0
}, {
"shoulder_angle": 0,
"elbow_angle": 0
}],
"lean_angle": 0
})
}
function f(e) {
return this.animate(e || .7, {
"legs": [{
"hip_angle": 80 * T,
"knee_angle": 160 * T
}, {
"hip_angle": 80 * T,
"knee_angle": 160 * T
}],
"arms": [{
"shoulder_angle": 20 * T,
"elbow_angle": 20 * T
}, {
"shoulder_angle": 20 * T,
"elbow_angle": 0
}],
"lean_angle": 45 * T
}, "linear")
}
function v() {
return this.animate(1, {
"legs": [{
"hip_angle": h(120 * T, 102 * T),
"knee_angle": 40 * T
}, {
"hip_angle": h(120 * T, 122 * T),
"knee_angle": 80 * T
}],
"arms": [{
"shoulder_angle": -10 * T,
"elbow_angle": 10 * T
}, {
"shoulder_angle": -20 * T,
"elbow_angle": 20 * T
}],
"lean_angle": -20 * T
}, "smooth")
}
function y() {
return this.animate(.7, {
"legs": [{
"hip_angle": h(160 * T, 100 * T),
"knee_angle": 160 * T
}, {
"hip_angle": h(160 * T, 100 * T),
"knee_angle": 160 * T
}],
"arms": [{
"shoulder_angle": 20 * T,
"elbow_angle": 20 * T
}, {
"shoulder_angle": 20 * T,
"elbow_angle": 0
}],
"lean_angle": 45 * T
}, "linear")
}
function m() {
return this.animate(.8, {
"legs": [{
"hip_angle": -5 * T,
"knee_angle": 50 * T
}, {
"hip_angle": -5 * T,
"knee_angle": 50 * T
}],
"arms": [{
"shoulder_angle": 95 * T,
"elbow_angle": 0 * T
}, {
"shoulder_angle": 90 * T,
"elbow_angle": 0 * T
}],
"lean_angle": h(90 * T, 80 * T)
}, "linear")
}
function b(e) {
switch (e) {
case 1:
return this.animate(.2, {
"arms": [{
"shoulder_angle": -30 * T,
"elbow_angle": 90 * T
}]
}, "smooth");
case 2:
return this.animate(.6, {
"arms": [{
"shoulder_angle": 90 * T,
"elbow_angle": h(90 * T, 0)
}]
}, "smooth");
case 3:
return this.animate(.4, {
"arms": [{
"shoulder_angle": 30 * T,
"elbow_angle": 60 * T
}]
}, "smooth")
}
}
function S(e, t) {
switch (e) {
case 1:
return this.animate(.6, {
"lean_angle": -20 * T,
"arms": [{
"shoulder_angle": 200 * T,
"elbow_angle": 60 * T
}]
});
case 2:
return this.animate(.4, {});
case 3:
var a = k(this, t.stickFigure.X, t.stickFigure.Y + t.stickFigure._last_points.neck.y, t.stickFigure.Z, t.stickFigure.VX, t.stickFigure.VZ);
return a.thrower = this.kid, this.animate(.4, {
"lean_angle": 30 * T,
"arms": [{
"shoulder_angle": h(120 * T, 50 * T),
"elbow_angle": h(0, 30 * T)
}],
"legs": [, {
"hip_angle": -30 * T
}]
}, "smooth")
}
}
function w(e, t, a, n) {
var r, i = a - e,
s = n - t;
if (0 === i) r = 0 > s ? 180 * T : 0 * T;
else {
var o = -s / i,
l = Math.atan(o);
0 > i && (l += 180 * T), r = 270 * T - l
}
return r
}
function _() {
var e = this.stickFigure = new a;
e.kid = this, this.initial = !0, e.size = .2 * Math.random() + .5;
var t = 46 * Math.random() + 2,
n = 120 * Math.random() - 60;
e.X = t, e.Z = n, e.Y = r(e.X, e.Z) - .8 * e.size, e.direction_angle = 0, this.plan = [];
var i = this;
x = J + D, e.when_idle = function() {
i.doSomething()
}
}
function k(t, a, n, i, s, o) {
for (var l = {
"x": t._last_points.hands[0].x + t.X,
"y": t._last_points.hands[0].y + t.Y,
"z": t._last_points.hands[0].z + t.Z,
"t": e()
}, h = 7 + 6 * Math.random(), u = 0; 2 > u; u++) {
var c = a - l.x,
d = n - l.y,
p = i - l.z,
g = Math.sqrt(c * c + p * p);
l.vx = c * h / g, l.vz = p * h / g;
var f = g / h;
a += s * f, i += o * f
}
return l.vy = Math.max(-10, -4.905 * f + d / f), K.push(l), l.step = function() {
var t = e(),
a = t - this.t;
a > .04 && (a = .04), this.vy += 9.81 * a, this.y += this.vy * a, this.x += this.vx * a, this.z += this.vz * a, this.y > r(this.x, this.z) && (this.gone = !0), this.t = t
}, l.draw = function(e, t) {
e.save();
var a = (1 - (200 - this.z) / 400) / .6;
e.scale(t, t), e.translate((this.x - 25) * a + 25, this.y * a), e.scale(a, a), e.lineWidth = 1 / t, e.fillStyle = e.strokeStyle = "white", e.beginPath(), e.arc(0, 0, .04, 0, 2 * Math.PI), e.save(), e.fill(), e.restore(), e.stroke(), e.restore()
}, l
}
var x, I = 0,
z = function(e) {
return window[e + (e ? "R" : "r") + "equestAnimationFrame"]
},
H = z("") || z("webkit") || z("moz") || z("o") || z("ms") || function(e) {
var t = Date.now(),
a = t - I;
I = t, setTimeout(function() {
e()
}, 16 - a % 16)
},
T = Math.PI / 180,
F = 1,
C = 2,
B = 3,
E = 4,
A = 5,
j = 6,
D = 7,
M = 8,
U = 9,
O = 10,
P = 11,
L = 1,
q = 11,
X = 12,
V = 13,
Z = 21,
N = 22,
J = 23,
Y = Math.sin,
W = Math.cos;
a.prototype.stop = function(e) {
return this.animators = [], !e && this.when_idle && this.when_idle(), this
}, a.prototype.animate = function(t, a, r) {
function i(a, h) {
for (var u in a)
if (a.hasOwnProperty(u)) {
var c = u;
if ("front_leg" === u ? c = o : "rear_leg" === u && (c = 1 - o), "object" == typeof h[c]) i(a[u], h[c]);
else {
var d, p;
a[u].constructor == Array ? (d = a[u][0], p = a[u][1]) : (p = r, d = a[u]), "string" == typeof d && (d = h[c] + parseFloat(d)), s.animators.push(n(h, c, e(), e() + t, h[c], d, p, l)), l = null
}
}
}
var s = this,
o = this.legs[0].hip_angle >= this.legs[1].hip_angle ? 0 : 1,
l = function() {
s.animators = [], s.when_idle && s.when_idle()
};
return i(a, this), l && l(), this
}, a.prototype.step = function() {
for (var t = this._last_time, a = e(), n = this.animators.length, l = n - 1; l >= 0; l--) this.animators[l] && this.animators[l](a);
var h = o(this),
u = i(h),
c = s(h, u),
d = {
"x": this.X,
"y": r(this.X + c.x, this.Z + c.z) - c.y,
"z": this.Z
};
if ("undefined" != typeof t) {
var p = this._last_points,
g = (this._last_hip, a - t);
if (this.VY += 9.81 * g, this.Y += this.VY * g, c.y + this.Y >= r(this.X + c.x, this.Z + c.z)) {
var f = c.x - s(p, u).x,
v = c.z - s(p, u).z;
Math.abs(f) > .1, this.VX = -f / g, this.X -= f, this.VZ = -v / g, this.Z -= v, this.VY > 0 && (this.VY = 0), this.Y = r(this.X + c.x, this.Z + c.z) - c.y
} else this.X += this.VX * g, this.Z += this.VZ * g
}
this._last_time = a, this._last_hip = d, this._last_points = h, 0 === n && this.when_idle && this.when_idle()
};
var Q = 2 * Math.PI;
_.prototype.step = function() {
this.stickFigure.step()
}, _.prototype.doSomething = function() {
if (!this.plan || !this.plan.length) return this.decide(), void 0;
var e = this.plan[0][0];
switch (e) {
case F:
return;
case C:
this.stickFigure.animate(this.plan[0][1], {
"_ignore": 0
}), this.plan.shift();
break;
case B:
v.call(this.stickFigure), this.plan.shift();
break;
case E:
y.call(this.stickFigure), this.plan.shift();
break;
case A:
f.call(this.stickFigure), this.plan.shift();
break;
case j:
g.call(this.stickFigure), this.plan.shift();
break;
case D:
m.call(this.stickFigure), this.plan.shift();
break;
case O:
for (var t = this.plan[0][1], a = Math.abs(t - this.stickFigure.direction_angle); a >= Q;) a -= Q;
if (2 * T > a) return this.plan.shift(), void 0;
c.call(this.stickFigure, this.plan[0][1]);
break;
case M:
case U:
var n = this.plan[0][1],
r = n - this.stickFigure.X,
i = this.plan[0][2],
s = i - this.stickFigure.Z;
if (Math.abs(r) + Math.abs(s) > 1) {
var o = w(this.stickFigure.X, this.stickFigure.Z, n, i);
return (e === U ? p : d).call(this.stickFigure, o, this.plan[0][3]), void 0
}
return this.plan.shift(), void 0;
case P:
var l = this.plan[0][1].shift();
if (!l) return this.plan.shift(), void 0;
switch (l) {
case L:
f.call(this.stickFigure);
break;
case q:
case X:
case V:
b.call(this.stickFigure, parseInt(l % 10));
break;
case j:
g.call(this.stickFigure);
break;
case O:
for (var h = this.plan[0][2], o = w(this.stickFigure.X, this.stickFigure.Y, h.stickFigure.X, h.stickFigure.Y), a = Math.abs(o - this.stickFigure.direction_angle); a >= Q;) a -= Q;
if (15 * T > a) return;
c.call(this.stickFigure, o), this.plan[0][1].unshift(O), g.call(this.stickFigure);
break;
case Z:
case N:
case J:
S.call(this.stickFigure, parseInt(l % 10), this.plan[0][2])
}
}
};
var R = 0;
_.prototype.decide = function() {
if (!this.initial && Math.random() > .4 + R / 50) {
for (var e, t = 0; 10 > t; t++) {
var a = G[Math.random() * G.length | 0];
if (a !== this && Math.abs(this.stickFigure.X - a.stickFigure.X) < 10 && Math.abs(this.stickFigure.Z - a.stickFigure.Z) < 10) {
e = a;
break
}
}
if (e) return this.plan.push([P, [L, q, X, V, j, O, Z, N, J], e]), void 0
}
this.initial = !1;
var n = 46 * Math.random() + 2,
r = 120 * Math.random() - 60,
i = this.stickFigure.X - n,
s = this.stickFigure.Z - r,
o = Math.abs(i) + Math.abs(s) > 7 && Math.random() < .7 - R / 50;
this.plan.push([o ? U : M, n, r, .2 * Math.random() - .1 + (o ? .3 : .6)])
};
var K = [],
G = [];
$(function() {
function t() {
var r = e();
r - s >= 1 && (o = 1 - Math.round(a.position().top) / (3 * x), s = r);
for (var c = r - .04, d = -100, p = -100, g = .1 / (G.length - 1), f = -g, v = 0; v < G.length; v++) {
if (v || (R = R * o + o * (r - (G[v].stickFigure._last_time || r))), (R + Math.PI / 2) * x > h && !i) {
do {
f += g;
var y = Q * f,
m = 13 * W(y) - y * W(2 * y) - 2 * W(3 * y) - W(4 * y),
b = 4 * (3 * Y(y) - Y(3 * y))
} while (3.6 > (b - d) * (b - d) + (m - p) * (m - p));
d = b, p = m, m = -5 * m - 10, b = 25 + b * ((60 - m) / 160);
var S = w(b, m, 25, -10);
u.push([b, m, S]), v === G.length - 1 && (i = r)
}
G[v].stickFigure._last_time < c && (G[v].stickFigure._last_time = c), G[v].step()
}
n.clearRect(0, 0, n.canvas.width, n.canvas.height), n.save(), n.translate(0, -30);
for (var v = 0; v < G.length; v++) {
var _ = G[v].stickFigure,
k = _._last_points;
l(k, n, _.X, _.Y, _.Z, 25, "#e4f4f3")
}
for (var v = K.length; v >= 0; v--) {
var I = K[v];
if (I) {
if (I.step(), I.gone) {
K.splice(v, 1);
continue
}
I.draw(n, 25)
}
if (I && I.vy > 0 || u.length)
for (var z = 0; z < G.length; z++) {
var C = G[z],
U = u.shift();
if (U) G[z].plan = [
[M, U[0], U[1], .5 + .1 * Math.random()],
[j],
[O, U[2]],
[A],
[B],
[F]
];
else if (Math.abs(I.x - C.stickFigure.X) < .2 && Math.abs(I.z - C.stickFigure.Z) < .2 && Math.abs(I.y - (C.stickFigure.Y + C.stickFigure._last_points.hip.y)) < .3) {
C.stickFigure.VY = -1.8 - .4 * Math.random();
var $ = C.stickFigure.VX * I.vx > 0 ? -1 : 1,
et = 3 + 2 * Math.random();
C.stickFigure.VX = +I.vx / et, C.stickFigure.VZ = +I.vz / et, C.plan = [
[B],
[E],
[j]
], C.plan = $ > 0 && Math.random() < .8 - R / 40 ? [
[D],
[P, [L, q, X, V, j, O, Z, N, J], I.thrower]
] : $ > 0 ? [
[D],
[j]
] : [
[B],
[E],
[j]
], C.stickFigure.stop(!0).animate(.3, {
"lean_angle": 80 * $ * T,
"legs": [{
"hip_angle": 90 * -$ * T,
"knee_angle": 0
}, {
"hip_angle": 90 * -$ * T,
"knee_angle": 0
}]
}, "linear"), K.splice(v, 1);
break
}
}
}
n.restore(), H(t)
}
for (var a = $("canvas").fadeIn(1e3), n = a[0].getContext("2d"), r = 0; 50 > r; r++) G.push(new _);
var i = 0,
s = e(),
o = 0,
h = a.width(),
u = [];
H(t)
})
}();